View Source GRPC.Message (grpc v0.8.1)

Transform data between encoded protobuf and HTTP/2 body of gRPC.

gRPC body format is:

http://www.grpc.io/docs/guides/wire.html Delimited-Message -> Compressed-Flag Message-Length Message Compressed-Flag -> 0 / 1 # encoded as 1 byte unsigned integer Message-Length -> {length of Message} # encoded as 4 byte unsigned integer Message -> *{binary octet}

Summary

Functions

Transforms gRPC body into Protobuf data.

Transform gRPC body into Protobuf data with compression.

Get message data from data buffer.

Transforms Protobuf data into a gRPC body binary.

Functions

@spec from_data(binary()) :: binary()

Transforms gRPC body into Protobuf data.

Examples

iex> GRPC.Message.from_data(<<0, 0, 0, 0, 8, 1, 2, 3, 4, 5, 6, 7, 8>>)
<<1, 2, 3, 4, 5, 6, 7, 8>>
@spec from_data(map(), binary()) :: {:ok, binary()} | {:error, GRPC.RPCError.t()}

Transform gRPC body into Protobuf data with compression.

Examples

iex> GRPC.Message.from_data(%{compressor: nil}, <<0, 0, 0, 0, 8, 1, 2, 3, 4, 5, 6, 7, 8>>)
{:ok, <<1, 2, 3, 4, 5, 6, 7, 8>>}

Get message data from data buffer.

Examples

iex> GRPC.Message.get_message(<<0, 0, 0, 0, 8, 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0>>)
{{0, <<1, 2, 3, 4, 5, 6, 7, 8>>}, <<0, 0, 0>>}
iex> GRPC.Message.get_message(<<1, 0, 0, 0, 8, 1, 2, 3, 4, 5, 6, 7, 8>>)
{{1, <<1, 2, 3, 4, 5, 6, 7, 8>>}, <<>>}
iex> GRPC.Message.get_message(<<0, 0, 0, 0, 8, 1, 2, 3, 4, 5, 6, 7>>)
false
Link to this function

get_message(data, compressor)

View Source
Link to this function

to_data(message, opts \\ [])

View Source
@spec to_data(
  iodata(),
  keyword()
) :: {:ok, iodata(), non_neg_integer()} | {:error, String.t()}

Transforms Protobuf data into a gRPC body binary.

Options

  • :compressor - the optional GRPC.Compressor to be used.
  • :iolist - if true, encodes the data as an t:iolist() instead of a t:binary()
  • :max_message_length - the maximum number of bytes for the encoded message.

Examples

iex> message = ["m", [["es", "sa"], "ge"]]
iex> GRPC.Message.to_data(message)
{:ok, <<0, 0, 0, 0, 7, "message">>, 12}
iex> GRPC.Message.to_data(message, iolist: true)
{:ok, [0, <<0, 0, 0, 7>>, ["m", [["es", "sa"], "ge"]]], 12}

Error cases:

iex> message = <<1, 2, 3, 4, 5, 6, 7, 8, 9>>
iex> GRPC.Message.to_data(message, %{max_message_length: 8})
{:error, "Encoded message is too large (9 bytes)"}