22 Nov 2011 19:08
Modification of fields
Dear all, How far from working is the code below? The idea is to change the field "x" to give it a new value, and to reconstruct the stream with this new value. https://bitbucket.org/haypo/hachoir/wiki/Ideas apparently explains that it has been envisaged. I quote: "Event driven system: allow fields to signal modify events up to parent fields, all the way to root". Regards, Louis from hachoir_core.stream import StringInputStream, LITTLE_ENDIAN from hachoir_core.field import Parser, CString, UInt16 class Point(Parser): endian = LITTLE_ENDIAN def createFields(self): yield CString(self, "name", "Point name") yield UInt16(self, "x", "X coordinate") yield UInt16(self, "y", "Y coordinate") d0 = "point\0\3\0\2\0" p0 = Point(StringInputStream(d0)) d1 = "point\0\8\0\8\0" p1 = Point(StringInputStream(d1)) p0["x"].value p0.replaceField("x",p1["x"])
RSS Feed