how to convert this container back to format build result?

Ho Yeung Lee jobmattcon at gmail.com
Mon Apr 10 16:01:08 EDT 2017


http://construct.readthedocs.io/en/latest/basics.html

format.build can build the hex string, 
but after edit attribute of the format parse result
it is a container, how to convert this container back to format build result?

#format.parse(format.build(dict(width=3,height=2,pixels=[7,8,9,11,12,13]))).signature
format = Struct(
"signature" / Const(b"a2MP"),
"width" / Int8ub,
"height" / Int8ub,
"pixels" / Array(3 * 2, Byte),
)

#protocolA = {"a1" : "a2"}
#protocolA["a2"] = "a3"
#protocolA["a3"] = "a1"
protocolA = {"a1MP" : format.build(dict(width=3,height=2,pixels=[7,8,9,11,12,13]))}

a2MP = format.parse(format.build(dict(width=3,height=2,pixels=[7,8,9,11,12,13])))
a2MP.signature = "a3MP"
protocolA["a2MP"] = a2MP.build({})
a1MP = format.parse(format.build(dict(width=3,height=2,pixels=[7,8,9,11,12,13])))
a1MP.signature = "a1MP"
protocolA["a3MP"] = format.build(a1MP)


More information about the Python-list mailing list