Skip to content

i64/duckparse

Repository files navigation

duckparse [WIP]

Duckparse is binary parsers for humans. It is similar to Construct and Kaitai. But it's more easy to write.

Duckparse is using PEP 526 type annotations. Check our gallery for more examples!

Example:

>>> from io import BytesIO

>>> from duckparse import stream_parser
>>> from duckparse.btypes import U8, Bits

>>> @stream_parser
... class ExampleFormat:
...     width: U8
...     height: U8
...     some_bitfield: Bits[1]
 
>>> result = ExampleFormat(BytesIO(b"\x03\x02\xFF"))
>>> print(result)
ExampleFormat(width=3, height=2, some_bitfield=1)

Or you can define a new data type or an enum

from duckparse import datakind, enumkind

@datakind
class I64():
    def __processor__(self, reader: Reader) -> bytearray:
        return reader.primitive.i64.unpack(reader.read_bytes(8))[0]

@enumkind
class Color:
    RED = 1
    GREEN = 2
    BLUE = 3

About

Duckparse: binary parsing for humans

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages