livery_grpc_wire (livery_grpc v0.1.0)

View Source

Message <-> wire glue shared by the server and the client.

Combines the three wire concerns into one place: protobuf coding (livery_grpc_codec), per-message compression (livery_grpc_compression), and length-prefixed framing (livery_grpc_frame). The server and client encode and decode messages through here so the rules stay identical on both sides.

Summary

Functions

Decode every whole frame in Bin as MsgName. Returns {error, incomplete} if a trailing partial frame remains, or the first frame's decode error. Max caps a single message's declared length.

Decode one framed message: decompress per the frame flag and message Encoding, then protobuf-decode as MsgName.

Encode one message to a wire frame: protobuf-encode, compress with Algorithm, then length-prefix.

Functions

decode_all(Proto, MsgName, Encoding, Bin, Max)

-spec decode_all(module(),
                 atom(),
                 livery_grpc_compression:algorithm(),
                 binary(),
                 non_neg_integer() | infinity) ->
                    {ok, [map() | tuple()]} | {error, term()}.

Decode every whole frame in Bin as MsgName. Returns {error, incomplete} if a trailing partial frame remains, or the first frame's decode error. Max caps a single message's declared length.

decode_frame/4

-spec decode_frame(module(), atom(), livery_grpc_compression:algorithm(), livery_grpc_frame:frame()) ->
                      {ok, map() | tuple()} | {error, term()}.

Decode one framed message: decompress per the frame flag and message Encoding, then protobuf-decode as MsgName.

encode(Proto, MsgName, Msg, Algorithm)

-spec encode(module(), atom(), map() | tuple(), livery_grpc_compression:algorithm()) ->
                {ok, iodata()} | {error, {encode, term()}}.

Encode one message to a wire frame: protobuf-encode, compress with Algorithm, then length-prefix.