rikveenboer / nanopb

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

Let max size options affect integers #139

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have seen this discussed somewhere before but I cannot find it anywhere in 
the bug tracker.

It would be nice if you could specify the max value for an integer and have its 
variable be chosen accordingly to conserve RAM. For example:
- max_size:255 = uint8_t
- 65535 = uint16_t
- default = uint32_t

In our case we would save around 1k RAM in a system which has 64k, not counting 
padding.

Original issue reported on code.google.com by denravon...@gmail.com on 31 Dec 2014 at 2:50

GoogleCodeExporter commented 9 years ago
Yeah, maybe this or just a new int_size: 8/16/32 option.

Original comment by Petteri.Aimonen on 2 Jan 2015 at 7:35

GoogleCodeExporter commented 9 years ago
That would be perfect. More explicit.

Original comment by denravon...@gmail.com on 3 Jan 2015 at 10:03

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

Original comment by Petteri.Aimonen on 4 Jan 2015 at 10:18

GoogleCodeExporter commented 9 years ago
Not sure I'm using it incorrectly but I get:

google.protobuf.text_format.ParseError: 1:1 : Message type "NanoPBOptions" has 
no field named "int_size".

Original comment by denravon...@gmail.com on 5 Jan 2015 at 7:15

GoogleCodeExporter commented 9 years ago
Hmm, how are you using it?

And you are using the newest version from version control?

Original comment by Petteri.Aimonen on 5 Jan 2015 at 7:24

GoogleCodeExporter commented 9 years ago
stsolutions.Configuration.SensorDefinition.sensor_display_decimal_places 
int_size:8

I'm on 7be7c7769f9532b2aca98e271540a565a6a321e6

Original comment by denravon...@gmail.com on 5 Jan 2015 at 7:29

GoogleCodeExporter commented 9 years ago
This is the full stack trace:

Traceback (most recent call last):
  File "/Users/marco/dev/CentralUnit/Bridge/nanopb/../../Vendor/nanopb/generator/nanopb_generator.py", line 1201, in <module>
    main_cli()
  File "/Users/marco/dev/CentralUnit/Bridge/nanopb/../../Vendor/nanopb/generator/nanopb_generator.py", line 1151, in main_cli
    results = process_file(filename, None, options)
  File "/Users/marco/dev/CentralUnit/Bridge/nanopb/../../Vendor/nanopb/generator/nanopb_generator.py", line 1092, in process_file
    Globals.separate_options = read_options_file(open(optfilename, "rU"))
  File "/Users/marco/dev/CentralUnit/Bridge/nanopb/../../Vendor/nanopb/generator/nanopb_generator.py", line 979, in read_options_file
    text_format.Merge(parts[1], opts)
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google/protobuf/text_format.py", line 265, in Merge
    return MergeLines(text.split('\n'), message)
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google/protobuf/text_format.py", line 298, in MergeLines
    _ParseOrMerge(lines, message, True)
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google/protobuf/text_format.py", line 229, in _ParseOrMerge
    _MergeField(tokenizer, message, allow_multiple_scalars)
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google/protobuf/text_format.py", line 356, in _MergeField
    message_descriptor.full_name, name))
google.protobuf.text_format.ParseError: 1:1 : Message type "NanoPBOptions" has 
no field named "int_size".

Original comment by denravon...@gmail.com on 5 Jan 2015 at 7:29

GoogleCodeExporter commented 9 years ago
Actually, I'm on cc3c8732fd3f8505f46802dd54bd4a21c79b72aa

Original comment by denravon...@gmail.com on 5 Jan 2015 at 7:33

GoogleCodeExporter commented 9 years ago
Actually it's "int_size: IS_8" because it is an enum. See 
https://code.google.com/p/nanopb/source/browse/tests/intsizes/intsizes.proto

But your error message is not because of that. It seems that the 
nanopb_generator.py or nanob_pb2.py is not of correct version for some reason. 
Maybe you need to re-run "make" in the generator/proto directory?

Original comment by Petteri.Aimonen on 5 Jan 2015 at 7:47

GoogleCodeExporter commented 9 years ago
I switched to IS_8 and now get:

google.protobuf.text_format.ParseError: 1:10 : Enum type "IntSize" has no value 
with number 8.

I also tried:
Sally:CentralUnit marco$ pushd Vendor/nanopb/generator/proto
Sally:proto marco$ rm nanopb_pb2.py plugin_pb2.py
Sally:proto marco$ make
protoc --python_out=. nanopb.proto
protoc --python_out=. plugin.proto
Sally:proto marco$

But the error remains. I'll see if I can get it running in Linux/apt instead of 
OSX/homebrew.

Original comment by denravon...@gmail.com on 5 Jan 2015 at 8:00

GoogleCodeExporter commented 9 years ago
The "Enum type "IntSize" has no value with number 8." error is much more 
promising. It seems that you still had "8" instead of "IS_8" somewhere when you 
got that error.

But I've now pushed a change that makes it work the same with "8" and "IS_8".

Original comment by Petteri.Aimonen on 5 Jan 2015 at 8:33

GoogleCodeExporter commented 9 years ago
You are absolutely right. I had an ":8" left. Changing it to IS_8 solved it, 
thanks!

Original comment by denravon...@gmail.com on 5 Jan 2015 at 8:40

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

Original comment by Petteri.Aimonen on 24 Jan 2015 at 3:53