View Source erlfdb_tuple (erlfdb v0.3.1)
Summary
Functions
Compares 2 Erlang tuples with the ordering defined by the tuple layer.
Encodes the tuple into a binary.
Encodes the prefix and tuple into a binary.
With versionstamps, encodes the tuple into a binary.
With versionstamps, encodes the prefix and tuple into a binary.
Returns a {StartKey, EndKey}
pair of binaries that includes all possible sub-tuples.
With prefix, returns a {StartKey, EndKey}
pair of binaries that includes all possible sub-tuples.
Decodes the binary into a tuple.
Decodes the binary into a prefix and tuple.
Functions
Compares 2 Erlang tuples with the ordering defined by the tuple layer.
Return
0
if both tuples compare as equal.-1
if the left tuple is less than the right tuple.1
if the left tuple is greater than the right tuple.
Examples
The ordering isn't equivalent to the Erlang term ordering:
1> lists:sort(fun(A, B) -> erlfdb_tuple:compare(A, B) =< 0 end, [{1}, {null}]).
[{null},{1}]
2> lists:sort([{1}, {null}]).
[{1},{null}]
Encodes the tuple into a binary.
Supported Erlang types
binary/0
: Encodes as binary blob.integer/0
: Encodes as variable-length integer.float/0
: Encodes as 64-bit floating point (double).tuple/0
: Encodes as nested tuple.
Special types
null
: Encodes as NULL char (16#0
) instead of as an atom.boolean/0
: Encodes as a boolean instead of as an atom.{utf8, Bin :: binary()}
: EncodesBin
as UTF-8 string.{float, float()}
: Advanced floating point encoding. Seeerlfdb_float
.{float, _, float()}
: Advanced floating point encoding. Seeerlfdb_float
.{double, _, float()}
: Advanced floating point encoding. Seeerlfdb_float
.{uuid, binary()}
: Encodes a binary of size == 16 as a UUID type.{id64, integer()}
: Encodes a fixed-length 64-bit integer.{versionstamp, Id :: integer(), Batch :: integer()}
: Versionstamp encoding. For unset versionstamps usepack_vs/1
.{versionstamp, Id :: integer(), Batch :: integer(), Tx}
: Versionstamp encoding. For unset versionstamps usepack_vs/1
.
Unsupported Erlang types
Examples
1> erlfdb_tuple:pack({}).
<<>>
1> erlfdb_tuple:pack({<<"hello">>, 42}).
<<1,104,101,108,108,111,0,21,42>>
Encodes the prefix and tuple into a binary.
Examples
1> erlfdb_tuple:pack({}, <<"foo">>).
<<"foo">>
1> erlfdb_tuple:pack({<<"foo">>}, <<>>).
<<1,102,111,111,0>>
1> erlfdb_tuple:pack({<<"hello">>, 42}, <<"foo">>).
<<102,111,111,1,104,101,108,108,111,0,21,42>>
With versionstamps, encodes the tuple into a binary.
Special types
{versionstamp, Id, Batch}
: Versionstamp encoding{versionstamp, Id, Batch, Tx}
: Versionstamp encoding
With versionstamps, encodes the prefix and tuple into a binary.
Returns a {StartKey, EndKey}
pair of binaries that includes all possible sub-tuples.
With prefix, returns a {StartKey, EndKey}
pair of binaries that includes all possible sub-tuples.
Decodes the binary into a tuple.
Examples
1> erlfdb_tuple:unpack(erlfdb_tuple:pack({})).
{}
1> erlfdb_tuple:unpack(erlfdb_tuple:pack({<<"hello">>, 42})).
{<<"hello">>,42}
Decodes the binary into a prefix and tuple.
Examples
1> erlfdb_tuple:unpack(erlfdb_tuple:pack({}, <<"foo">>), <<"foo">>).
{}
1> erlfdb_tuple:unpack(erlfdb_tuple:pack({<<"hello">>, 42}, <<"foo">>), <<"foo">>).
{<<"hello">>,42}