質問

I have a Player structure which holds a list of pointers to its closest neighbors. The structure might look as follows in C++:

struct Player {
  string handle;
  vector<Player*> neighbors;
};

I want to use protobuf to serialize instances of this class. How would I write a message definition to represent the above structure?

役に立ちましたか?

解決

There is no concept of "reference" in protobuf.

Therefore the sanest way to do it would be to:

message Player {
  required string handle = 1;
  repeated string neighborHandles = 2;
};

Usually you would then convert them to C++ references when you are done deserializing.

他のヒント

I think this would do the trick:

message Player
{
  required string handle = 1;

  repeated Player neighbors = 2;
}

I compiled the definition with protobuf-c and it seems to be working.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top