SCRC v0.4.0 Scrc.Mapper View Source
Mapper implements a custom DSL to map an SCRC Binary string to typed native fields and vice versa.
defmodule Scrc.InitData do
use Scrc.Mapper
defstruct name: "SCR",
angles: [0, 0]
prefix :name, :string
field "init", :angles, [:float]
end
iex> data = Scrc.InitData.from_binary("SCR(init 0 2)")
%Scrc.InitData{angles: [0.0, 2.0], name: "SCR"}
iex> Scrc.InitData.to_binary(data)
"SCR(init 0.0 2.0)"
Link to this section Summary
Functions
Declare a field with name (external and internal, type and options
Declare a prefix field with name internal and type (String in most cases)
Link to this section Types
Link to this section Functions
Declare a field with name (external and internal, type and options.
name
- Field specifier how it appears in the binarykey
- Field specifier to use in the structtype
- Can be:float
or:integer
. Also allows lists using[:float]
and[:integer]
opts
- Allows to specifiy clipping and default valuesdefault: value
- Specify default valueclip: {min, max}
- Clips the number to min-maxclip: [val1, val2, ..., valn]
- Clips the number to one of the values -nil
if not in the list
Declare a prefix field with name internal and type (String in most cases).
key
- Field specifier to use in the structtype
- Ignored