Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optional int32 does not get packed or unpacked . #43

Closed
GoogleCodeExporter opened this issue Apr 5, 2016 · 3 comments
Closed

optional int32 does not get packed or unpacked . #43

GoogleCodeExporter opened this issue Apr 5, 2016 · 3 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Delcare optional int32 in .proto file.
2. set the optional field.
3. pack it.
4. unpack it.
5. get the optional field.

What is the expected output? What do you see instead?
I was expecting the optional field back. But it is always the default value(0) .

What version of the product are you using? On what operating system?
version: libprotoc 2.3.0
os: fedora core 10

-- Thanks
Kamanashis Roy

Original issue reported on code.google.com by kamanash...@gmail.com on 5 Jul 2010 at 3:57

@GoogleCodeExporter
Copy link
Author

Look in the .h file that is produced from your .proto file and you will see the 
structure generated to be filled in.  In that structure there is a field called 
has_(name of optional field) that must be set to true (or 1) in order for the 
macros to pack and unpack the optional field correctly.  It appears that this 
is not done automatically, but instead must be done manually.

Set that variable, try it again and see if it works.

Original comment by roweandr...@gmail.com on 8 Jul 2010 at 4:17

@GoogleCodeExporter
Copy link
Author

Yes, I was wrestling with this for a while today too! Setting the member to 
true fixed it for me.

Original comment by rado...@gmail.com on 22 Jul 2010 at 1:02

@GoogleCodeExporter
Copy link
Author

Yes - you must set the has_ member to nonzero for the member to be packed.

Original comment by lahike...@gmail.com on 3 Aug 2010 at 3:14

  • Changed state: Invalid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant