c-like struct implementation for human
Project description
pystructs
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
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
pystructs-0.3.0.tar.gz
(5.2 kB
view details)
File details
Details for the file pystructs-0.3.0.tar.gz
.
File metadata
- Download URL: pystructs-0.3.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6655d3ed06bae82ed6508272eebd783f5c316d946e751470ab473ec2b28deff8 |
|
MD5 | 7add1591e4e5f1f61a0b83c43404f8b3 |
|
BLAKE2b-256 | b5beafa2f932b20a5e0cf532bedfacf3e042aa6e88a36b4bc7c0b78d941caeff |