module

GRPC::Codec

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

Constants

HEADER_SIZE = 5

Class methods

decode(data : Bytes, encoding : String | Nil = nil, validate_encoding : Bool = false) : Tuple(Bytes, Int32)

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.

Source
decode_all(data : Bytes) : Array(Bytes)

Decode all gRPC messages from the given Bytes slice.

Source
decode_payload(compressed : UInt8, body : Bytes, encoding : String | Nil = nil, validate_encoding : Bool = false) : Bytes
Source
encode(message_bytes : Bytes, compress : Bool = false) : Bytes

Encode a protobuf-serialized message into a gRPC DATA frame payload. Pass compress: true to gzip-compress the payload.

Source
validate_encoding!(encoding : String | Nil) : Nil
Source