base
Public base classes for defining C-compatible Pydantic models.
Classes:
-
CEncoded–Pydantic annotated metadata declaring how to pack/unpack a value from a C encoded buffer.
-
CFormat–Pydantic annotated metadata declaring the C format for to pack/unpack a value.
-
CModel–Base class for models that can be packed to and unpacked from C-compatible bytes.
CEncoded
dataclass
CEncoded(
get_encoder: Callable[
[EndianType, SizeType], CEncoderSchema[CEncoded[T]]
],
)
Pydantic annotated metadata declaring how to pack/unpack a value from a C encoded buffer.
Attributes:
-
get_encoder(Callable[[EndianType, SizeType], CEncoderSchema[CEncoded[T]]]) –A function that produces a CEncoder for this value given an endianness and size type.
get_encoder
instance-attribute
get_encoder: Callable[
[EndianType, SizeType], CEncoderSchema[CEncoded[T]]
]
A function that produces a CEncoder for this value given an endianness and size type.
CFormat
dataclass
CFormat(
format: str,
validate: Callable[
[tuple[Any, ...]], CFormat[T]
] = lambda x: x,
dump: Callable[
[CFormat[T]], tuple[Any, ...]
] = lambda x: x,
)
Pydantic annotated metadata declaring the C format for to pack/unpack a value.
CModel
Bases: BaseModel
Base class for models that can be packed to and unpacked from C-compatible bytes.
Subclasses behave like normal Pydantic models, but also carry a derived binary
schema that c_pack() and
c_unpack() use to read and write struct data.
Methods:
-
c_pack–Write this model instance to the current position of a binary buffer.
-
c_unpack–Read one model instance from the current position of a binary buffer.
Attributes:
-
c_alignment(int) –Override the alignment of this struct. Native by default (0).
-
c_endian_type(EndianType) –Override the endianness of this struct. Native by default.
-
c_schema(CStructSchema) –The C struct schema for this model, derived from the Pydantic schema of the model
-
c_size_type(SizeType) –Override the size type of this struct. Native by default.
c_alignment
class-attribute
c_alignment: int = 0
Override the alignment of this struct. Native by default (0).
c_endian_type
class-attribute
Override the endianness of this struct. Native by default.
c_schema
class-attribute
The C struct schema for this model, derived from the Pydantic schema of the model
c_size_type
class-attribute
Override the size type of this struct. Native by default.
c_pack
c_pack(buffer: BytesIO) -> None
Write this model instance to the current position of a binary buffer.