Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Represent an array of objects as a protobuf message

I would like to create a protobuf message which represents an array of objects.

Example

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

Pseudo code (not a valid syntax)

syntax = "proto3";

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

repeated message Response {
  ...Entry;
}

I cannot find a way to do this. Is it even possible or am I forced to nest it like this?

syntax = "proto3";

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

message Response {
  repeated Entry data = 2;
}
like image 732
Bartek Maciejiczek Avatar asked Oct 23 '25 23:10

Bartek Maciejiczek


1 Answers

syntax = "proto3";

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

message ObjectArray {
  repeated SingleObject objects = 1;
}
like image 67
Kumar Avatar answered Oct 26 '25 23:10

Kumar