ExKdl (ex_kdl v0.1.0-rc2) View Source
A robust and efficient decoder and encoder for the KDL Document Language.
Link to this section Summary
Functions
Decodes a KDL-encoded document from the input
binary.
Decodes a KDL-encoded document from the input
binary.
Encodes a list of ExKdl.Node
structs into a KDL-encoded binary.
Encodes a list of ExKdl.Node
structs into a KDL-encoded binary.
Link to this section Functions
Specs
decode(binary()) :: {:ok, [ExKdl.Node.t()]} | {:error, ExKdl.DecodeError.t()}
Decodes a KDL-encoded document from the input
binary.
Examples
iex> ExKdl.decode("node 10")
{:ok,
[
%ExKdl.Node{
name: "node",
type: nil,
values: [%ExKdl.Value{type: nil, value: %Decimal{coef: 10}}],
properties: %{},
children: []
}
]}
iex> ExKdl.decode(~s|node "unterminated string|)
{:error,
%ExKdl.DecodeError{
line: 1,
message: "unterminated string meets end of file"
}}
Specs
decode!(binary()) :: [ExKdl.Node.t()]
Decodes a KDL-encoded document from the input
binary.
Similar to decode/1
except it will raise in the event of an error.
Examples
iex> ExKdl.decode!("node 10")
[
%ExKdl.Node{
name: "node",
type: nil,
values: [%ExKdl.Value{type: nil, value: %Decimal{coef: 10}}],
properties: %{},
children: []
}
]
iex> ExKdl.decode!(~s|node "unterminated string|)
** (ExKdl.DecodeError) Line 1: unterminated string meets end of file
Specs
encode([ExKdl.Node.t()]) :: {:ok, binary()} | {:error, ExKdl.EncodeError.t()}
Encodes a list of ExKdl.Node
structs into a KDL-encoded binary.
Examples
iex> ExKdl.encode([%ExKdl.Node{name: "node", values: [%ExKdl.Value{value: %Decimal{coef: 10}}]}])
{:ok, "node 10\n"}
iex> ExKdl.encode(nil)
{:error, %ExKdl.EncodeError{message: "Argument to encode/1 must be a list of KDL nodes"}}
Specs
encode!([ExKdl.Node.t()]) :: binary()
Encodes a list of ExKdl.Node
structs into a KDL-encoded binary.
Similar to encode/1
except it will raise in the event of an error.
Examples
iex> ExKdl.encode!([%ExKdl.Node{name: "node", values: [%ExKdl.Value{value: %Decimal{coef: 10}}]}])
"node 10\n"
iex> ExKdl.encode!(nil)
** (ExKdl.EncodeError) Argument to encode/1 must be a list of KDL nodes