Spacetimedbex.BSATN.ValueEncoder (spacetimedbex v0.1.2)

Copy Markdown View Source

Schema-driven BSATN encoding. Inverse of RowDecoder.decode_value/2.

Encodes Elixir values into BSATN binary using algebraic type information from the schema, so callers don't need to know the wire format.

Summary

Functions

Encode reducer arguments from a map of param names to values.

Encode an Elixir value to BSATN binary given its algebraic type.

Functions

encode_reducer_args(args_map, params)

Encode reducer arguments from a map of param names to values.

Uses the reducer's param definitions (from schema) to encode each argument in the correct order as a BSATN product.

Parameters

  • args_map - Map of %{"param_name" => value} or %{param_name: value}
  • params - List of %{name: String.t(), type: algebraic_type()} from schema

encode_value(val, type)

Encode an Elixir value to BSATN binary given its algebraic type.

Examples

iex> encode_value(42, :u32)
{:ok, <<42, 0, 0, 0>>}

iex> encode_value("hello", :string)
{:ok, <<5, 0, 0, 0, "hello">>}