It's visible in the descriptor for introspection at execution-time - but 
it's useful to have the field numbers at *compile* time in order to refer 
to them for accessing messages with reflection.

For example, if you have an IMessage which you know represents a Timestamp, 
but may be implemented via DynamicMessage (not implemented yet, but 
coming...) then it's reasonable to use

long seconds = (long) 
message.Descriptor.Fields[Timestamp.SecondsField].Accessor.GetValue(message);

I've considered introducing an enum called Fields as a nested type within 
each generated class instead, but that would create unnecessary casting 
everywhere.

Jon


On Tuesday, 24 November 2015 20:02:44 UTC, Teddy Zhang wrote:
>
> I notice that for ProtoBuf 3 generated classes, they have fields 
> numbers there.
>
> E.g. for C#:
>
>>     public const int LatitudeFieldNumber = 1;
>>
>  
>
>>     private float latitude_;
>>     public float Latitude {
>>       get { return latitude_; }
>>       set {
>>         latitude_ = value;
>>       }
>>     }
>>
>
>  Found similar behavior in Java and C++.
>
> I think those should belong to Descriptor, no?
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to