Building a Leak-Safe gRPC Frame Decoder on Reactor Netty
This is the second article in my grpc-reactor series. The first article explains why I chose to build the runtime directly on Reactor Netty and where its compatibility boundary sits. This article moves one layer down into the Stage 1 protocol implementation: the frame decoder that every RPC shape relies on. gRPC protobuf messages are not written directly as raw bytes into HTTP/2 DATA frames.…
This article is the second installment in a series exploring the implementation of a gRPC runtime on Reactor Netty. The focus of this article is on the Stage 1 protocol implementation, specifically the frame decoder that is utilized by every RPC shape. gRPC protobuf messages are not transmitted as raw bytes within HTTP/2 DATA frames.
Instead, each message is prefixed with a five-byte envelope. The first byte's least significant bit encodes whether compression is applied, while the next seven bits must be zero. Bytes 1 through 4 represent an unsigned big-endian payload length. Bytes 5 to n contain either the protobuf message itself or its compressed representation.
Decoding this envelope presents a challenge, as it does not assume that each input buffer will contain a complete frame. This is due to the fact that HTTP/2, TCP, and Reactor Netty do not guarantee that buffer boundaries will align with gRPC message boundaries.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written; read the original for the full account.



