Package tp :: Package netlib :: Module xstruct
[show private | hide private]
[frames | no frames]

Module tp.netlib.xstruct

An advanced version of pack/unpack which works with extra TP strutures.

Everything is assumed to be network order, ie you don't need to
prepend every struct with !

Normal stuff from the struct module:

 c      Char
 b      Int8            (8 bit integer)
 B      UInt8           (8 bit unsigned integer)
 h      Int16           (16 bit integer)
 H      UInt16          (16 bit unsigned integer)
 i      Int32           (32 bit integer)
 I      UInt32          (32 bit unsigned integer)
 q      Int64           (64 bit integer)
 Q      UInt64          (64 bit unsigned integer)
 f      float           (32 bit floating point number)
 d      double          (64 bit floating point number)

Extra stuff defined by this module:

 S      String
 Y      Padded String   
 [      List Start              (unsigned int32 length)
 ]      List End        
 {      List Start              (unsigned int64 length)
 }      List End
 n      SInt16                  (16 bit semi-signed integer)
 j      SInt32                  (32 bit semi-signed integer)
 p      SInt64                  (64 bit semi-signed integer)
 t      timestamp               (32 bit unsigned integer)
 T      timestamp               (64 bit unsigned integer)
 
The structure of the data in the list is described by the data inside the
brackets.

Example:
        [L] would be a list of unsigned longs
        It is actually transmitted as <length><data><data><data>
        
Obviously you can't calculate size of an xstruct string. The unpack
function will return the unused data.

Function Summary
  hexbyte(string)
Takes a string and prints out the bytes in hex.
  pack(sstruct, *aargs)
Takes a structure string and the arguments to pack in the format specified by string.
  pack_list(length_struct, struct, args)
*Internal* Packs the id list so it can be send.
  pack_string(s)
*Internal* Prepares a string to be send out on a wire.
  pack_time(t, type)
*Internal* Returns the datetime object and any remaining data.
  smartsplit(struct, openbrace, closebrace)
  unpack(struct, s)
Takes a structure string and a data string.
  unpack_list(length_struct, struct, s)
*Internal* Returns the first string from the input data and any remaining data.
  unpack_string(s)
*Internal* Returns the first string from the input data and any remaining data.
  unpack_time(s, type)
*Internal* Returns the datetime object and any remaining data.

Variable Summary
str noarg = '0123456789 !x'
dict semi = {'p': (64, 'Q'), 'j': (32, 'I'), 'n': (16, 'H')}
str smallints = 'njbBhHiI'
dict times = {'T': 'Q', 't': 'I'}

Function Details

hexbyte(string)

Takes a string and prints out the bytes in hex.

pack(sstruct, *aargs)

Takes a structure string and the arguments to pack in the format
specified by string.

pack_list(length_struct, struct, args)

*Internal*

Packs the id list so it can be send.

pack_string(s)

*Internal*

Prepares a string to be send out on a wire.

It appends the string length to the beginning and adds a 
null terminator.

pack_time(t, type='I')

*Internal*

Returns the datetime object and any remaining data.

unpack(struct, s)

Takes a structure string and a data string.

((values1,value2), remaining_data)

unpack_list(length_struct, struct, s)

*Internal*

Returns the first string from the input data and any remaining data.

unpack_string(s)

*Internal*

Returns the first string from the input data and any remaining data.

unpack_time(s, type='I')

*Internal*

Returns the datetime object and any remaining data.

Variable Details

noarg

Type:
str
Value:
'0123456789 !x'                                                        

semi

Type:
dict
Value:
{'p': (64, 'Q'), 'j': (32, 'I'), 'n': (16, 'H')}                       

smallints

Type:
str
Value:
'njbBhHiI'                                                             

times

Type:
dict
Value:
{'T': 'Q', 't': 'I'}                                                   

Generated by Epydoc 2.1 on Fri Jan 1 08:00:27 2010 http://epydoc.sf.net