aakash-sahai / nanopb

Automatically exported from code.google.com/p/nanopb
zlib License
0 stars 0 forks source link

Add a new FieldType that allows to ignore the field #51

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm in a situation where I want nanopb to decode some fields of the protobuf, 
and ignore some others.
With current implementation, I could marked the ones I want to ignore with 
[type=FT_CALLBACK] and set the callback to NULL; but it would be better if the 
field were not generated at all.

I suggest adding the ability to mark fields as [type=FT_IGNORE], to simply 
remove the fields from the structures.

Nevertheless, there would be a side effect: if a required field is marked as 
FT_IGNORE, it would be impossible to pb_encode a valid protobuf.
I think this is acceptable, because FT_IGNORE is mainly for decoders; the 
generator could just print a warning if FT_IGNORE is used on a required field.

Original issue reported on code.google.com by benoit.b...@gmail.com on 14 Jan 2013 at 1:02

GoogleCodeExporter commented 9 years ago
I guess the idea is to keep the fields for other generators? Because otherwise 
you could just remove them completely from the .proto.

Original comment by Petteri.Aimonen on 14 Jan 2013 at 1:20

GoogleCodeExporter commented 9 years ago
Yes. I have some fields that are relevant for computers but can be ignored by 
embedded programs.
Moreover, I think this feature fits well with the way nanopb is designed.

Original comment by benoit.b...@gmail.com on 14 Jan 2013 at 2:54

GoogleCodeExporter commented 9 years ago
I agree. I will leave out the warning, because:
1) Any missing required fields will be detected by the other end anyway and
2) Someone may want to ignore a required field when decoding, in which case the 
warning would be annoying.

Original comment by Petteri.Aimonen on 14 Jan 2013 at 3:22

GoogleCodeExporter commented 9 years ago
This issue was updated by revision d32d3226580b.

Original comment by Petteri.Aimonen on 14 Jan 2013 at 3:32

GoogleCodeExporter commented 9 years ago
Thanks !

Original comment by benoit.b...@gmail.com on 14 Jan 2013 at 5:15

GoogleCodeExporter commented 9 years ago
Fix released in nanopb-0.1.9.

Original comment by Petteri.Aimonen on 13 Feb 2013 at 7:19