#
Supported Types
See: Format characters
#
Padding
Simple padding, it will create N
empty bytes when packing, and void them when reading.
from struct_model import *
class Form(StructModel):
pad: Padding(10)
#
Boolean
The '?' conversion code corresponds to the _Bool type defined by C99. If this type is not available, it is simulated using a char. In standard mode, it is always represented by one byte.
from struct_model import *
class Form(StructModel):
is_alive: Bool
#
Integers
from struct_model import *
class Form(StructModel):
id: uInt8
#
Floats
*Float2 is Half-precision floating-point format
from struct_model import *
class Form(StructModel):
pos_x: Float8
pos_y: Float8
#
Decimal
from struct_model import *
class Form(StructModel):
balance: Decimal(4)
#
Char
One-byte character
from struct_model import *
class Form(StructModel):
letter: Char
#
Strings
String
and PascalString
accepts amount: int = 1
- length, strip_null: bool = True
- remove NULL bytes when
parsing or not.
The 'p' format character encodes a “Pascal string”, meaning a short variable-length string stored in a fixed number of bytes, given by the count. The first byte stored is the length of the string, or 255, whichever is smaller. The bytes of the string follow. If the string passed in to pack() is too long (longer than the count minus 1), only the leading count-1 bytes of the string are stored. If the string is shorter than count-1, it is padded with null bytes so that exactly count bytes in all are used. Note that for unpack(), the 'p' format character consumes count bytes, but that the string returned can never contain more than 255 bytes.
from struct_model import *
class Form(StructModel):
username: String(64)
#
UUID
from struct_model import *
class Form(StructModel):
uuid: UUID