livery_grpc_compression (livery_grpc v0.1.0)

View Source

gRPC per-message compression.

Supports identity (no compression) and gzip. The active algorithm is negotiated through the grpc-encoding (what this message used) and grpc-accept-encoding (what the peer can decode) headers.

A frame's compressed flag (see livery_grpc_frame) says whether its payload went through compress/2; identity always leaves the flag clear.

Summary

Functions

The grpc-accept-encoding value advertising what we can decode.

Compress a payload. Returns {Compressed, Bytes}: Compressed is the boolean to put in the frame flag. identity never marks the frame.

Decompress a payload given the frame's compressed flag and the message encoding. A clear flag means the payload is identity-coded regardless of the negotiated algorithm (per the gRPC spec, the flag wins per message).

Parse a grpc-encoding header value into an algorithm. An absent header (undefined) or an unknown value falls back to identity.

Whether an algorithm atom is supported.

Types

algorithm()

-type algorithm() :: identity | gzip.

Functions

accept_header()

-spec accept_header() -> binary().

The grpc-accept-encoding value advertising what we can decode.

compress/2

-spec compress(algorithm(), binary()) -> {boolean(), binary()}.

Compress a payload. Returns {Compressed, Bytes}: Compressed is the boolean to put in the frame flag. identity never marks the frame.

decompress/3

-spec decompress(boolean(), algorithm(), binary()) -> binary().

Decompress a payload given the frame's compressed flag and the message encoding. A clear flag means the payload is identity-coded regardless of the negotiated algorithm (per the gRPC spec, the flag wins per message).

A set flag with an identity encoding is malformed and raises {grpc_compression, flag_set_for_identity}.

from_header/1

-spec from_header(binary() | undefined) -> algorithm().

Parse a grpc-encoding header value into an algorithm. An absent header (undefined) or an unknown value falls back to identity.

is_supported/1

-spec is_supported(algorithm() | term()) -> boolean().

Whether an algorithm atom is supported.