简体   繁体   English

Golang protobuf 动态消息

[英]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:服务器响应是以这种方式构造的字节:

  1. start byte起始字节
  2. length byte长度字节
  3. command byte命令字节
  4. adress1 byte地址 1 字节
  5. adress2 byte地址2字节
  6. address3 byte地址3字节
  7. address4 byte地址4字节
  8. error byte错误字节
  9. param 1 byte ... N. param N byte参数 1 字节 ... N. 参数 N 字节

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM