Today I learned what is protobufs. “Protocol Buffers are a language-neutral, platform-neutral extensible mechanism for serializing structured data”. Or, in human language, it is a set of rules of what data of a certain kind looks like.
In many languages, there are primitive data types such as int32, string, boolean, array (often called as list or slice), and map (of key-value). Some languages define a way to create more complex and user-defined data types.
type Computer struct {
NumCpuCores int
RamSize int
HaveWifi bool
Devices []string
PartitionSize map[string]int
}
struct product {
int num_cpu_cores;
double ram_size;
bool have_wifi;
string devices[256]
map<string,int> partition_size
} ;
Why is that important? sometimes we want a set of different kinds of values of a specific type to pass together. In the example above we define what info about a computer looks like. But how it is related to profobufs? – well, a protobuf is a common way to define how data will look like when it is used in multiple languages, say you have a client written in Go and a server written in Java. Using the protocol buffers a client can serialize (transfer the data from its multi-type variables to binary data) the go struct and send it as bytes to the server, whereas the server can de-serialize it and read it in Java language.
Protobuff has a lot more interesting features, such as:
- serialize can compress the size of the data
- highly configurable fields options (onof fileds, optional/required, tagging, etc..)
- rpc definitions
- and more
Check out Google’s protocol-buffers page: https://developers.google.com/protocol-buffers