drop utils.read/write.

This commit is contained in:
Christopher Jeffrey 2016-05-18 07:09:16 -07:00
parent b9c7afa0ea
commit ee3d3eaea1
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
13 changed files with 78 additions and 437 deletions

View File

@ -78,7 +78,10 @@ Bloom.prototype.add = function add(val, enc) {
shift = bit >>> 5;
shift *= 4;
utils.writeU32(this.filter, utils.readU32(this.filter, shift) | pos, shift);
this.filter.writeUInt32LE(
this.filter.readUInt32LE(shift, true) | pos,
shift,
true);
}
};
@ -101,7 +104,7 @@ Bloom.prototype.test = function test(val, enc) {
shift = bit >>> 5;
shift *= 4;
if ((utils.readU32(this.filter, shift) & pos) === 0)
if ((this.filter.readUInt32LE(shift, true) & pos) === 0)
return false;
}

View File

@ -457,7 +457,7 @@ ChainDB.prototype.save = function save(entry, block, connect, callback) {
hash = new Buffer(entry.hash, 'hex');
height = new Buffer(4);
utils.writeU32(height, entry.height, 0);
height.writeUInt32LE(height, 0, true);
batch.put('h/' + entry.hash, height);
batch.put('e/' + entry.hash, entry.toRaw());

View File

@ -609,7 +609,7 @@ HDPrivateKey.prototype.derivePurpose45 = function derivePurpose45() {
HDPrivateKey.prototype.isMaster = function isMaster() {
return this.depth === 0
&& this.childIndex === 0
&& utils.readU32(this.parentFingerPrint, 0) === 0;
&& this.parentFingerPrint.readUInt32LE(0, true) === 0;
};
/**

View File

@ -528,7 +528,7 @@ MinerBlock.prototype.findNonce = function findNonce() {
// Update the raw buffer (faster than
// constantly serializing the block)
utils.writeU32(data, block.nonce, 76);
data.writeUInt32LE(block.nonce, 76, true);
// Send progress report every so often
if (block.nonce % 100000 === 0)

View File

@ -51,7 +51,7 @@ Framer.prototype.header = function header(cmd, payload) {
assert(payload.length <= 0xffffffff);
// Magic value
utils.writeU32(h, this.network.magic, 0);
h.writeUInt32LE(this.network.magic, 0, true);
// Command
len = cmd.copy(h, 4);
@ -59,7 +59,7 @@ Framer.prototype.header = function header(cmd, payload) {
h[i] = 0;
// Payload length
utils.writeU32(h, payload.length, 16);
h.writeUInt32LE(payload.length, 16, true);
// Checksum
utils.checksum(payload).copy(h, 20);

View File

@ -90,6 +90,8 @@ Parser.prototype.feed = function feed(data) {
*/
Parser.prototype.parse = function parse(chunk) {
var checksum;
if (chunk.length > constants.MAX_MESSAGE)
return this._error('Packet too large: %dmb.', utils.mb(chunk.length));
@ -100,7 +102,9 @@ Parser.prototype.parse = function parse(chunk) {
this.packet.payload = chunk;
if (utils.readU32(utils.checksum(this.packet.payload)) !== this.packet.checksum)
checksum = utils.checksum(this.packet.payload).readUInt32LE(0, true);
if (checksum !== this.packet.checksum)
return this._error('Invalid checksum');
try {
@ -126,7 +130,7 @@ Parser.prototype.parse = function parse(chunk) {
Parser.prototype.parseHeader = function parseHeader(h) {
var i, magic, cmd;
magic = utils.readU32(h, 0);
magic = h.readUInt32LE(0, true);
if (magic !== this.network.magic)
return this._error('Invalid magic value: ' + magic.toString(16));
@ -138,7 +142,7 @@ Parser.prototype.parseHeader = function parseHeader(h) {
return this._error('Not NULL-terminated cmd');
cmd = h.toString('ascii', 4, 4 + i);
this.waiting = utils.readU32(h, 16);
this.waiting = h.readUInt32LE(16, true);
if (this.waiting > constants.MAX_MESSAGE)
return this._error('Packet length too large: %dmb', utils.mb(this.waiting));
@ -146,7 +150,7 @@ Parser.prototype.parseHeader = function parseHeader(h) {
return {
cmd: cmd,
length: this.waiting,
checksum: utils.readU32(h, 20)
checksum: h.readUInt32LE(20, true)
};
};

View File

@ -145,7 +145,7 @@ BufferReader.prototype.destroy = function destroy() {
BufferReader.prototype.readU8 = function readU8() {
var ret;
assert(this.offset + 1 <= this.data.length);
ret = utils.readU8(this.data, this.offset);
ret = this.data.readUInt8(this.offset, true);
this.offset += 1;
return ret;
};
@ -158,7 +158,7 @@ BufferReader.prototype.readU8 = function readU8() {
BufferReader.prototype.readU16 = function readU16() {
var ret;
assert(this.offset + 2 <= this.data.length);
ret = utils.readU16(this.data, this.offset);
ret = this.data.readUInt16LE(this.offset, true);
this.offset += 2;
return ret;
};
@ -171,7 +171,7 @@ BufferReader.prototype.readU16 = function readU16() {
BufferReader.prototype.readU16BE = function readU16BE() {
var ret;
assert(this.offset + 2 <= this.data.length);
ret = utils.readU16BE(this.data, this.offset);
ret = this.data.readUInt16BE(this.offset, true);
this.offset += 2;
return ret;
};
@ -184,7 +184,7 @@ BufferReader.prototype.readU16BE = function readU16BE() {
BufferReader.prototype.readU32 = function readU32() {
var ret;
assert(this.offset + 4 <= this.data.length);
ret = utils.readU32(this.data, this.offset);
ret = this.data.readUInt32LE(this.offset, true);
this.offset += 4;
return ret;
};
@ -197,7 +197,7 @@ BufferReader.prototype.readU32 = function readU32() {
BufferReader.prototype.readU32BE = function readU32BE() {
var ret;
assert(this.offset + 4 <= this.data.length);
ret = utils.readU32BE(this.data, this.offset);
ret = this.data.readUInt32BE(this.offset, true);
this.offset += 4;
return ret;
};
@ -284,7 +284,7 @@ BufferReader.prototype.readU53BE = function readU53BE() {
BufferReader.prototype.read8 = function read8() {
var ret;
assert(this.offset + 1 <= this.data.length);
ret = utils.read8(this.data, this.offset);
ret = this.data.readInt8(this.offset, true);
this.offset += 1;
return ret;
};
@ -297,7 +297,7 @@ BufferReader.prototype.read8 = function read8() {
BufferReader.prototype.read16 = function read16() {
var ret;
assert(this.offset + 2 <= this.data.length);
ret = utils.read16(this.data, this.offset);
ret = this.data.readInt16LE(this.offset, true);
this.offset += 2;
return ret;
};
@ -310,7 +310,7 @@ BufferReader.prototype.read16 = function read16() {
BufferReader.prototype.read16BE = function read16BE() {
var ret;
assert(this.offset + 2 <= this.data.length);
ret = utils.read16BE(this.data, this.offset);
ret = this.data.readInt16BE(this.offset, true);
this.offset += 2;
return ret;
};
@ -323,7 +323,7 @@ BufferReader.prototype.read16BE = function read16BE() {
BufferReader.prototype.read32 = function read32() {
var ret;
assert(this.offset + 4 <= this.data.length);
ret = utils.read32(this.data, this.offset);
ret = this.data.readInt32LE(this.offset, true);
this.offset += 4;
return ret;
};
@ -336,7 +336,7 @@ BufferReader.prototype.read32 = function read32() {
BufferReader.prototype.read32BE = function read32BE() {
var ret;
assert(this.offset + 4 <= this.data.length);
ret = utils.read32BE(this.data, this.offset);
ret = this.data.readInt32BE(this.offset, true);
this.offset += 4;
return ret;
};
@ -577,7 +577,7 @@ BufferReader.prototype.readNullString = function readNullString(enc) {
BufferReader.prototype.createChecksum = function createChecksum() {
var start = this.stack[this.stack.length - 1] || 0;
var data = this.data.slice(start, this.offset);
return utils.readU32(utils.checksum(data), 0);
return utils.checksum(data).readUInt32LE(0, true);
};
/**

View File

@ -2554,7 +2554,7 @@ Script.prototype.isCommitment = function isCommitment() {
return false;
if (this.raw[1] !== 0x24)
return false;
if (utils.readU32BE(this.raw, 2) !== 0xaa21a9ed)
if (this.raw.readUInt32BE(2, true) !== 0xaa21a9ed)
return false;
return true;
}
@ -2562,7 +2562,7 @@ Script.prototype.isCommitment = function isCommitment() {
&& this.code[0] === opcodes.OP_RETURN
&& Buffer.isBuffer(this.code[1])
&& this.code[1].length === 36
&& utils.readU32BE(this.code[1], 0) === 0xaa21a9ed;
&& this.code[1].readUInt32BE(0, true) === 0xaa21a9ed;
};
/**

View File

@ -75,7 +75,7 @@ function salsa20_8(B) {
var i;
for (i = 0; i < 16; i++)
B32[i] = utils.readU32(B, i * 4);
B32[i] = B.readUInt32LE(i * 4, true);
for (i = 0; i < 16; i++)
x[i] = B32[i];
@ -126,7 +126,7 @@ function salsa20_8(B) {
B32[i] += x[i];
for (i = 0; i < 16; i++)
utils.writeU32(B, B32[i], 4 * i);
B.writeUInt32LE(B32[i], 4 * i, true);
}
function R(a, b) {
@ -153,7 +153,7 @@ function blockmix_salsa8(B, Y, r) {
}
function integerify(B, r) {
return utils.readU32(B, (2 * r - 1) * 64);
return B.readUInt32LE((2 * r - 1) * 64, true);
}
function smix(B, r, N, V, XY) {

View File

@ -1643,7 +1643,7 @@ TXDB.prototype.getBalance = function getBalance(address, callback) {
utils.forEachSerial(hashes, function(hash, next) {
self.db.fetch('c/' + hash[0] + '/' + hash[1], function(data, key) {
var height = utils.readU32(data, 4);
var height = data.readUInt32LE(4, true);
var value = utils.read64N(data, 8);
assert(data.length >= 16);

View File

@ -1294,104 +1294,11 @@ utils.U64 = new bn('ffffffffffffffff', 'hex');
utils.nonce = function _nonce() {
var nonce = new Buffer(8);
utils.writeU32(nonce, Math.random() * 0x100000000 | 0, 0);
utils.writeU32(nonce, Math.random() * 0x100000000 | 0, 4);
nonce.writeUInt32LE(Math.random() * 0x100000000 | 0, 0, true);
nonce.writeUInt32LE(Math.random() * 0x100000000 | 0, 4, true);
return new bn(nonce);
};
//
// Integer Functions
//
// Non-64-bit functions originally taken from the node.js tree:
//
// Copyright Joyent, Inc. and other Node contributors. All rights reserved.
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
/**
* Read uint8.
* @param {Buffer} data
* @param {Number} off
* @returns {Number}
*/
utils.readU8 = function readU8(data, off) {
off = off >>> 0;
return data[off];
};
/**
* Read uint16le.
* @param {Buffer} data
* @param {Number} off
* @returns {Number}
*/
utils.readU16 = function readU16(data, off) {
off = off >>> 0;
return data[off] | (data[off + 1] << 8);
};
/**
* Read uint16be.
* @param {Buffer} data
* @param {Number} off
* @returns {Number}
*/
utils.readU16BE = function readU16BE(data, off) {
off = off >>> 0;
return (data[off] << 8) | data[off + 1];
};
/**
* Read uint32le.
* @param {Buffer} data
* @param {Number} off
* @returns {Number}
*/
utils.readU32 = function readU32(data, off) {
off = off >>> 0;
return ((data[off])
| (data[off + 1] << 8)
| (data[off + 2] << 16))
+ (data[off + 3] * 0x1000000);
};
/**
* Read uint32be.
* @param {Buffer} data
* @param {Number} off
* @returns {Number}
*/
utils.readU32BE = function readU32BE(data, off) {
off = off >>> 0;
return (data[off] * 0x1000000)
+ ((data[off + 1] << 16)
| (data[off + 2] << 8)
| data[off + 3]);
};
/**
* Read uint64le.
* @param {Buffer} data
@ -1420,80 +1327,6 @@ utils.readU64BE = function readU64BE(data, off) {
return new bn(num, 'be');
};
/**
* Read int8.
* @param {Buffer} data
* @param {Number} off
* @returns {Number}
*/
utils.read8 = function read8(data, off) {
var num;
off = off >>> 0;
num = data[off];
return !(num & 0x80) ? num : (0xff - num + 1) * -1;
};
/**
* Read int16le.
* @param {Buffer} data
* @param {Number} off
* @returns {Number}
*/
utils.read16 = function read16(data, off) {
var num;
off = off >>> 0;
num = data[off] | (data[off + 1] << 8);
return (num & 0x8000) ? num | 0xffff0000 : num;
};
/**
* Read int16be.
* @param {Buffer} data
* @param {Number} off
* @returns {Number}
*/
utils.read16BE = function read16BE(data, off) {
var num;
off = off >>> 0;
num = data[off + 1] | (data[off] << 8);
return (num & 0x8000) ? num | 0xffff0000 : num;
};
/**
* Read int32le.
* @param {Buffer} data
* @param {Number} off
* @returns {Number}
*/
utils.read32 = function read32(data, off) {
off = off >>> 0;
return (data[off])
| (data[off + 1] << 8)
| (data[off + 2] << 16)
| (data[off + 3] << 24);
};
/**
* Read int32be.
* @param {Buffer} data
* @param {Number} off
* @returns {Number}
*/
utils.read32BE = function read32BE(data, off) {
off = off >>> 0;
return (data[off] << 24)
| (data[off + 1] << 16)
| (data[off + 2] << 8)
| (data[off + 3]);
};
/**
* Read int64le.
* @param {Buffer} data
@ -1534,74 +1367,6 @@ utils.read64BE = function read64BE(data, off) {
return new bn(num, 'be');
};
/**
* Write uint8.
* @param {Number} value
*/
utils.writeU8 = function writeU8(dst, num, off) {
num = +num;
off = off >>> 0;
dst[off] = num & 0xff;
return 1;
};
/**
* Write uint16le.
* @param {Number} value
*/
utils.writeU16 = function writeU16(dst, num, off) {
num = +num;
off = off >>> 0;
dst[off] = num & 0xff;
dst[off + 1] = (num >>> 8) & 0xff;
return 2;
};
/**
* Write uint16be.
* @param {Number} value
*/
utils.writeU16BE = function write16BE(dst, num, off) {
num = +num;
off = off >>> 0;
dst[off] = (num >>> 8) & 0xff;
dst[off + 1] = num & 0xff;
return 2;
};
/**
* Write uint32le.
* @param {Number} value
*/
utils.writeU32 = function writeU32(dst, num, off) {
num = +num;
off = off >>> 0;
dst[off + 3] = (num >>> 24) & 0xff;
dst[off + 2] = (num >>> 16) & 0xff;
dst[off + 1] = (num >>> 8) & 0xff;
dst[off] = num & 0xff;
return 4;
};
/**
* Write uint32be.
* @param {Number} value
*/
utils.writeU32BE = function writeU32BE(dst, num, off) {
num = +num;
off = off >>> 0;
dst[off] = (num >>> 24) & 0xff;
dst[off + 1] = (num >>> 16) & 0xff;
dst[off + 2] = (num >>> 8) & 0xff;
dst[off + 3] = num & 0xff;
return 4;
};
/**
* Write uint64le.
* @param {BN|Number} value
@ -1707,7 +1472,7 @@ utils.write64N = function write64N(dst, num, off, be) {
dst[off + 7] = (hi >>> 24) & 0xff;
}
return 8;
return off + 8;
};
/**
@ -1735,11 +1500,11 @@ utils.readU64N = function readU64N(data, off, force53, be) {
off = off >>> 0;
if (be) {
hi = utils.readU32(data, off);
lo = utils.readU32(data, off + 4);
hi = data.readUInt32LE(off, true);
lo = data.readUInt32LE(off + 4, true);
} else {
hi = utils.readU32(data, off + 4);
lo = utils.readU32(data, off);
hi = data.readUInt32LE(off + 4, true);
lo = data.readUInt32LE(off, true);
}
if (force53)
@ -1778,11 +1543,11 @@ utils.read64N = function read64N(data, off, force53, be) {
off = off >>> 0;
if (be) {
hi = utils.readU32(data, off);
lo = utils.readU32(data, off + 4);
hi = data.readUInt32LE(off, true);
lo = data.readUInt32LE(off + 4, true);
} else {
hi = utils.readU32(data, off + 4);
lo = utils.readU32(data, off);
hi = data.readUInt32LE(off + 4, true);
lo = data.readUInt32LE(off, true);
}
if (hi & 0x80000000) {
@ -1818,137 +1583,6 @@ utils.read64NBE = function read64NBE(data, off, force53) {
return utils.read64N(data, off, force53, true);
};
/**
* Read first least significant 53 bits of
* a uint64le as a js number. Maintain the sign.
* @param {Buffer} data
* @param {Number} off
* @returns {Number}
*/
utils.readU53 = function readU53(data, off) {
return utils.readU64N(data, off, true);
};
/**
* Read first least significant 53 bits of
* a uint64be as a js number. Maintain the sign.
* @param {Buffer} data
* @param {Number} off
* @returns {Number}
*/
utils.readU53BE = function readU53BE(data, off) {
return utils.readU64NBE(data, off, true);
};
/**
* Read first least significant 53 bits of
* a uint64le as a js number. Maintain the sign.
* @param {Buffer} data
* @param {Number} off
* @returns {Number}
*/
utils.read53 = function read53(data, off) {
return utils.read64N(data, off, true);
};
/**
* Read first least significant 53 bits of
* a int64be as a js number. Maintain the sign.
* @param {Buffer} data
* @param {Number} off
* @returns {Number}
*/
utils.read53BE = function read53BE(data, off) {
return utils.read64NBE(data, off, true);
};
/**
* Write int8.
* @param {Buffer} dst
* @param {Number} num
* @param {Number} off
* @returns {Number} Number of bytes written.
*/
utils.write8 = function write8(dst, num, off) {
num = +num;
off = off >>> 0;
dst[off] = num & 0xff;
return 1;
};
/**
* Write int16le.
* @param {Buffer} dst
* @param {Number} num
* @param {Number} off
* @returns {Number} Number of bytes written.
*/
utils.write16 = function write16(dst, num, off) {
num = +num;
off = off >>> 0;
dst[off] = num & 0xff;
dst[off + 1] = (num >>> 8) & 0xff;
return 2;
};
/**
* Write int16be.
* @param {Buffer} dst
* @param {Number} num
* @param {Number} off
* @returns {Number} Number of bytes written.
*/
utils.write16BE = function write16BE(dst, num, off) {
num = +num;
off = off >>> 0;
dst[off] = (num >>> 8) & 0xff;
dst[off + 1] = num & 0xff;
return 2;
};
/**
* Write int32le.
* @param {Buffer} dst
* @param {Number} num
* @param {Number} off
* @returns {Number} Number of bytes written.
*/
utils.write32 = function write32(dst, num, off) {
num = +num;
off = off >>> 0;
dst[off] = num & 0xff;
dst[off + 1] = (num >>> 8) & 0xff;
dst[off + 2] = (num >>> 16) & 0xff;
dst[off + 3] = (num >>> 24) & 0xff;
return 4;
};
/**
* Write int32be.
* @param {Buffer} dst
* @param {Number} num
* @param {Number} off
* @returns {Number} Number of bytes written.
*/
utils.write32BE = function write32BE(dst, num, off) {
num = +num;
off = off >>> 0;
dst[off] = (num >>> 24) & 0xff;
dst[off + 1] = (num >>> 16) & 0xff;
dst[off + 2] = (num >>> 8) & 0xff;
dst[off + 3] = num & 0xff;
return 4;
};
/**
* Write int64le.
* @param {Buffer} dst
@ -1976,7 +1610,7 @@ utils.write64 = function write64(dst, num, off) {
for (i = 0; i < num.length; i++)
dst[off++] = num[i];
return 8;
return off;
};
/**
@ -2006,7 +1640,7 @@ utils.write64BE = function write64BE(dst, num, off) {
for (i = 0; i < num.length; i++)
dst[off++] = num[i];
return 8;
return off;
};
/**
@ -2038,7 +1672,7 @@ utils.readVarint = function readVarint(data, off, big) {
} else if (data[off] === 0xfe) {
size = 5;
assert(off + size <= data.length);
value = utils.readU32(data, off + 1);
value = data.readUInt32LE(off + 1, true);
if (big)
value = new bn(value);
} else if (data[off] === 0xff) {
@ -2070,7 +1704,7 @@ utils.writeVarint = function writeVarint(dst, num, off) {
if (num.bitLength() > 32) {
dst[off] = 0xff;
utils.writeU64(dst, num, off + 1);
return 9;
return off + 9;
}
num = num.toNumber();
}
@ -2079,14 +1713,14 @@ utils.writeVarint = function writeVarint(dst, num, off) {
if (num < 0xfd) {
dst[off] = num & 0xff;
return 1;
return off + 1;
}
if (num <= 0xffff) {
dst[off] = 0xfd;
dst[off + 1] = num & 0xff;
dst[off + 2] = (num >>> 8) & 0xff;
return 3;
return off + 3;
}
if (num <= 0xffffffff) {
@ -2095,13 +1729,13 @@ utils.writeVarint = function writeVarint(dst, num, off) {
dst[off + 2] = (num >>> 8) & 0xff;
dst[off + 3] = (num >>> 16) & 0xff;
dst[off + 4] = (num >>> 24) & 0xff;
return 5;
return off + 5;
}
dst[off] = 0xff;
utils.writeU64N(dst, num, off + 1);
return 9;
return off + 9;
};
/**
@ -2543,7 +2177,7 @@ utils.getMerkleBranch = function getMerkleBranch(index, leaves) {
for (; size > 1; size = (size + 1) / 2 | 0) {
i = Math.min(index ^ 1, size - 1);
branch.push(tree[j + i]);
index >>= 1;
index >>>= 1;
j += size;
}
@ -2575,7 +2209,7 @@ utils.checkMerkleBranch = function checkMerkleBranch(hash, branch, index) {
else
hash = utils.dsha256(Buffer.concat([hash, otherside]));
index >>= 1;
index >>>= 1;
}
return hash;

View File

@ -807,9 +807,9 @@ Parser.prototype.feed = function feed(data) {
Parser.prototype.parseHeader = function parseHeader(data) {
return {
magic: utils.readU32(data, 0),
job: utils.readU32(data, 4),
size: utils.readU32(data, 8)
magic: data.readUInt32LE(0, true),
job: data.readUInt32LE(4, true),
size: data.readUInt32LE(8, true)
};
};

View File

@ -78,25 +78,25 @@ BufferWriter.prototype.render = function render(keep) {
item = this.data[i];
switch (item[0]) {
case SEEK: off += item[1]; break;
case UI8: off += utils.writeU8(data, item[1], off); break;
case UI16: off += utils.writeU16(data, item[1], off); break;
case UI16BE: off += utils.writeU16BE(data, item[1], off); break;
case UI32: off += utils.writeU32(data, item[1], off); break;
case UI32BE: off += utils.writeU32BE(data, item[1], off); break;
case UI64: off += utils.writeU64(data, item[1], off); break;
case UI64BE: off += utils.writeU64BE(data, item[1], off); break;
case I8: off += utils.write8(data, item[1], off); break;
case I16: off += utils.write16(data, item[1], off); break;
case I16BE: off += utils.write16BE(data, item[1], off); break;
case I32: off += utils.write32(data, item[1], off); break;
case I32BE: off += utils.write32BE(data, item[1], off); break;
case I64: off += utils.write64(data, item[1], off); break;
case I64BE: off += utils.write64BE(data, item[1], off); break;
case FL: data.writeFloatLE(item[1], off, true); off += 4; break;
case FLBE: data.writeFloatBE(item[1], off, true); off += 4; break;
case DBL: data.writeDoubleLE(item[1], off, true); off += 8; break;
case DBLBE: data.writeDoubleBE(item[1], off, true); off += 8; break;
case VARINT: off += utils.writeVarint(data, item[1], off); break;
case UI8: off = data.writeUInt8(item[1], off, true); break;
case UI16: off = data.writeUInt16LE(item[1], off, true); break;
case UI16BE: off = data.writeUInt16BE(item[1], off, true); break;
case UI32: off = data.writeUInt32LE(item[1], off, true); break;
case UI32BE: off = data.writeUInt32BE(item[1], off, true); break;
case UI64: off = utils.writeU64(data, item[1], off); break;
case UI64BE: off = utils.writeU64BE(data, item[1], off); break;
case I8: off = data.writeInt8(item[1], off, true); break;
case I16: off = data.writeInt16LE(item[1], off, true); break;
case I16BE: off = data.writeInt16BE(item[1], off, true); break;
case I32: off = data.writeInt32LE(item[1], off, true); break;
case I32BE: off = data.writeInt32BE(item[1], off, true); break;
case I64: off = utils.write64(data, item[1], off); break;
case I64BE: off = utils.write64BE(data, item[1], off); break;
case FL: off = data.writeFloatLE(item[1], off, true); break;
case FLBE: off = data.writeFloatBE(item[1], off, true); break;
case DBL: off = data.writeDoubleLE(item[1], off, true); break;
case DBLBE: off = data.writeDoubleBE(item[1], off, true); break;
case VARINT: off = utils.writeVarint(data, item[1], off); break;
case BYTES: off += item[1].copy(data, off); break;
case STR: off += data.write(item[1], off, item[2]); break;
case CHECKSUM: