liveBook · Manning

Proto file

As explained in Quarkus in Action

A proto file is a Protocol Buffers definition file that declares messages and service contracts for generated code.

A proto file is a Protocol Buffers definition file. It declares a typed message schema and can define service contracts for generated, language-specific code. Binary protobuf messages are compact and efficient to serialize, though they are not human-readable. section 4.6.2

A proto file typically specifies:

  • The syntax version, such as proto3. section 4.6.2
  • Language-specific generation options, including the Java package, outer class, and whether generated messages use separate files. section 4.6.2
  • A protobuf package that namespaces the declared messages. section 4.6.2
  • Message fields with a type, name, and unique numeric order; camel-case names are compiled into snake_case protobuf names. section 4.6.2
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;
}

The Car definition demonstrates a proto3 schema with Java generation options, an inventory namespace, and four typed fields. section 4.6.2

Generated Java code

Compiling the Car definition can produce a Java message class, builder, and serialization methods. Application code can create a Car with Car.newBuilder(), set its fields, build it, and write the encoded message to an OutputStream. section 4.6.2

Compilation can use protoc, build-tool plugins, or the Quarkus gRPC extension. For a gRPC client, the proto file supplies the service contract from which Quarkus generates stubs; the client then injects a generated stub with @GrpcClient. section 4.6.2 section 4.8.2

How Quarkus in Action covers it

How deep it goes
Explains syntax, namespaces, fields, naming, compilation choices, and generated Java usage without detailing compiler internals.
Examples
Uses an Inventory Car message, generated Java builders, and a Quarkus Inventory gRPC client.
What it assumes
Assumes typed data and Java familiarity while introducing protobuf schemas, generated code, and gRPC contracts.
What you can do after
Builds protobuf messages and consumes gRPC services through generated Java classes and Quarkus client stubs.
How it connects
Connects Protocol Buffers with serialization, schema definition, code generation, gRPC, and generated client stubs.

Also explained in

Compare how 3 books explain proto file →

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.