module
GRPC::Codec
Overview
Codec handles gRPC message framing and optional gzip compression.
Each gRPC message is prefixed with a 5-byte header: Byte 0: Compressed-Flag (0 = not compressed, 1 = gzip compressed) Bytes 1-4: Message-Length (big-endian uint32) — length of the (possibly compressed) body
Defined in:
grpc/codec.crConstant Summary
-
HEADER_SIZE =
5
Class Method Summary
-
.decode(data : Bytes, encoding : String | Nil = nil, validate_encoding : Bool = false, limits : ReceiveLimits = ReceiveLimits.new) : Tuple(Bytes, Int32)
Decode reads one gRPC message from the given Bytes slice.
-
.decode_all(data : Bytes, limits : ReceiveLimits = ReceiveLimits.new) : Array(Bytes)
Decode all gRPC messages from the given Bytes slice.
- .decode_payload(compressed : UInt8, body : Bytes, encoding : String | Nil = nil, validate_encoding : Bool = false, limits : ReceiveLimits = ReceiveLimits.new) : Bytes
-
.encode(message_bytes : Bytes, compress : Bool = false) : Bytes
Encode a protobuf-serialized message into a gRPC DATA frame payload.
- .validate_encoding!(encoding : String | Nil) : Nil
-
.validate_frame_header(compressed : UInt8, length : UInt32, limits : ReceiveLimits = ReceiveLimits.new) : Int32
Bytes and deframer offsets use Int32.
Class Method Detail
Decode reads one gRPC message from the given Bytes slice. Returns {message_bytes, bytes_consumed}. Decompresses gzip-compressed frames automatically. Raises StatusError on incomplete or malformed frames.
Decode all gRPC messages from the given Bytes slice.
Encode a protobuf-serialized message into a gRPC DATA frame payload.
Pass compress: true to gzip-compress the payload.
Bytes and deframer offsets use Int32. Validate the unsigned wire length before conversion or adding the header, and reject bad flags immediately.