The Protobuf Compiler
Now that we know the Protobuf syntax and the text format, we can finally get our hands dirty and play with the Protobuf compiler. In this section, we are going to generate code from .proto
files, get binary from Protobuf text format, and get text from Protobuf serialized data (binary files).
In this chapter, we’re going to cover the following main topics:
- Downloading and installing
protoc
- Transpiling
.
proto
files - Specifying import paths
- Encoding data to type with
--encode
- Decoding data to type with
--decode
- Decoding data to type, without
.proto
files, with--decode_raw
- What about the other flags?
By the end of this chapter, you will know how to use protoc
’s main flags. You will know how to generate C++ (or any other supported language) code, how to tell protoc
where to find the imported files in your .proto
files, and how to get binary data out of data described with text format.