pod()

picopod.pod(value, *, binary=False, lz4=False, base64=False, compression_hint=Compression.MTF, encoding='p8scii', invalid_chars='strict')

Serialize a Python object into a Picotron pod.

Parameters:
  • value (Value) –

    The value to serialize.

    This can be a int, float, bool, str, Buffer (bytes), Sequence (list), Mapping (dict), Userdata, or None.

  • binary (bool, optional) –

    If true, encode userdata as binary when possible, and encode byte objects as binary strings. If false, userdata and byte objects will be serialized as strings.

    Setting this to true is roughly equivalent to calling Picotron’s pod() with the 0x1 flag bit (for userdata) or 0x20 flag bit (for strings).

  • lz4 (bool, optional) –

    If true, LZ4-compress the resulting pod. Defaults to false.

    Setting this to true is equivalent to calling Picotron’s pod() with the 0x2 flag bit.

  • base64 (bool, optional) –

    If true, Base64-encode the resulting pod. Defaults to false.

    If lz4 is also true, Base64 encoding applies after compression.

    Note that Picotron’s Base64 encoding scheme uses a custom URL-safe variant where + is replaced with _ and / is replaced with -.

    Setting this to true is equivalent to calling Picotron’s pod() with the 0x4 flag bit.

  • compression_hint (Compression, optional) –

    A suggested compression type for binary userdata. If a userdata format does not support this type, this parameter is ignored.

    Currently, U8 supports MTF, RLE, and RAW, and I16 only supports RLE. Other formats do not support compression. Defaults to MTF for maximum compression.

    Specifying raw for this is equivalent to calling Picotron’s pod() with the 0x10 flag bit.

  • encoding (str, optional) – The codec to encode strings with. Defaults to “p8scii”.

  • invalid_chars (str, optional) –

    The codec error handler to use for invalid characters in strings. Defaults to “strict”.

    By default, attempting to encode a string with no valid representation in the target encoding (P8SCII by default) will raise an error. Pass “ignore” to omit invalid characters altogether, or “replace” to replace them with a placeholder (? for P8SCII).

Returns:

The serialized pod bytes.

Raises:
  • TypeError – The input type cannot be represented in a pod.

  • UnicodeEncodeErrorinvalid_chars is “strict” and a character in a string cannot be represented in the target encoding.