Code Review
/
apps
/
agl-service-can-low-level.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Add #if guard for .pb.h version.
[apps/agl-service-can-low-level.git]
/
generator
/
nanopb_generator.py
diff --git
a/generator/nanopb_generator.py
b/generator/nanopb_generator.py
index
1d12ae3
..
5d2a360
100755
(executable)
--- a/
generator/nanopb_generator.py
+++ b/
generator/nanopb_generator.py
@@
-261,7
+261,7
@@
class Field:
result = ''
if self.allocation == 'POINTER':
if self.rules == 'REPEATED':
result = ''
if self.allocation == 'POINTER':
if self.rules == 'REPEATED':
- result += ' size_t ' + self.name + '_count;\n'
+ result += '
pb_
size_t ' + self.name + '_count;\n'
if self.pbtype == 'MESSAGE':
# Use struct definition, so recursive submessages are possible
if self.pbtype == 'MESSAGE':
# Use struct definition, so recursive submessages are possible
@@
-277,17
+277,14
@@
class Field:
if self.rules == 'OPTIONAL' and self.allocation == 'STATIC':
result += ' bool has_' + self.name + ';\n'
elif self.rules == 'REPEATED' and self.allocation == 'STATIC':
if self.rules == 'OPTIONAL' and self.allocation == 'STATIC':
result += ' bool has_' + self.name + ';\n'
elif self.rules == 'REPEATED' and self.allocation == 'STATIC':
- result += ' size_t ' + self.name + '_count;\n'
+ result += '
pb_
size_t ' + self.name + '_count;\n'
result += ' %s %s%s;' % (self.ctype, self.name, self.array_decl)
return result
def types(self):
'''Return definitions for any special types this field might need.'''
if self.pbtype == 'BYTES' and self.allocation == 'STATIC':
result += ' %s %s%s;' % (self.ctype, self.name, self.array_decl)
return result
def types(self):
'''Return definitions for any special types this field might need.'''
if self.pbtype == 'BYTES' and self.allocation == 'STATIC':
- result = 'typedef struct {\n'
- result += ' size_t size;\n'
- result += ' uint8_t bytes[%d];\n' % self.max_size
- result += '} %s;\n' % self.ctype
+ result = 'typedef PB_BYTES_ARRAY_T(%d) %s;\n' % (self.max_size, self.ctype)
else:
result = None
return result
else:
result = None
return result
@@
-364,7
+361,7
@@
class Field:
'''Return the pb_field_t initializer to use in the constant array.
prev_field_name is the name of the previous field or None.
'''
'''Return the pb_field_t initializer to use in the constant array.
prev_field_name is the name of the previous field or None.
'''
- result = ' PB_FIELD
2
(%3d, ' % self.tag
+ result = ' PB_FIELD(%3d, ' % self.tag
result += '%-8s, ' % self.pbtype
result += '%s, ' % self.rules
result += '%-8s, ' % self.allocation
result += '%-8s, ' % self.pbtype
result += '%s, ' % self.rules
result += '%-8s, ' % self.allocation
@@
-771,8
+768,8
@@
def generate_header(dependencies, headername, enums, messages, extensions, optio
yield '/* Generated by %s at %s. */\n\n' % (nanopb_version, time.asctime())
symbol = make_identifier(headername)
yield '/* Generated by %s at %s. */\n\n' % (nanopb_version, time.asctime())
symbol = make_identifier(headername)
- yield '#ifndef
_PB_%s_
\n' % symbol
- yield '#define
_PB_%s_
\n' % symbol
+ yield '#ifndef
PB_%s_INCLUDED
\n' % symbol
+ yield '#define
PB_%s_INCLUDED
\n' % symbol
try:
yield options.libformat % ('pb.h')
except TypeError:
try:
yield options.libformat % ('pb.h')
except TypeError:
@@
-785,6
+782,11
@@
def generate_header(dependencies, headername, enums, messages, extensions, optio
yield options.genformat % (noext + options.extension + '.h')
yield '\n'
yield options.genformat % (noext + options.extension + '.h')
yield '\n'
+ yield '#if PB_PROTO_HEADER_VERSION != 30\n'
+ yield '#error Regenerate this file with the current version of nanopb generator.\n'
+ yield '#endif\n'
+ yield '\n'
+
yield '#ifdef __cplusplus\n'
yield 'extern "C" {\n'
yield '#endif\n\n'
yield '#ifdef __cplusplus\n'
yield 'extern "C" {\n'
yield '#endif\n\n'
@@
-857,6
+859,11
@@
def generate_source(headername, enums, messages, extensions, options):
yield options.genformat % (headername)
yield '\n'
yield options.genformat % (headername)
yield '\n'
+ yield '#if PB_PROTO_HEADER_VERSION != 30\n'
+ yield '#error Regenerate this file with the current version of nanopb generator.\n'
+ yield '#endif\n'
+ yield '\n'
+
for msg in messages:
yield msg.default_decl(False)
for msg in messages:
yield msg.default_decl(False)
@@
-911,7
+918,7
@@
def generate_source(headername, enums, messages, extensions, options):
yield ' * numbers or field sizes that are larger than what can fit in 8 or 16 bit\n'
yield ' * field descriptors.\n'
yield ' */\n'
yield ' * numbers or field sizes that are larger than what can fit in 8 or 16 bit\n'
yield ' * field descriptors.\n'
yield ' */\n'
- yield 'STATIC_ASSERT((%s), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_%s)\n'%(assertion,msgs)
+ yield '
PB_
STATIC_ASSERT((%s), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_%s)\n'%(assertion,msgs)
yield '#endif\n\n'
if worst < 65536:
yield '#endif\n\n'
if worst < 65536:
@@
-928,7
+935,7
@@
def generate_source(headername, enums, messages, extensions, options):
yield ' * numbers or field sizes that are larger than what can fit in the default\n'
yield ' * 8 bit descriptors.\n'
yield ' */\n'
yield ' * numbers or field sizes that are larger than what can fit in the default\n'
yield ' * 8 bit descriptors.\n'
yield ' */\n'
- yield 'STATIC_ASSERT((%s), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_%s)\n'%(assertion,msgs)
+ yield '
PB_
STATIC_ASSERT((%s), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_%s)\n'%(assertion,msgs)
yield '#endif\n\n'
# Add check for sizeof(double)
yield '#endif\n\n'
# Add check for sizeof(double)
@@
-944,7
+951,7
@@
def generate_source(headername, enums, messages, extensions, options):
yield ' * These are not directly supported by nanopb, but see example_avr_double.\n'
yield ' * To get rid of this error, remove any double fields from your .proto.\n'
yield ' */\n'
yield ' * These are not directly supported by nanopb, but see example_avr_double.\n'
yield ' * To get rid of this error, remove any double fields from your .proto.\n'
yield ' */\n'
- yield 'STATIC_ASSERT(sizeof(double) == 8, DOUBLE_MUST_BE_8_BYTES)\n'
+ yield '
PB_
STATIC_ASSERT(sizeof(double) == 8, DOUBLE_MUST_BE_8_BYTES)\n'
yield '\n'
yield '\n'