Search code examples
c++protocol-buffers

Splitting protocol buffer definitions into multiple .proto files


I would like to include a protocol definition file in another protocol file. For example:

// base.proto:
message P_EndPoint {
  required int32 id = 1;
  required string host = 2;
  required int32 port = 3;
}

Then in another file:

communication.proto:
// somehow include `base.proto'
// ...
message P_CommunicationProtocol {
  required CP_MessageType type = 1;
  optional int32 id = 2;
  optional P_EndPoint identity = 3;
  repeated P_EndPoint others = 4;
}
// ...

(Note: developers.google.com is not available in my locale)


Solution

  • import "myproject/base.proto";
    

    Docs: https://developers.google.com/protocol-buffers/docs/proto#importing