Package vstruct :: Class VStruct
[hide private]
[frames] | no frames]

Class VStruct

source code



The VStruct class is the bases for all groups of primitive fields which define a "structure".
Fields may be added with vsAddField() or simply added as attributes (provided you use a VStruct
or one of the vstruct.primitives in the initial assignment.)

Example:
    import vstruct
    from vstruct.primitives import *

    vs = vstruct.VStruct()
    vs.fieldone = v_uint32()
    vs.fieldtwo = v_str(size=30)

    bytes = vs.vsEmit()

Instance Methods [hide private]
 
__init__(self)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
vsAddParseCallback(self, fieldname, callback)
Register a callback which will be triggered when the field with the given name is set by the parser.
source code
 
vsGetClassPath(self)
Return the entire class name (including module path).
source code
 
vsParseFd(self, fd)
Parse from the given file like object as input.
source code
 
vsParse(self, sbytes, offset=0, fast=False)
For all the primitives contained within, allow them an opportunity to parse the given data and return the total offset...
source code
 
vsGetFastParseFields(self) source code
 
vsEmit(self)
Get back the byte sequence associated with this structure.
source code
 
vsCalculate(self)
Calculate fields which need correction before emitting bytes etc...
source code
 
vsIsPrim(self) source code
 
vsGetFields(self)
Get a list of (fieldname, fieldobj) tuples for all the kids in this VStruct (non-recursive)
source code
 
vsGetField(self, name) source code
 
vsHasField(self, name)
Test weather this structure contains a field with the given name....
source code
 
vsSetField(self, name, value)
Mostly for internal use...
source code
 
__ixor__(self, other) source code
 
vsClearFields(self)
Clear all fields from the current vstruct object.
source code
 
vsGetFirstPrim(self) source code
 
vsAddField(self, name, value) source code
 
vsInsertField(self, name, value, befname)
WARNING: vsInsertField does NOT honor field alignment! # FIXME (AND CAN MESS UP OTHER FIELDS ALIGNMENT!)
source code
 
vsGetPrims(self)
return an order'd list of the primitive fields in this structure definition.
source code
 
vsGetTypeName(self) source code
 
vsGetOffset(self, name)
Return the offset of a member (by name):
source code
 
vsGetPrintInfo(self, offset=0, indent=0, top=True) source code
 
__len__(self) source code
 
__getattr__(self, name) source code
 
__setattr__(self, name, value)
x.__setattr__('name', value) <==> x.name = value
source code
 
__iter__(self) source code
 
__repr__(self)
repr(x)
source code
 
tree(self, va=0, reprmax=None) source code

Inherited from primitives.v_base: vsGetMeta, vsSetMeta

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

vsAddParseCallback(self, fieldname, callback)

source code 

Register a callback which will be triggered when the field with the given name
is set by the parser.  This can be used to simplify auto-parsing to change fields
sizes or whatnot during parsing.

(You may also name a method pcb_<FieldName> to get a callback for your struct.)

Example:

    def updateLengthTarget(vs):
        dostuff()

    v.vsAddParseCallback('lenfield', updateLengthTarget)

vsParse(self, sbytes, offset=0, fast=False)

source code 

For all the primitives contained within, allow them an opportunity to parse the given data and return the total offset...

Any method named pcb_<FieldName> will be called back when the specified field is set by the parser.

the "fast" option enables fastparse which will *not* call any callbacks can may not be compatible with some structure defs. ( eg mixed endian )

Overrides: primitives.v_base.vsParse

vsCalculate(self)

source code 

Calculate fields which need correction before emitting bytes etc...

(VStruct extenders may call this, then modify fields internally)

Overrides: primitives.v_base.vsCalculate

vsIsPrim(self)

source code 
Overrides: primitives.v_base.vsIsPrim

vsGetFields(self)

source code 

Get a list of (fieldname, fieldobj) tuples for all the kids
in this VStruct (non-recursive)

Example:
        for kidname, kidobj in x.vsGetFields():
            print kidname

vsHasField(self, name)

source code 

Test weather this structure contains a field with the
given name....

Example:
    if x.vsHasField('woot'):
        print 'STRUCT HAS WOOT FIELD!'

vsClearFields(self)

source code 

Clear all fields from the current vstruct object. This may be useful in specialized parsers which populate their structure on vsParse()

vsGetPrims(self)

source code 

return an order'd list of the primitive fields in this structure definition. This is recursive and will return the sub fields of all nested structures.

vsGetTypeName(self)

source code 
Overrides: primitives.v_base.vsGetTypeName

__setattr__(self, name, value)

source code 

x.__setattr__('name', value) <==> x.name = value

Overrides: object.__setattr__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)