livery_grpc_status (livery_grpc v0.1.1)

View Source

gRPC status codes and status metadata.

The 17 canonical codes (0 OK through 16 UNAUTHENTICATED) as atoms, with conversions to and from the integer used in the grpc-status trailer/header. Also encodes and decodes the grpc-message value, which uses gRPC's percent-encoding (only %x20-%x7E minus % pass through literally; everything else is %-escaped).

Summary

Functions

The integer code for a status atom.

Decode a percent-encoded grpc-message value.

Percent-encode a UTF-8 message for the grpc-message header. Printable ASCII except % passes through; every other byte becomes %XX.

Parse a grpc-status value into a status atom.

Whether the term is a known status atom.

The status atom for an integer code. Unknown integers map to unknown, so a peer using a code we do not model still yields a usable value.

Render a status (atom or integer) as the grpc-status value.

Status trailers with no message.

Status trailers carrying a (percent-encoded) message.

Types

code()

-type code() :: 0..16.

status()

-type status() ::
          ok | cancelled | unknown | invalid_argument | deadline_exceeded | not_found | already_exists |
          permission_denied | resource_exhausted | failed_precondition | aborted | out_of_range |
          unimplemented | internal | unavailable | data_loss | unauthenticated.

Functions

code/1

-spec code(status()) -> code().

The integer code for a status atom.

decode_message(Bin)

-spec decode_message(binary()) -> binary().

Decode a percent-encoded grpc-message value.

encode_message(Msg)

-spec encode_message(binary()) -> binary().

Percent-encode a UTF-8 message for the grpc-message header. Printable ASCII except % passes through; every other byte becomes %XX.

from_binary(Bin)

-spec from_binary(binary()) -> status().

Parse a grpc-status value into a status atom.

is_code/1

-spec is_code(term()) -> boolean().

Whether the term is a known status atom.

name/1

-spec name(integer()) -> status().

The status atom for an integer code. Unknown integers map to unknown, so a peer using a code we do not model still yields a usable value.

to_binary/1

-spec to_binary(status() | code()) -> binary().

Render a status (atom or integer) as the grpc-status value.

trailers(Status)

-spec trailers(status() | code()) -> [{binary(), binary()}].

Status trailers with no message.

trailers/2

-spec trailers(status() | code(), binary()) -> [{binary(), binary()}].

Status trailers carrying a (percent-encoded) message.