wpiutil.wpistruct functions

wpiutil.wpistruct.forEachNested(t: type, fn: Callable[[str, str], None]) None

Call a function to retrieve the (type string, schema) for each nested struct

wpiutil.wpistruct.getSchema(t: type) str

Retrieve schema for the specified type

wpiutil.wpistruct.getSize(t: type) int

Returns the serialized size in bytes

wpiutil.wpistruct.getTypeString(t: type) str

Retrieve the type string for the specified type

wpiutil.wpistruct.make_wpistruct(cls=None, /, *, name: str | None = None)[source]

This decorator allows you to easily define a custom type that can be used with wpilib’s custom serialization protocol (for use in datalog and networktables). Just create a normal python dataclass, and apply this decorator to the class.

For example, here’s how you define a dataclass that contains an integer, a boolean, and a double:

@wpiutil.wpistruct.make_wpistruct(name="mystruct")
@dataclasses.dataclass
class MyStruct:
    x: wpiutil.wpistruct.int32
    y: bool
    z: wpiutil.struct.double

The types defined in the dataclass can be another WPIStruct compatible class (either builtin or user defined); one of int, bool, or float; or you can use one of the wpiutil.wpistruct.[u]int* values for explicitly sized integer types.

wpiutil.wpistruct.pack(v: object) bytes

Serialize object into byte buffer

wpiutil.wpistruct.packInto(v: object, b: Buffer) None

Serialize object into byte buffer. Buffer must be exact size.

wpiutil.wpistruct.unpack(t: type, b: Buffer) object

Convert byte buffer into object of specified type. Buffer must be exact size.