Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

protobuf-net into .proto generates enum conflicts?

In C# we have namespaces in .proto we get from protobuf-net we do not get any namespaces. So the question is how to make protobuf-net generate (and use inside) .proto files with namespacs/packages.

Example when we parsed all our project to make .proto files to connect a C++ app to our C# app we got tons of

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

and

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

And so when we gave that unified project .proto file to protogen compiler we got tons of

Enum type "SessionStateCode" has no value named "None".

and

Note that enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it.

and no C++ code.

Point was to make it so that encoded C# message would be at least readable from C++

like image 352
myWallJSON Avatar asked Dec 10 '12 14:12

myWallJSON


1 Answers

There is not currently any code inside protobuf-net to perform automatic name collision fixes, although I'd be interested to know if you have any proposals. Another option would be:

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

Here, the .proto will use AnimationCode_None when generation the scema; in fact, it will be:

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

I've checked the MetaType/ValueMember API, and it looks like currently it would be hard to set the .Name at runtime, but that could be fixed in a new release easily enough (like with this similar enum/MetaType fix) if you preferred to set them at runtime rather than decorate with attributes.

like image 187
Marc Gravell Avatar answered Oct 23 '22 23:10

Marc Gravell