livery_grpc_codec (livery_grpc v0.1.0)
View SourceProtobuf encode/decode glue over a gpb-generated module.
A gpb module (e.g. helloworld_pb, built from proto/helloworld.proto)
exposes encode_msg/2 and decode_msg/2. This module wraps them behind a
stable interface so the server and client do not call gpb directly, and so
an alternative codec (for example JSON for application/grpc+json) can be
slotted in later behind the same calls.
Encoding errors are surfaced as {error, {encode|decode, Reason}} rather
than raised, so the caller can turn them into a gRPC internal status.
Summary
Functions
Recognised gRPC content-type values for proto framing.
The default gRPC content type.
Decode protobuf bytes into a message map (gpb maps mode).
Encode a message map/record to protobuf bytes.
Whether a content-type header value names a gRPC proto request. A
trailing parameter (e.g. ;charset=...) is tolerated; the base type is
matched.
Types
Functions
-spec content_subtypes() -> [binary()].
Recognised gRPC content-type values for proto framing.
-spec content_type() -> binary().
The default gRPC content type.
-spec decode(proto_module(), msg_name(), binary()) -> {ok, map() | tuple()} | {error, {decode, term()}}.
Decode protobuf bytes into a message map (gpb maps mode).
-spec encode(proto_module(), msg_name(), map() | tuple()) -> {ok, binary()} | {error, {encode, term()}}.
Encode a message map/record to protobuf bytes.
Whether a content-type header value names a gRPC proto request. A
trailing parameter (e.g. ;charset=...) is tolerated; the base type is
matched.