Protocol buffers set bool default value =true

11,554 views
Skip to first unread message

steph

unread,
Mar 16, 2011, 3:17:12 PM3/16/11
to Protocol Buffers
I want to have a bool value default to true but I cant seem to make it
do that. As stated in the protocol buffer documentation bools default
to false. However since i'm able to set default values on types i want
to set the defautl value of my bool types to true.

Here is what i've tried:

optional bool getA = 1 [default = true];

optional bool getA = 1 [default = TRUE];

optional bool getA = 1 [default = 1];

none of these worked for me. How can i set the bool to default to
true?

thanks,
steph

Jason Hsueh

unread,
Mar 16, 2011, 3:25:34 PM3/16/11
to steph, Protocol Buffers
On Wed, Mar 16, 2011 at 12:17 PM, steph <prest...@gmail.com> wrote:
I want to have a bool value default to true but I cant seem to make it
do that. As stated in the protocol buffer documentation bools default
to false. However since i'm able to set default values on types i want
to set the defautl value of my bool types to true.

Here is what i've tried:

optional bool getA = 1 [default = true];

This first one should work. What did you observe when using this?
 

optional bool getA = 1 [default = TRUE];

optional bool getA = 1 [default = 1];

none of these worked for me. How can i set the bool to default to
true?

thanks,
steph

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.


Jason Hsueh

unread,
Mar 16, 2011, 3:39:30 PM3/16/11
to steph, Protocol Buffers
I'm not familiar with that error. Can you provide the protoc command you are using, as well as the output of protoc --version? And is your .proto file simply:

message Foo {
  optional bool getA = 1 [default = true];
}

On Wed, Mar 16, 2011 at 12:28 PM, steph <prest...@gmail.com> wrote:
The error text i get is:

Error the .proto-file is invalid, content:               optional bool
getA = 1 [default = true];, line number: 2


On Mar 16, 3:25 pm, Jason Hsueh <jas...@google.com> wrote:
> >http://groups.google.com/group/protobuf?hl=en.- Hide quoted text -
>
> - Show quoted text -

steph

unread,
Mar 16, 2011, 4:09:14 PM3/16/11
to Protocol Buffers
The syntax you show for the file matches mine.

Im guessing that my issue is coming from the javaprotobuffer
implementation that I am using. I am using this custom one that
outputs to JavaME http://code.google.com/p/protobuf-javame/

To my knowledge it was just a wrapper around protocol buffers so I
assumed i had all the same functionality. I guess I dont, i'll have to
try to post on their support since it appears its not a general
protocol buffers issue

Thank you for your help!
stephanie
> > > >http://groups.google.com/group/protobuf?hl=en.-Hide quoted text -

steph

unread,
Mar 16, 2011, 3:28:03 PM3/16/11
to Protocol Buffers
The error text i get is:

Error the .proto-file is invalid, content: optional bool
getA = 1 [default = true];, line number: 2


On Mar 16, 3:25 pm, Jason Hsueh <jas...@google.com> wrote:

steph

unread,
Mar 16, 2011, 3:26:45 PM3/16/11
to Protocol Buffers
the error text i get is

Error: the .proto-file is invalid, content: optional bool getA = 1
[default = true];, line number:2

Reply all
Reply to author
Forward
0 new messages