liveBook · Manning

Protocol buffer

As explained in Quarkus in Action

Protocol Buffers is a language-neutral serialization format that represents structured data using schemas and generated types.

Protocol Buffers, or protobuf, is a compact, efficient, language-independent serialization format for typed structured data. A proto schema describes the messages, while tooling generates language-specific classes that serialize and deserialize them. Binary messages are smaller and faster than JSON, but they are not human-readable. section 4.6.2

A proto file declares proto3 syntax, namespaces, language-specific options, and message fields. Each field has a type, name, and numeric order; generated code follows protobuf naming conventions, such as converting licensePlateNumber to license_plate_number. section 4.6.2

A protobuf workflow typically proceeds as follows:

  • Define messages and, when needed, remote methods in a .proto file. section 4.7
  • Compile the file with protoc, a build-tool plugin, or Quarkus's quarkus-grpc extension. section 4.6.2 section 4.7
  • Use generated message builders for application data and generated client or server stubs for gRPC calls. section 4.6.2 section 4.7

Car message and generated builder

A Car message can contain license_plate_number, manufacturer, model, and id fields. Generated Java code then supports Car.newBuilder(), field setters, build(), and writeTo(outputStream) for constructing and serializing an instance.

Listing 4.31 Describing the Car model using Protocol Buffers
syntax = "proto3";

option java_multiple_files = true;
option java_package = "org.acme.inventory.model";
option java_outer_classname = "InventoryProtos";

package inventory;

message Car {
    string license_plate_number = 1;
    string manufacturer = 2;
    string model = 3;
    int64 id = 4;
}

Inspect the complete proto3 Car schema, including Java generation options, the inventory namespace, field types, and field numbers. section 4.6.2

With Quarkus gRPC, placing inventory.proto under src/main/proto and running ./mvnw clean package generates Java message classes, service bases, and client stubs. This supports compact service communication while leaving business implementations in application code. section 4.7

How Quarkus in Action covers it

How deep it goes
Explains proto3 schemas, field numbering, generated Java builders, serialization, and gRPC stubs without detailing wire encoding.
Examples
Uses Car messages, InventoryService RPC methods, generated builders, and an inventory.proto contract.
What you can do after
Build typed messages and gRPC service contracts, then generate and use Java serialization code and communication stubs.
How it connects
Connects serialization with gRPC, schema compilation, generated Java classes, client stubs, and server stubs.

Also explained in

Compare how 10 books explain protocol buffer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.