Package org.mockserver.grpc
Class IncrementalGrpcFrameDecoder
java.lang.Object
org.mockserver.grpc.IncrementalGrpcFrameDecoder
Incremental gRPC length-prefixed frame decoder that accumulates across multiple
feed() calls, retaining any trailing partial bytes for the next call.
Unlike GrpcFrameCodec.decode(byte[]), which operates on a complete buffer
and discards trailing partial frames (line ~49), this decoder preserves partial frames
across feeds so that a gRPC message split across multiple HTTP/2 DATA frames is
reassembled correctly.
Each gRPC frame has a 5-byte header: [1-byte compressed flag][4-byte big-endian length][payload].
Thread-safety: NOT thread-safe. Expected to be used by a single Netty I/O thread
(per-stream handler, NOT @Sharable).
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a decoder with the default max buffer size (8 MiB).IncrementalGrpcFrameDecoder(int maxBufferSize) Creates a decoder with a custom max buffer size. -
Method Summary
Modifier and TypeMethodDescriptionList<byte[]>feed(byte[] chunk) Feeds a chunk of bytes into the decoder and returns a list of complete gRPC message payloads (after stripping the 5-byte header and decompressing if needed).booleanReturnstrueif there are buffered bytes awaiting more data to form a complete frame.
-
Constructor Details
-
IncrementalGrpcFrameDecoder
public IncrementalGrpcFrameDecoder()Creates a decoder with the default max buffer size (8 MiB). -
IncrementalGrpcFrameDecoder
public IncrementalGrpcFrameDecoder(int maxBufferSize) Creates a decoder with a custom max buffer size.- Parameters:
maxBufferSize- maximum number of bytes that may be buffered; if exceeded aGrpcExceptionis thrown fromfeed(byte[])
-
-
Method Details
-
feed
Feeds a chunk of bytes into the decoder and returns a list of complete gRPC message payloads (after stripping the 5-byte header and decompressing if needed).Any trailing partial bytes are retained internally for the next feed.
- Parameters:
chunk- bytes to append (may be empty ornull)- Returns:
- list of complete message payloads (never
null; may be empty) - Throws:
GrpcException- if the total buffered bytes exceed the configured cap, or if a frame header has invalid flag bits or exceedsMAX_MESSAGE_SIZE
-
hasBufferedBytes
public boolean hasBufferedBytes()Returnstrueif there are buffered bytes awaiting more data to form a complete frame.
-