polywrap_msgpack.encoder module

This module implements the msgpack encoder for encoding data before sending it to a wrapper.

polywrap_msgpack.encoder.msgpack_encode(value: Any) bytes[source]

Encode any python object into msgpack bytes.

Parameters:

value (Any) – any valid python object

Raises:
Returns:

encoded msgpack value

Return type:

bytes

Examples

>>> from polywrap_msgpack import msgpack_encode
>>> from polywrap_msgpack import msgpack_decode
>>> from polywrap_msgpack import GenericMap
>>> msgpack_encode({"a": 1})
b'\x81\xa1a\x01'
>>> msgpack_encode(GenericMap({"a": 1}))
b'\xd6\x01\x81\xa1a\x01'
>>> msgpack_encode({1.0: 1})
Traceback (most recent call last):
...
polywrap_msgpack.errors.MsgpackSanitizeError: Failed to sanitize object