Protobuf使用
protobuf序列化,假设有个用protoc.exe生成的LoginReq的类
class Program
{
static void Main(string[] args)
{
LoginReq loginReq = new LoginReq();
byte[] bytes = new byte[loginReq.CalculateSize()];
using (CodedOutputStream cos = new CodedOutputStream(bytes))
{
loginReq.WriteTo(cos);
}
}
}
protobuf反序列化
var loginReq = LoginReq.Parser.ParseFrom(message);
proto的根目录下的所有.proto文件生成C#文件
protoc.exe --csharp_out=. *.proto
Protobuf Github地址
protocolbuffers/protobuf: Protocol Buffers - Google’s data interchange format (github.com)