Protobuf-net in .proto creates enum conflicts?

In C #, we have namespaces in .proto that we get from protobuf-net, we don't get any namespaces. Therefore, the question arises how to make protobuf-net generate (and use internally) .proto files with the names packs / packages.

An example, when we analyzed our entire project to make .proto files for connecting a C ++ application to our C # application, we got tons

enum AnimationCode { None = 0; Idle = 1; //... } 

and

 enum SessionCode { None = 0; //... } 

So, when we provided this combined project .proto file for the proton compiler, we got tons

The enumeration type "SessionStateCode" does not matter with the name None.

and

Note that enumeration values ​​use C ++ rules to determine scope, which means that enumeration values ​​are siblings of their type, not children.

and no C ++ code.

The point was to make the encoded C # message be at least readable from C ++

+4
source share
2 answers

There is currently no code inside protobuf-net for automatically resolving name conflicts, although I would be interested to know if you have any suggestions. Another variant:

  enum AnimationCode { [ProtoEnum(Name="AnimationCode_None")] None = 0, Idle = 1 } 

Here at startup scema.proto will use AnimationCode_None ; in fact it will be:

 enum AnimationCode { AnimationCode_None = 0; Idle = 1; } 

I checked the MetaType / ValueMember API and it seems that it was currently difficult to set .Name at runtime, but it could be fixed in the new version quite easily (for example, using a similar similar enumeration / MetaType fix ) if you prefer Set them at run time, rather than decorate them with attributes.

+2
source

Have you tried this?

 package MyNamespace{ enum AnimationCode { None = 0; Idle = 1; //... } } 
0
source

All Articles