View Source Syrup.Record (Syrup v0.3.0)
A record is a labeled tuple representing an Elixir struct.
Declaring a Syrup record defines a struct with the arguments and a Syrup encoder using the record format.
Example:
defmodule MyRecord do
use Syrup.Record
syrup do
label :my_record
argument :name, :string, public?: true
end
end
record = %MyRecord{name: "foo"}
assert Syrup.decode!(Syrup.encode!(record)) == {:my_record, "foo"}
MyRecord.from_syrup_record({:my_record, "foo"}) == {:ok, %MyRecord{name: "foo"}}
MyRecord.from_syrup(Syrup.encode!(record)) == {:ok, %MyRecord{name: "foo"}}
Arguments must be marked as public?
to be serialized by Syrup. The default is false
(not to include it) so that the inclusion of data in the serialization is a deliberate choice.