Table Of Contents


class Array(name, lengthfield, fieldtype)

Bases: BitPacket.Structure.Structure

An Array is an structure for fields of the same type. It contains a length field to count the number of elements that the array holds. After the length field, all the rest of fields (of the same type) are stored.

Initialize the array with the given name, a lengthfield for the counter field and fieldtype for a single argument function that will return a new array member. The single argument is a reference to the top-level root Container field where the array belongs to.


Appends a new field to the array. The given field must be of the same type specified when creating the array, otherwise a TypeError exception is raised.

It is important to note that the given field name will be changed by its index in the array.


class Data(name, lengthfield, wordsize=1)

Bases: BitPacket.Structure.Structure

This class lets you store strings of characters (divided by words) and also provides a field to hold its length. It is a Structure with two fields: length and data (internally created with name Data). The length is a numeric field and specifies how many words the Data field contains. The Data field is internally a String.

Initialize the field with the given name and a lengthfield. The lengthfield must be a numeric field instance. wordsize specifies how many bytes a word contains and it can be a numeric value or a unary function that knows where to get the word size, it has a default value of 1. So, the total length in bytes of a Data field is the length field multiplied by the word size. If wordsize is a function, it takes the top-level root Container field as a single argument. This way, it is possible to provide a word size that depends on the value of another field.


Sets a new string to the Data field. The given string length must be a mutliple of the word size and must fit in the length field (i.e. 300 characters are too long if the length field is UInt8, as only 255 characters fit), otherwise a ValueError exception will be raised.


Returns the value of the Data field as a string.