pod() and unpod()

Use the pod() function to serialize values:

>>> from picopod import pod
>>> pod(1234)
b'1234'
>>> pod("Hello, world!")
b'"Hello, world!"'
>>> pod([1, 2, 3])
b'{1,2,3}'
>>> pod({"fullscreen": False, "pixel_scale": 3})
b'{fullscreen=false,pixel_scale=3}'

And use unpod() to deserialize them:

>>> from picopod import unpod
>>> unpod("1234")
1234
>>> unpod('"Hello, world!"')
'Hello, world!'
>>> unpod("{1,2,3}")
[1, 2, 3]
>>> unpod("{fullscreen=false,pixel_scale=3}")
{'fullscreen': False, 'pixel_scale': 3}

pod() always returns bytes, but unpod() can accept either bytes or a string.

Error Handling

Unlike in Picotron, unpod() does not return None if an error happens. Instead, errors are raised using subclasses of Error. For example,

try:
   unpod("foo")
except picopod.Error as e:
   print(f"Error: {e}")

will print:

Error: Unexpected token: 'foo'