Protobuf for Enum

529 views
Skip to first unread message

Rashmi Vijay

unread,
May 21, 2021, 2:56:24 AM5/21/21
to Protocol Buffers
What is the difference it makes if we decorate the enum with ProtoContract in C# enum while doing Protobuf Serialization. I do get the value when i do deserialization irrespective of that Attribute on Enum. Then what is the best Practice?

Marc Gravell

unread,
May 21, 2021, 5:19:58 AM5/21/21
to Rashmi Vijay, Protocol Buffers
This is specific to protobuf-net. If you're using v3, the main usage here is to provide explicit names for the enum and (via ProtoEnumAttribute) the defined values; the names only matter if you are generating a .proto from a code-first model (GetSchema(), GetProto<T>(), etc)

In v2, you can *also* use ProtoEnumAttribute to provide explicit serialization values different to the natural value, or you can tell it to *always* use natural values (with no attempt to consider mapped values) via EnumPassthru on ProtoContractAttribute, however: these features are deprecated in v3 - enums are now *always* treated as direct pass-thru values with no attempt to map values.

On Fri, 21 May 2021 at 07:56, Rashmi Vijay <rash...@gmail.com> wrote:
What is the difference it makes if we decorate the enum with ProtoContract in C# enum while doing Protobuf Serialization. I do get the value when i do deserialization irrespective of that Attribute on Enum. Then what is the best Practice?

--
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+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/1c8d3097-c2c5-4f6d-a80b-c89ff7f05272n%40googlegroups.com.


--
Regards,

Marc
Reply all
Reply to author
Forward
0 new messages