Thnx for your answer!
I have solved this problem by patching StructType class in struct.js file.
I have added field
isPacked (with defaul value '
false'), and two methods '
pack()' and '
unpack()' to
StructType class in struct.js.
These methods simply switch isPacked field and run recalc() method from initial StructType definition. Then I have made some changes to recalc() and addType() methods.
In recalc() method I have replaced
struct.alignment = Math.max(struct.alignment, alignment)
with
if (struct.isPacked){
if (struct.alignment === 0){
struct.alignment = alignment;
}else{
struct.alignment = Math.min(struct.alignment, alignment)
}
}else{
struct.alignment = Math.max(struct.alignment, alignment)
}
And in addType() method I have replaced
var padding = (align - (offset % align)) % align
with
var padding = struct.pack ? 0 : (align - (offset % align)) % align
And
assert.equal(offset % align, 0, "offset should align")
with
if (!struct.isPacked){
assert.equal(offset % align, 0, "offset should align")
}
среда, 30 января 2013 г., 12:05:10 UTC+4 пользователь Nathan Rajlich написал: