| Did you know ... | Search Documentation: |
| Pack logtalk -- logtalk-3.100.1/docs/handbook/_sources/libraries/message_pack.rst.txt |
.. _library_message_pack:
message_pack
The message_pack library provides predicates for parsing and
generating data in the `MessagePack https://msgpack.org/`__ format
based on the current specification and reference documents found at:
Open the `../../apis/library_index.html#message_pack <../../apis/library_index.html#message_pack>`__ link in a web browser.
To load all entities in this library, load the loader.lgt file:
::
| ?- logtalk_load(message_pack(loader)).
To test this library predicates, load the tester.lgt file:
::
| ?- logtalk_load(message_pack(tester)).
The following choices of syntax have been made to represent MessagePack elements as terms:
{Pairs}, where
each pair uses the representation Key-Value.chars(List), or
codes(List). Use the message_pack/1 parameterized object with
the parameter bound to atom, chars, or codes to select the
representation used when decoding strings.bytes(List).ext(Type, bytes(Bytes)), where
Type is the signed 8-bit extension type and Bytes is the
extension payload.false, true, and nil are
represented by, respectively, the @false, @true, and @null
compound terms.@infinity, @negative_infinity, and @not_a_number compound
terms.0.0 and -0.0 floats, but
backends that normalize both values to 0.0 cannot preserve the
sign of zero when re-encoding.
The following table exemplifies the term equivalents of common
MessagePack elements when using message_pack(atom):
================= =======================
MessagePack value term
================= =======================
nil @null
false @false
true @true
"foo" foo
[1,2,3] [1,2,3]
{"a":1,"b":true} {a-1, b-@true}
bin payload bytes([...])
extension payload ext(Type, bytes([...]))
================= =======================
message_pack(atom) is usually the
most convenient choice when the rest of the application already works
with atoms. For untrusted input, prefer message_pack(codes) or
message_pack(chars) to avoid interning arbitrary incoming strings
as atoms.message_pack(codes) is generally the best
default choice. It avoids atom creation while preserving the exact
decoded Unicode code points. message_pack(chars) provides the same
safety with a more readable but less compact representation.ext(-1, bytes(Bytes)) representation.cbor, avro,
and protobuf libraries.