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.cr

Constant Summary

HEADER_SIZE = 5

Class Method Summary

Class Method Detail

def self.decode(data : Bytes) : 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.


[View source]
def self.decode_all(data : Bytes) : Array(Bytes) #

Decode all gRPC messages from the given Bytes slice.


[View source]
def self.decode_payload(compressed : UInt8, body : Bytes) : Bytes #

[View source]
def self.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.


[View source]