Re: [protobuf] Proto2 possible field options

2018-11-01 Thread Josh Humphries
On Thu, Nov 1, 2018 at 11:36 AM Michael Powell 
wrote:

> On Thu, Nov 1, 2018 at 11:08 AM Josh Humphries 
> wrote:
> >
> > Michael,
> > They map to field names in the options messages defined in
> descriptor.proto.
>
> This is pretty interesting. So they've used the Proto spec to describe
> itself, ey?
>
> > Also, if you define custom options (by extending those options
> messages), you refer to them using qualified name enclosed in parentheses.
> That proto file above also serves as a sort of AST for proto source files,
> where FileDescriptorProto is the root of the AST. You can then look at
> UninterpretedOption for seeing the AST structure for parsing options.
>
> So, for instance, my field options could include something like this:
>
> ... [default_value = 3, oneof_index = 1, json_name = "myField", ...]
>
> And, so on, ad nauseam for the possible field options?
>
>
> https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/descriptor.proto#L136


Not quite. Those are fields on the *descriptor*, which map to other
elements in the source. (The oneof index, for example, is computed based on
the order of oneof declarations in the enclosing DescriptorProto and is
unset for fields that are not enclosed in a oneof in the source file. You
can't define that via an option.)

The options are all defined in special *Options messages, like this one:
https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/descriptor.proto#L507
The various descriptor protos have a field for the corresponding options
type (for example, this

).

The two exceptions are both for field options only: default and json_name.
Contrary to what I just told you, these are not fields of the FieldOptions
message, but they are defined via options in the actual source. I call them
"pseudo-options" -- they behave just like options, but when incorporated
into the descriptor proto, they get *promoted* out of the options message
and into the enclosing FieldDescriptorProto.


>
>
> > Josh Humphries
> > jh...@bluegosling.com
> >
> >
> > On Wed, Oct 31, 2018 at 7:30 PM Michael Powell 
> wrote:
> >>
> >> Hello,
> >>
> >> In the Proto2 specification, "field options" are sort of meta-tucked
> >> away. I don't think the specification really names them. Is there a
> >> list of them somewhere in the docs?
> >>
> >> i.e. field = label type fieldName "=" fieldNumber [ "[" fieldOptions
> "]" ] ";"
> >> fieldOptions = fieldOption { ","  fieldOption }
> >> fieldOption = optionName "=" constant
> >>
> >> Specifically, "optionName" ? If memory serves from examples, things
> >> like "default" ?
> >>
> >> Thanks!
> >>
> >> Best regards,
> >>
> >> Michael Powell
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups "Protocol Buffers" group.
> >> To unsubscribe from this group and stop receiving emails from it, send
> an email to protobuf+unsubscr...@googlegroups.com.
> >> To post to this group, send email to protobuf@googlegroups.com.
> >> Visit this group at https://groups.google.com/group/protobuf.
> >> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


Re: [protobuf] Proto2 possible field options

2018-11-01 Thread Michael Powell
On Thu, Nov 1, 2018 at 11:08 AM Josh Humphries  wrote:
>
> Michael,
> They map to field names in the options messages defined in descriptor.proto.

This is pretty interesting. So they've used the Proto spec to describe
itself, ey?

> Also, if you define custom options (by extending those options messages), you 
> refer to them using qualified name enclosed in parentheses. That proto file 
> above also serves as a sort of AST for proto source files, where 
> FileDescriptorProto is the root of the AST. You can then look at 
> UninterpretedOption for seeing the AST structure for parsing options.

So, for instance, my field options could include something like this:

... [default_value = 3, oneof_index = 1, json_name = "myField", ...]

And, so on, ad nauseam for the possible field options?

https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/descriptor.proto#L136

> Josh Humphries
> jh...@bluegosling.com
>
>
> On Wed, Oct 31, 2018 at 7:30 PM Michael Powell  wrote:
>>
>> Hello,
>>
>> In the Proto2 specification, "field options" are sort of meta-tucked
>> away. I don't think the specification really names them. Is there a
>> list of them somewhere in the docs?
>>
>> i.e. field = label type fieldName "=" fieldNumber [ "[" fieldOptions "]" ] 
>> ";"
>> fieldOptions = fieldOption { ","  fieldOption }
>> fieldOption = optionName "=" constant
>>
>> Specifically, "optionName" ? If memory serves from examples, things
>> like "default" ?
>>
>> Thanks!
>>
>> Best regards,
>>
>> Michael Powell
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Protocol Buffers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to protobuf+unsubscr...@googlegroups.com.
>> To post to this group, send email to protobuf@googlegroups.com.
>> Visit this group at https://groups.google.com/group/protobuf.
>> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


Re: [protobuf] Proto2 possible field options

2018-11-01 Thread Josh Humphries
Michael,
They map to field names in the options messages defined in descriptor.proto

.

Also, if you define custom options (by extending those options messages),
you refer to them using qualified name enclosed in parentheses. That proto
file above also serves as a sort of AST for proto source files, where
FileDescriptorProto is the root of the AST. You can then look at
UninterpretedOption for seeing the AST structure for parsing options.


*Josh Humphries*
jh...@bluegosling.com


On Wed, Oct 31, 2018 at 7:30 PM Michael Powell 
wrote:

> Hello,
>
> In the Proto2 specification, "field options" are sort of meta-tucked
> away. I don't think the specification really names them. Is there a
> list of them somewhere in the docs?
>
> i.e. field = label type fieldName "=" fieldNumber [ "[" fieldOptions "]" ]
> ";"
> fieldOptions = fieldOption { ","  fieldOption }
> fieldOption = optionName "=" constant
>
> Specifically, "optionName" ? If memory serves from examples, things
> like "default" ?
>
> Thanks!
>
> Best regards,
>
> Michael Powell
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


[protobuf] Proto2 possible field options

2018-10-31 Thread Michael Powell
Hello,

In the Proto2 specification, "field options" are sort of meta-tucked
away. I don't think the specification really names them. Is there a
list of them somewhere in the docs?

i.e. field = label type fieldName "=" fieldNumber [ "[" fieldOptions "]" ] ";"
fieldOptions = fieldOption { ","  fieldOption }
fieldOption = optionName "=" constant

Specifically, "optionName" ? If memory serves from examples, things
like "default" ?

Thanks!

Best regards,

Michael Powell

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.