View Source Syrup (Syrup v0.4.0)
A Syrup parser and generator in pure Elixir.
Syrup is a simple data serialization format that is easy to read and write by humans. See https://github.com/ocapn/syrup for more information.
See the Syrup.Encoder module for information on implementing the protocol for structures.
Summary
Functions
Forces encoding a value as a Syrup binary.
Forces encoding a value as a Syrup record.
Forces encoding a value as a Syrup string.
Forces encoding as a symbol without creating an atom.
Parses a Syrup value from input iodata.
Parses a Syrup value from input iodata.
Encodes a value to Syrup.
Functions
Forces encoding a value as a Syrup binary.
Forces encoding a value as a Syrup record.
Forces encoding a value as a Syrup string.
Forces encoding as a symbol without creating an atom.
Parses a Syrup value from input iodata.
Options
:symbols- controls how symbols are decoded. Possible values are::strings(default) - decodes symbols as binary strings:atoms- decodes symbols as atoms usingString.to_atom/1:atoms!- decodes symbols as atoms usingString.to_existing_atom/1:structs- decodes symbols asSyrup.Types.Symbolstructs
Decoding symbols to atoms
The :atoms option uses the String.to_atom/1 call that can create atoms at runtime.
Since the atoms are not garbage collected, this can pose a DoS attack vector when used
on user-controlled data.
Examples
iex> Syrup.decode("{}")
{:ok, %{}}
iex> Syrup.decode("invalid")
{:error, %Syrup.DecodeError{message: "invalid data"}}
Parses a Syrup value from input iodata.
Raises an exception if the input is invalid.
Encodes a value to Syrup.
Options
:binaries- controls how binaries are encoded. Possible values are::strings(default) - encodes Elixir binaries as Syrup strings if they are valid UTF-8 sequences:binaries- encodes Elixir binaries as Syrup binaries regardless of their UTF-8 validity