Skip to content
useful c-like struct package for human
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/ISSUE_TEMPLATE
docs
examples
pystructs
tests
.gitignore
.readthedocs.yml
.travis.yml
Pipfile
Pipfile.lock
README.md
setup.py

README.md

pystructs

Documentation Status Build Status codecov slack

pystructs is useful c-like struct package for human

How to install

$ pip install pystructs

Example codes

from typing import List
from pystructs import fields


class Attribute(fields.Struct):
    type = fields.BytesField(size=1)
    length = fields.Int32Field(byteorder='big')
    value = fields.VariableBytesField(related_field='length')


class StunMessage(fields.Struct):
    type = fields.BytesField(size=1)
    length = fields.Int32Field(byteorder='big')
    attributes: List[Attribute] = fields.MultipleField(count='length', field=Attribute())


message = StunMessage(
    b'\x09\x00\x00\x00\x02'
    b'\x01\x00\x00\x00\x03\x12\x34\x56'
    b'\x02\x00\x00\x00\x03\x12\x34\x56')

message.initialize()

print(message.length)  # 2
print(message.attributes[0].length)  # 3
print(message.attributes[1].length)  # 3
You can’t perform that action at this time.