Table Of Contents

Array

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.

append(field)

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.

Data

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.

set_value(value)

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.

value()

Returns the value of the Data field as a string.