Copyright (C) 2000-2012 |
GNU Info (python2.1-lib.info)Unpacker ObjectsUnpacker Objects ---------------- The `Unpacker' class offers the following methods: `reset(data)' Resets the string buffer with the given DATA. `get_position()' Returns the current unpack position in the data buffer. `set_position(position)' Sets the data buffer unpack position to POSITION. You should be careful about using `get_position()' and `set_position()'. `get_buffer()' Returns the current unpack data buffer as a string. `done()' Indicates unpack completion. Raises an `Error' exception if all of the data has not been unpacked. In addition, every data type that can be packed with a `Packer', can be unpacked with an `Unpacker'. Unpacking methods are of the form `unpack_TYPE()', and take no arguments. They return the unpacked object. `unpack_float()' Unpacks a single-precision floating point number. `unpack_double()' Unpacks a double-precision floating point number, similarly to `unpack_float()'. In addition, the following methods unpack strings, bytes, and opaque data: `unpack_fstring(n)' Unpacks and returns a fixed length string. N is the number of characters expected. Padding with null bytes to guaranteed 4 byte alignment is assumed. `unpack_fopaque(n)' Unpacks and returns a fixed length opaque data stream, similarly to `unpack_fstring()'. `unpack_string()' Unpacks and returns a variable length string. The length of the string is first unpacked as an unsigned integer, then the string data is unpacked with `unpack_fstring()'. `unpack_opaque()' Unpacks and returns a variable length opaque data string, similarly to `unpack_string()'. `unpack_bytes()' Unpacks and returns a variable length byte stream, similarly to `unpack_string()'. The following methods support unpacking arrays and lists: `unpack_list(unpack_item)' Unpacks and returns a list of homogeneous items. The list is unpacked one element at a time by first unpacking an unsigned integer flag. If the flag is `1', then the item is unpacked and appended to the list. A flag of `0' indicates the end of the list. UNPACK_ITEM is the function that is called to unpack the items. `unpack_farray(n, unpack_item)' Unpacks and returns (as a list) a fixed length array of homogeneous items. N is number of list elements to expect in the buffer. As above, UNPACK_ITEM is the function used to unpack each element. `unpack_array(unpack_item)' Unpacks and returns a variable length LIST of homogeneous items. First, the length of the list is unpacked as an unsigned integer, then each element is unpacked as in `unpack_farray()' above. automatically generated by info2www version 1.2.2.9 |