Splitting protocol buffer definitions into multipl

2020-02-26 03:28发布

问题:

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)

回答1:

import "myproject/base.proto";

Docs: http://developers.google.com/protocol-buffers/docs/proto#other