[英]Golang protobuf dynamic messages
I'm writing a go tcp client to receive events from a server.我正在编写一个 go tcp 客户端来从服务器接收事件。 The server response are bytes structured in this way:
服务器响应是以这种方式构造的字节:
Can I use Protobufs for this?我可以为此使用 Protobufs 吗? If yes how should I structure the message?
如果是,我应该如何构建消息?
Kind regards, Jurgen亲切的问候,尤尔根
The answer is: yes, you can.答案是:是的,你可以。 And it must looks something like this:
它必须看起来像这样:
proto file:原型文件:
syntax = "proto3";
message Event {
bytes start = 1;
bytes length = 2;
...
repeated bytes param = 9;
}
your go struct will be:你的 go 结构将是:
type Event struct {
Start []byte
Length []byte
...
Param [][]byte
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.