0

我需要将具有数组(std::array,但我认为 std::vector 解决方案相同)的“本机”C++ 结构映射到 protobuf。

所以假设我有

struct MyStruct{
    // Color is some class I already know how to map to PB
    std::array<std::optional<Color>, 4> opt_colors;
}

我不确定什么是最好的方法。

我目前最好的猜测是:

message ColorPb{
// some fields here
}

message OptColorPb{
  int32 idx = 1; // idx in array
  ColorPb color = 2; // value
}
message MyStructPb{
   // in case of vector I would also have a size, but for array it is known
   repeated OptColorPb opt_colors = 1;
}
4

0 回答 0