Skip to main content

Pythonic implementation of the 'postcard' wire format

Project description

Pohlednice

Pohlednice is a pythonic implementation of the postcard wire format.

Usage

Variable integer:

from pohlednice import I16, I32

I16.to_bytes(400) // a byte iterator
bytes(I16.to_bytes(400)) // transform into bytes

// or chain multiple
chain(I16.to_bytes(3600), I32.to_bytes(55))

// read from a byte iterable
number I16.from_bytes([1])

De/Serialize Structure:

from pohlednice import Struct, U16, String, Option, ByteArray

class ABC(Struct):
    a: U16
    b: String
    c: Option[ByteArray]


payload = bytes(ABC.to_bytes(ABC(40, 'Trollě', None)))

abc = ABC.from_bytes(payload)

De/Serialize Enum:

class Color(Enum):
    Red: None
    Blue: None
    Green: None
    Custom: Tuple[U8, U8, U8]

payload = Color.to_bytes(Color.Custom((0xff, 0xf0, 0x0f)))
color = Color.from_bytes(payload)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pohlednice-0.2.1.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

pohlednice-0.2.1-py3-none-any.whl (7.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page