Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nanopb
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
le
nanopb
Commits
1f13e8cd
Commit
1f13e8cd
authored
11 years ago
by
Petteri Aimonen
Browse files
Options
Downloads
Patches
Plain Diff
Fix bugs in extension support when multiple extension fields are present.
parent
64947cb3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
generator/nanopb_generator.py
+6
-3
6 additions, 3 deletions
generator/nanopb_generator.py
pb.h
+11
-0
11 additions, 0 deletions
pb.h
pb_encode.c
+6
-1
6 additions, 1 deletion
pb_encode.c
with
23 additions
and
4 deletions
generator/nanopb_generator.py
+
6
−
3
View file @
1f13e8cd
...
...
@@ -313,16 +313,19 @@ class ExtensionField(Field):
raise
NotImplementedError
(
"
Only
'
optional
'
is supported for extension fields.
"
+
"
(%s.rules == %s)
"
%
(
self
.
fullname
,
self
.
rules
))
self
.
rules
=
'
OPTEXT
'
def
extension_decl
(
self
):
'''
Declaration of the extension type in the .pb.h file
'''
return
'
extern const pb_extension_type_t %s;
'
%
self
.
fullname
return
'
extern const pb_extension_type_t %s;
\n
'
%
self
.
fullname
def
extension_def
(
self
):
'''
Definition of the extension type in the .pb.c file
'''
result
=
'
typedef struct {
\n
'
result
+=
str
(
self
)
result
+=
'
} %s;
\n
'
%
self
.
struct_name
result
+=
(
'
static const pb_field_t %s_field = %s;
\n
'
%
result
+=
'
\n
} %s;
\n
\n
'
%
self
.
struct_name
result
+=
(
'
static const pb_field_t %s_field =
\n
%s;
\n
\n
'
%
(
self
.
fullname
,
self
.
pb_field_t
(
None
)))
result
+=
'
const pb_extension_type_t %s = {
\n
'
%
self
.
fullname
result
+=
'
NULL,
\n
'
...
...
This diff is collapsed.
Click to expand it.
pb.h
+
11
−
0
View file @
1f13e8cd
...
...
@@ -364,6 +364,17 @@ struct _pb_extension_t {
{tag, PB_ATYPE_CALLBACK | PB_HTYPE_REPEATED | ltype, \
pb_delta_end(st, m, pm), 0, pb_membersize(st, m), 0, ptr}
/* Optional extensions don't have the has_ field, as that would be redundant. */
#define PB_OPTEXT_STATIC(tag, st, m, pm, ltype, ptr) \
{tag, PB_ATYPE_STATIC | PB_HTYPE_OPTIONAL | ltype, \
0, \
0, \
pb_membersize(st, m), 0, ptr}
#define PB_OPTEXT_CALLBACK(tag, st, m, pm, ltype, ptr) \
{tag, PB_ATYPE_CALLBACK | PB_HTYPE_OPTIONAL | ltype, \
0, 0, pb_membersize(st, m), 0, ptr}
/* The mapping from protobuf types to LTYPEs is done using these macros. */
#define PB_LTYPE_MAP_BOOL PB_LTYPE_VARINT
#define PB_LTYPE_MAP_BYTES PB_LTYPE_BYTES
...
...
This diff is collapsed.
Click to expand it.
pb_encode.c
+
6
−
1
View file @
1f13e8cd
...
...
@@ -161,9 +161,14 @@ static bool checkreturn encode_static_field(pb_ostream_t *stream,
{
pb_encoder_t
func
;
const
void
*
pSize
;
bool
dummy
=
true
;
func
=
PB_ENCODERS
[
PB_LTYPE
(
field
->
type
)];
pSize
=
(
const
char
*
)
pData
+
field
->
size_offset
;
if
(
field
->
size_offset
)
pSize
=
(
const
char
*
)
pData
+
field
->
size_offset
;
else
pSize
=
&
dummy
;
switch
(
PB_HTYPE
(
field
->
type
))
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment