packer v0.0.3 Packer

Link to this section Summary

Functions

Decodes iodata to a term. The output of Packer.encode/2 is expected, and this function is indeed symetric to Packer.encode/2. It also supports a similar set of options

Encodes a term. Returns an array with the version-specific magic string, the data schema, and buffer

Returns the magic string header prepended to encodings. The type parameter can be :none, :full or :version. The default is :version, which is a minimal prefix of one byte containing the version of the encoding

Link to this section Types

Link to this type decode_options()
decode_options() :: [compress: boolean(), header: :version | :full | :none]
Link to this type encode_options()
encode_options() :: [
  compress: boolean(),
  short_int: boolean(),
  header: :version | :full | :none,
  format: :iolist | :binary
]

Link to this section Functions

Link to this function decode(data, opts \\ [])
decode(data :: iodata(), opts :: decode_options()) :: any()

Decodes iodata to a term. The output of Packer.encode/2 is expected, and this function is indeed symetric to Packer.encode/2. It also supports a similar set of options:

  • compress: boolean, defaults to true; if the payload was not compressed, leaving this as true will be less efficient but should not be harmful
  • header: the type of header that is expected, from :version (the default), :full, or :none
Link to this function encode(term, opts \\ [])
encode(term :: any(), opts :: encode_options()) :: iolist()

Encodes a term. Returns an array with the version-specific magic string, the data schema, and buffer.

Options supported include:

  • compress: boolean, defaulting to true
  • small_int: boolean, defaulting to true. When false integers that would fit into a single byte are instead encoded in 2 bytes; for large terms with a mix of single- and two-byte encodable integers, setting small_int to false to can result in a significantly smaller schema
  • header: atom, defaulting to :version; controls what sort of header information, if any, to prepend to return. Recognized values: :version -> the version number of the encoding is prepended :full -> a header suitable for durable storage (e.g. a file) is prepended ** :none -> no header; fewer bytes, less safety. buckle up, cowboy!
  • format: atom, defaulting to :iolist; controls the format of the resulting encoding :iolist: returns a list of binaries, [header, schema, data] or [schema, data] :binary: returns a single binary buffer
Link to this function encoded_term_header(type \\ :version)
encoded_term_header(type :: :none | :full | :version) :: String.t()

Returns the magic string header prepended to encodings. The type parameter can be :none, :full or :version. The default is :version, which is a minimal prefix of one byte containing the version of the encoding.