View Source Syrup (Syrup v0.1.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 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.
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.
This is mostly useful if
the tuple might be interpreted as forcing a particular encoding.
For example, as_record(as_string("foo"))
will result in encoding
the record {:string, "foo"}
rather than the string "foo"
.
Forces encoding a value as a Syrup string.
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
:tuples
- decodes symbols as tuples with the first element being:symbol
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