To convert a C# class to a Protobuf message (proto), you need to define the schema of the message in a .proto file, then use a protobuf compiler like protoc to generate the corresponding C# classes.
Here's an example:
main.cs83 chars7 lines
main.cs38 chars2 lines
This will generate a C# file named mymessage.cs.
main.cs394 chars21 lines
Note that the ToProto and FromProto methods are used to convert between the MyMessage proto and MyClass C# class.
main.cs299 chars14 lines
In this example, we use the Google.Protobuf library to serialize/deserialize the proto messages.
gistlibby LogSnag