Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

protobuf message holding reference to another message of same type

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?

like image 424
Agnel Kurian Avatar asked Oct 19 '25 07:10

Agnel Kurian


1 Answers

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.

like image 108
Mr. Beer Avatar answered Oct 21 '25 22:10

Mr. Beer