fix(ConstTypes): size should be same as in type
This commit is contained in:
@ -13,6 +13,9 @@ ConstArray.prototype.serialize = function(dv, src, ...inner_types) {
|
||||
if (dv.byteLength < size * item_size) {
|
||||
throw new Error('too small buffer')
|
||||
}
|
||||
if (src.length != size) {
|
||||
throw new Error('array should be ' + size + ' elements length')
|
||||
}
|
||||
|
||||
for (let i = 0; i < size; i++) {
|
||||
const item_frame = new DataView(dv.buffer, dv.byteOffset + item_size * i)
|
||||
|
||||
@ -10,6 +10,9 @@ ConstDataView.prototype.serialize = function(dv, src) {
|
||||
if (dv.byteLength < this._size) {
|
||||
throw new Error('too small buffer')
|
||||
}
|
||||
if (src.byteLength != this._size) {
|
||||
throw new Error('buffer should be ' + this._size + ' bytes length')
|
||||
}
|
||||
memcpy(dv, src)
|
||||
return
|
||||
}
|
||||
|
||||
@ -14,6 +14,9 @@ ConstString.prototype.serialize = function(dv, src) {
|
||||
if (dv.byteLength < encoded.byteLength) {
|
||||
throw new Error('too small buffer')
|
||||
}
|
||||
if (src.length != this._size) {
|
||||
throw new Error('string should be ' + this._size + ' symbols length')
|
||||
}
|
||||
|
||||
memcpy(dv, encoded)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user