Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 391
sorush-r Avatar asked Jun 03 '13 18:06

sorush-r


People also ask

What are .proto files?

A . proto file is similar to a JSON file in that it represents structured data, but you can run a compiler on the . proto file to generate code that can read and write the data in the programming language of your choice. For more information about protocol buffers, see Protocol Buffer Developer Guide on Google's site.

What is repeated Protobuf?

namespace google::protobuf. RepeatedField and RepeatedPtrField are used by generated protocol message classes to manipulate repeated fields. These classes are very similar to STL's vector, but include a number of optimizations found to be useful specifically in the case of Protocol Buffers.

How do protocol buffers work?

The Protobuf is a binary transfer format, meaning the data is transmitted as a binary. This improves the speed of transmission more than the raw string because it takes less space and bandwidth. Since the data is compressed, the CPU usage will also be less.

Does gRPC use protocol buffers?

By default, gRPC uses Protocol Buffers, Google's mature open source mechanism for serializing structured data (although it can be used with other data formats such as JSON). Here's a quick intro to how it works.


1 Answers

import "myproject/base.proto"; 

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

like image 90
Brian Roach Avatar answered Sep 19 '22 18:09

Brian Roach