Protocol Buffer (protobuf) are a language-neutral, platform-neutral extensible mechanism for serializing structured data
https://developers.google.com/protocol-buffers
Frameworks That Use Protocol Buffers
Installation
protoc - is compiler that takes a .proto file and outputs code in the specified language
from source
download the package and follow the instructions in the README
homebrew
brew search protobuf
brew install protobuf
Example Use
example .proto file
syntax = "proto2";
package tutorial;
option java_package = "com.example.tutorial";
option java_outer_classname = "AddressBookProtos";
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
required string number = 1;
optional PhoneType type = 2 [default = HOME];
}
repeated PhoneNumber phones = 4;
}
message AddressBook {
repeated Person people = 1;
}
now run the compiler, specifying the source directory (where your application’s source code lives – the current directory is used if you don’t provide a value), the destination directory (where you want the generated code to go; often the same as $SRC_DIR), and the path to your .proto
protoc -I=$SRC_DIR --java_out=$DST_DIR $SRC_DIR/addressbook.proto—java_out - specifies we want Java code (similar options are provided for other supported languages)