ProtoSharp is a library to encode ProtoBuf messages without needing to generate C# classes from the .proto files, or to specify the schema using runtime libraries like protobuf-net
.
First, create a new ProtoMessage
object. This object represents the message you want to encode. You can then add fields to the message using chained Field
method.
Here is an example of how to encode a message using ProtoSharp:
using ProtoSharp;
var encoded = new ProtoMessage()
.Field(1, 42)
.Field(2, 3.14)
.Field(3, "大笨蛋qwqa")
.Field(4, [1, 1, 4, 5, 1, 4])
.Field(5, [0.1, 0.2], false)
.Field(6, [0x11, 0x45, 0x14, 0x19, 0x19, 0x81, 0x00])
.Field(7, new ProtoMessage()
.Field(1, "nested qwqa baka")
.Field(2, 2L, EncodingFlags.Fixed)
.Field(3, 3, EncodingFlags.ZigZag));