json - 将对象数组表示为 protobuf 消息

标签 json protocol-buffers

我想创建一个代表对象数组的 protobuf 消息。

示例

[
  {
    "firstKey": "firstValue",
    "secondKey": "secondValue",
  },
  {
    "firstKey": "firstValue",
    "secondKey": "secondValue",
  },
  ...
]

伪代码(不是有效的语法)

syntax = "proto3";

message Entry {
  string firstKey = 1;
  string secondKey = 2;
}

repeated message Response {
  ...Entry;
}

我找不到办法做到这一点。有可能吗?还是我被迫像这样嵌套它?

syntax = "proto3";

message Entry {
  string firstKey = 1;
  string secondKey = 2;
}

message Response {
  repeated Entry data = 2;
}

最佳答案

syntax = "proto3";

message SingleObject {
  string name = 1;
  int32 age = 2;
}

message ObjectArray {
  repeated SingleObject objects = 1;
}

关于json - 将对象数组表示为 protobuf 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69243156/

相关文章:

javascript - 使用给定数字对 JSON 数组进行分组

java - @JsonView 不过滤属性(Spring 4.1.0.RC2,Jackson 2.3.2)

Javascript 变量在不应该的时候被重置

java - Protocol Buffers 可执行系统间 Linux 错误

python-3.x - gRPC:如何使用静态参数和流参数的组合来调用远程过程?

javascript - 使用 JavaScript 根据 JSON 文件开头的内容读取该行

java - Google Protocol Buffer,在 Windows 上快,在 Ubuntu 上慢

c++ - 在 DEBUG 模式下调整字节字段大小时发生访问冲突

go - gRPC 和 Swagger 注解区别

javascript - 通过nodejs过滤对象数组