Commit 249dbdf6 authored by yann300's avatar yann300

always use bytes offset as param

parent f06cc737
...@@ -57,33 +57,25 @@ class ArrayType extends RefType { ...@@ -57,33 +57,25 @@ class ArrayType extends RefType {
} }
decodeFromMemory (offset, memory) { decodeFromMemory (offset, memory) {
offset = 2 * offset
var ret = [] var ret = []
var length = extractLength(this, offset, memory) var length = this.arraySize
if (this.arraySize === 'dynamic') { if (this.arraySize === 'dynamic') {
offset = offset + 64 length = memory.substr(2 * offset, 64)
length = parseInt(length, 16)
offset = offset + 32
} }
this.underlyingType.location = this.location this.underlyingType.location = this.location
for (var k = 0; k < length; k++) { for (var k = 0; k < length; k++) {
var contentOffset = offset var contentOffset = offset
if (this.underlyingType.basicType === 'RefType') { if (this.underlyingType.basicType === 'RefType') {
contentOffset = memory.substr(offset, 64) contentOffset = memory.substr(2 * contentOffset, 64)
contentOffset = parseInt(contentOffset, 16) contentOffset = parseInt(contentOffset, 16)
} }
ret.push(this.underlyingType.decode(contentOffset, memory)) ret.push(this.underlyingType.decode(contentOffset, memory))
offset += 64 offset += 32
} }
return ret return ret
} }
} }
function extractLength (type, offset, memory) {
var length = type.arraySize
if (length === 'dynamic') {
length = memory.substr(offset, 64)
length = parseInt(length, 16)
}
return length
}
module.exports = ArrayType module.exports = ArrayType
...@@ -21,18 +21,17 @@ class Struct extends RefType { ...@@ -21,18 +21,17 @@ class Struct extends RefType {
} }
decodeFromMemory (offset, memory) { decodeFromMemory (offset, memory) {
offset = 2 * offset
var ret = {} var ret = {}
this.members.map((item, i) => { this.members.map((item, i) => {
var contentOffset = offset var contentOffset = offset
if (item.type.basicType === 'RefType') { if (item.type.basicType === 'RefType') {
contentOffset = memory.substr(contentOffset, 64) contentOffset = memory.substr(2 * contentOffset, 64)
contentOffset = parseInt(contentOffset, 16) contentOffset = parseInt(contentOffset, 16)
} }
item.type.location = this.location item.type.location = this.location
var member = item.type.decode(contentOffset, memory) var member = item.type.decode(contentOffset, memory)
ret[item.name] = member ret[item.name] = member
offset += 64 offset += 32
}) })
return ret return ret
} }
......
...@@ -28,7 +28,6 @@ class ValueType { ...@@ -28,7 +28,6 @@ class ValueType {
} }
decode (offset, memory) { decode (offset, memory) {
offset = offset / 2
return this.decodeFromMemory(offset, memory) return this.decodeFromMemory(offset, memory)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment