# Protocol Buffers

## About

{% embed url="<https://protobuf.dev/>" %}

{% embed url="<https://protobuf.dev/programming-guides/style/>" %}

It is a language-neutral, plataform-neutral, extensible mechanism for serializing structured data, although it can be used with other data formats like JSON.

The data is serialized to **binary**.

The first step is to define the structure for the data to serialize in a proto file `.proto`.

{% code title="proto3" %}

```protobuf
message SearchRequest {
  string query = 1;
  int32 page_number = 2;
  int32 results_per_page = 3;
}
```

{% endcode %}

{% hint style="info" %}
The number right after the fieldname is an index used by gRPC for the serialization.
{% endhint %}

Once the data structures are defined, you use the protocol buffer compiler `protoc` to generate data access classes in whatever language it will be used.

### Versions

Most recent version is `proto3` (Version 3), which has simplified syntax, new features and support more languages.
