> For the complete documentation index, see [llms.txt](https://motivlabs.gitbook.io/impulse-dev-manual/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://motivlabs.gitbook.io/impulse-dev-manual/grpc/protocol-buffer-compiler.md).

# Protocol buffer compiler

While not mandatory, gRPC applications often leverage Protocol Buffers for service definitions and data serialization. All the services in Impulse uses version 3 of the protocol buffer language (proto3).

The protocol buffer compiler, protoc, is used to compile `.proto` files, which contain service and message definitions.

## How to install protoc

{% embed url="<https://grpc.io/docs/protoc-installation/>" %}

### Mac OS

#### Install Protocol buffer compiler, protoc

```shell
brew install protobuf
protoc --version  # Ensure compiler version is 3+
```

#### Install Go plugins for the protocol compiler

```shell
cd ~

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
```

#### Update your PATH so that the protoc compiler can find the plugins:

```shell
export PATH="$PATH:$(go env GOPATH)/bin"
```

## Compile .proto file

#### **Regular Microservices (Depends on the go-grpc)**

When compiling `.proto` files from a microservice it is important to notice there is a dependency with the `go-grpc` module, meaning, it needs to exist.

```shell
protoc --go_out=./generated --go_opt=paths=source_relative \
    --go-grpc_out=./generated --go-grpc_opt=paths=source_relative \
    grpc/*.proto --proto_path=../go-grpc --proto_path=.
```

#### Microservices with no dependencies with the go-grpc module

```shell
protoc --go_out=./generated --go_opt=paths=source_relative \
    --go-grpc_out=./generated --go-grpc_opt=paths=source_relative \
    grpc/*.proto --proto_path=.
```

#### **From the go-grpc module:**

For cases where the generic gRPC messages used by all the microservices existing in the `go-grpc` module need to be updated.

```shell
protoc --go_out=./generated --go_opt=paths=source_relative \
    --go-grpc_out=./generated --go-grpc_opt=paths=source_relative \
    grpc/*.proto --proto_path=.
```
