An implementation of the MessagePack serialization format for Elixir.
It provides functions for encoding and decoding Elixir terms and supports the full MessagePack specification, including the Timestamp and custom Extension types.
- Specification Compliance: Implements the complete MessagePack type system.
- Elixir Struct Support: Encodes and decodes
DateTime
andNaiveDateTime
structs via the Timestamp extension type. - Configurable Validation: Provides an option to bypass UTF-8 validation on strings for performance-critical paths.
- Resource Limiting: Includes configurable
:max_depth
and:max_byte_size
limits to mitigate resource exhaustion from malformed or malicious payloads. - Telemetry Integration: Emits standard
:telemetry
events for integration with monitoring tools.
Add msgpack_elixir
to your list of dependencies in mix.exs
:
def deps do
[{:msgpack_elixir, "~> 1.0.0"}]
end
Then, run mix deps.get
.
# Encode a map. Atom keys are converted to strings by default.
iex> data = %{id: 1, name: "Elixir"}
iex> {:ok, encoded} = Msgpack.encode(data)
<<130, 162, 105, 100, 1, 164, 110, 97, 109, 101, 166, 69, 108, 105, 120, 105, 114>>
# Decode a binary.
iex> Msgpack.decode(encoded)
{:ok, %{"id" => 1, "name" => "Elixir"}}
# Use the exception-raising variants for exceptional failure cases.
iex> Msgpack.decode!(<<0xC1>>)
** (Msgpack.DecodeError) Unknown type prefix: 193. The byte `0xC1` is not a valid MessagePack type marker.
For detailed information on all features, options, and functions, see the full documentation on HexDocs, which contains a complete API reference for all public modules and functions.
This section explains how to setup the project locally for development.
- Elixir
~> 1.7
(OTP 21+)
Clone the project locally:
# via HTTPS
git clone https://github.com/nrednav/msgpack_elixir.git
# via SSH
git clone git@github.com:nrednav/msgpack_elixir.git
Install the project's dependencies:
cd msgpack_elixir/
mix deps.get
Run the test suite:
mix test
Run the benchmarks:
mix run bench/run.exs
This project uses Semantic Versioning. For a list of available versions, see the repository tag list.
If you encounter a bug or have a feature request, please open an issue on the GitHub repository.
Public contributions are welcome! If you would like to contribute, please fork the repository and create a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.