what's Construct ---------------------------- a library for parsing and building of data structures, at the bit-level, in a declarative manner (no procedural code needed). site ---------------------------- get it at http://pyconstruct.sourceforge.net what' news ---------------------------- * two bug fixes: forgot to define two exception classes * new builtins: - Pass - a "do nothing" construct, useful for the default arguments to Switch, etc. - If - a conditional construct, that executes the sub-construct only if some meta-condition is satisfied - Embed - embeds a Struct into another Struct. see example below. - LazyBind - lazy-binds a construct, so you can be define recursive constructs. see example. - Float - IEEE754 floating point implementation. this release only supports parsing of floats, not building them, but i thought its useful enough by itself. a later release will address the building problem. * improved the LV construct * removed the TLV construct (it's pointless to have it as a builtin) * added get_size() which returns the size of a 'normal' (non-meta) construct, example ---------------------------- to_embed = Struct("blah", UInt8("a"), UInt8("b"), UInt8("c"), ) struct1 = Struct("struct1", to_embed, UInt8("x"), ) struct2 = Struct("struct2", Embed(to_embed), UInt8("x"), ) #>>> print struct1.parse("xabc") #Container: # blah = Container: # a = 120 # b = 97 # c = 98 # x = 99 #>>> print struct2.parse("xabc") #Container: # a = 120 # b = 97 # c = 98 # x = 99 #>>> print struct1.get_size() #32 #>>> print struct2.get_size() #32 my_linked_list = Struct("linked_list", UInt8("data"), UInt8("has_next"), If("_.has_next", LazyBind("next", "my_linked_list", globals()) ) ) #>>> print my_linked_list.parse("A\x01B\x01C\x01D\x00") #Container: # data = 65 # has_next = 1 # next = Container: # data = 66 # has_next = 1 # next = Container: # data = 67 # has_next = 1 # next = Container: # data = 68 # has_next = 0 # next = None -tomer
participants (1)
-
tomerfilibaï¼ gmail.com