Protocol Buffers is a binary format for structured message payloads, designed for compactness and efficient processing. Numeric field tags identify values, letting consumers skip unknown tags when their local schema is missing fields or has changed. section 8.1.6
Message structures are defined in a typed IDL. A compiler generates message classes and serialization code; this API-first workflow requires extra tooling, but can let statically typed clients catch API misuse at compile time. section 8.1.6
With gRPC, the Protocol Buffers-based IDL defines services and request/response messages. The compiler generates client stubs and server code; clients and servers exchange binary messages over HTTP/2. section 8.2.3
Table 8.3 The benefits and drawbacks of text-based vs. binary formats for message payloads
|
Format |
Benefits |
Drawbacks |
|
Text |
|
|
|
Binary |
|
|
Compare the compactness and processing benefits of binary payloads with their tooling and readability drawbacks. section 8.1.6
Listing 8.1 An excerpt of the gRPC API for the Order Service
package net.chrichardson.ftgo.orderservice_v1;
service OrderService {
rpc createOrder(CreateOrderRequest) returns (CreateOrderReply) {}
rpc cancelOrder(CancelOrderRequest) returns (CancelOrderReply) {}
rpc reviseOrder(ReviseOrderRequest) returns (ReviseOrderReply) {}
...
}
message CreateOrderRequest {
int64 restaurantId = 1;
int64 consumerId = 2;
repeated LineItem lineItems = 3;
...
}
message LineItem {
string menuItemId = 1;
int32 quantity = 2;
}
message CreateOrderReply {
int64 orderId = 1;
}
...
Inspect an Order Service definition and see numeric tags on request-message fields. section 8.2.3











