MeshxRpc.Protocol.Default.serialize

You're seeing just the function serialize, go back to MeshxRpc.Protocol.Default module for more information.

Specs

serialize(term :: term(), opts :: Keyword.t()) ::
  {:ok, result :: binary(), serialization_flag :: 0..255}
  | {:error, reason :: term()}

Serializes given Erlang term to binary with :erlang.term_to_binary/2.

If successful function returns serialized binary as result and serialization_flag.

If user provided term is of binary type, serialization step is skipped and serialization_flag is set to 0. Otherwise :erlang.term_to_binary(term, opts) is called and serialization_flag is set to 1.

Function argument opts is passed as options to :erlang.term_to_binary/2. Serialization options can be used to force binary data compression, which by default is disabled.

iex(1)> {:ok, bin, ser_flag} = MeshxRpc.Protocol.Default.serialize(%{test_k: "test_v"}, [])
{:ok,
<<131, 116, 0, 0, 0, 1, 100, 0, 6, 116, 101, 115, 116, 95, 107, 109, 0, 0, 0,
 6, 116, 101, 115, 116, 95, 118>>, 1}
iex(2)> MeshxRpc.Protocol.Default.deserialize(bin, [], ser_flag)
{:ok, %{test_k: "test_v"}}
iex(3)> {:ok, bin, ser_flag} = MeshxRpc.Protocol.Default.serialize("test", [])
{:ok, "test", 0}
iex(4)> MeshxRpc.Protocol.Default.deserialize(bin, [], ser_flag)
{:ok, "test"}