Reputation: 59476
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?
Upvotes: 3
Views: 3038
Reputation: 12176
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.
Upvotes: 2
Reputation: 255
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.
Upvotes: 2