https://github.com/moreal/pystructs
Useful django-model like struct package for human
https://github.com/moreal/pystructs
bytes django-model-like marshalling pypi-package python python-library struct
Last synced: 7 months ago
JSON representation
Useful django-model like struct package for human
- Host: GitHub
- URL: https://github.com/moreal/pystructs
- Owner: moreal
- Created: 2019-06-09T13:25:28.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-11-19T11:54:50.000Z (about 1 year ago)
- Last Synced: 2025-05-24T22:07:56.926Z (8 months ago)
- Topics: bytes, django-model-like, marshalling, pypi-package, python, python-library, struct
- Language: Python
- Homepage:
- Size: 77.1 KB
- Stars: 5
- Watchers: 0
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
# pystructs
[](https://pystructs.readthedocs.io/en/latest/?badge=0.2.1)
[](https://travis-ci.com/moreal/pystructs)
[](https://codecov.io/gh/moreal/pystructs)
[](https://pystructs-slack-application.herokuapp.com/)
`pystructs` is useful `c-like struct` package for human
## How to install
```bash
$ pip install pystructs
```
## Example codes
```python
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
```
## Contributing Guide
You can see [CONTRIBUTING.md][contributing]
[contributing]: ./CONTRIBUTING.md