71

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)

David Moles
  • 48,006
  • 27
  • 136
  • 235
sorush-r
  • 10,490
  • 17
  • 89
  • 173

2 Answers2

71
import "myproject/base.proto";

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

Ray
  • 7,940
  • 7
  • 58
  • 90
Brian Roach
  • 76,169
  • 12
  • 136
  • 161
  • 3
    Thanks. Sorry for not doing my own search. Google Developers is not accessible in my country. [(I see this)](http://s2.picofile.com/file/7789729137/arch12.png) – sorush-r Jun 03 '13 at 19:04
  • 3
    Because of the stupid politics. US Export control laws restrict providing certain services to some countries. This really sucks. I'm a student. I'm not trying to make bombs! I just wanna finish my final project on CSP course :| – sorush-r Jun 03 '13 at 19:10
  • 3
    No worries. I edited your Q so I could remove my downvote. Glad I could help. – Brian Roach Jun 03 '13 at 19:11
  • I'd suggest something like googling "anonymous http proxy" but that would probably violate some laws or something. – Brian Roach Jun 03 '13 at 19:12
  • 11
    Oh dude :) You really don't know what are you talking about. Living here is really difficult. VPN, SOCKS, Certain IPs, Certain protocols, are blocked. Data transmission is sniffed at both ISP and governmental level. No way you can get real internet here :D – sorush-r Jun 03 '13 at 19:16
  • 19
    Oh wow, I didn't look at your profile until just now. Ignore that I said anything :) Ask any damn thing you want on here, and mention where you are. – Brian Roach Jun 03 '13 at 19:19
  • I know the pain @sorush-r :) glad you made it out of that place man – Yar Apr 06 '22 at 20:42
1
syntax = "proto3";

import "Protos/general.proto";

enter image description here

Laeeq Khan Niazi
  • 568
  • 4
  • 11