UNPACK(1)

NAME
packet.unpack - Unpack module

DESCRIPTION
Provides the object for managing and unpacking raw data from a working buffer.

CLASSES

  class Unpack(__builtin__.object)
Unpack object Usage:
    from packet.unpack import Unpack
    x = Unpack(buffer)
    # Get the 32 bytes from the working buffer
    data = x.rawdata(32)
    # Unpack an 'unsigned short' (2 bytes)
    short_int = x.unpack(2, 'H')[0]
    # Unpack different basic types
    char_int = x.unpack_char()
    short_int = x.unpack_short()
    uint = x.unpack_uint()
    uint64 = x.unpack_uint64()
    # Get string where length is given as an unsigned integer
    buffer = x.unpack_string()
    # Get string where length is given as a short integer
    buffer = x.unpack_string(x.unpack_short)
    buffer = x.unpack_string(ltype=x.unpack_short)
    # Get string padded to a 4 byte boundary, discard padding bytes
    buffer = x.unpack_string(pad=4)
    # Get an array of integers
    alist = x.unpack_array()
    # Get an array of short integers
    alist = x.unpack_array(x.unpack_short)
    # Get an array of strings, the length of the array is given
    # by a short integer
    alist = x.unpack_array(x.unpack_string, x.unpack_short)
    # Get an array of strings, the length of each string is given by
    # a short integer and each string is padded to a 4 byte boundary
    alist = x.unpack_array(x.unpack_string, args={'ltype':x.unpack_short, 'pad':4})
    # Get a list of integers
    alist = x.unpack_list()
    # Get a list of short integers
    alist = x.unpack_list(x.unpack_short)
    # Get a list of strings, the next item flag is given
    # by a short integer
    alist = x.unpack_list(x.unpack_string, x.unpack_short)
    # Get a list of strings, the length of each string is given by
    # a short integer and each string is padded to a 4 byte boundary
    alist = x.unpack_list(x.unpack_string, args={'ltype':x.unpack_short, 'pad':4})

Methods defined here:
---------------------

__init__(self, data)
    Constructor Initialize object's private data.

    data:
        Raw packet data

rawdata(self, size)
    Get the number of bytes given from the working buffer.

unpack(self, size, fmt)
    Get the number of bytes given from the working buffer and process it according to the given format. Return a tuple of unpack items, see struct.unpack.

unpack_array(self, *kwts, **kwds)
    Get a variable length array, the type of objects in the array is given by the unpacking function unpack_item and the type to decode the length of the array is given by ltype

    unpack_item:
        Unpack function for each item in the array [default: unpack_uint] Given as the first positional argument or as a named argument

    ltype:
        Function to decode length of array [default: unpack_uint] Given as the second positional argument or as a named argument

    args:
        Named arguments to pass to unpack_item function [default: {}]

unpack_char(self)
    Get an unsigned char

unpack_list(self, *kwts, **kwds)
    Get an indeterminate size list, the type of objects in the list is given by the unpacking function unpack_item and the type to decode the next item flag is given by ltype

    unpack_item:
        Unpack function for each item in the list [default: unpack_uint] Given as the first positional argument or as a named argument

    ltype:
        Function to decode the next item flag [default: unpack_uint] Given as the second positional argument or as a named argument

    args:
        Named arguments to pass to unpack_item function [default: {}]

unpack_short(self)
    Get an unsigned short integer

unpack_string(self, *kwts, **kwds)
    Get a variable length string

    ltype:
        Function to decode length of string [default: unpack_uint] Given as the first positional argument or as a named argument

    pad:
        Get and discard padding bytes [default: 0] If given, string is padded to this byte boundary

unpack_uint(self)
    Get an unsigned integer

unpack_uint64(self)
    Get an unsigned 64 bit integer

BUGS
No known bugs.

AUTHOR
Jorge Mora (mora@netapp.com)