How to use the binary.unpackInt function in binary

To help you get started, we’ve selected a few binary examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hellomatty / daap.js / test / binary.js View on Github external
assert.equal(255, binary.unpackByte([255]), 'unpack_byte: 255');

assert.deepEqual([0, 0], binary.packShort(0), 'pack_short: 0');
assert.deepEqual([0, 255], binary.packShort(255), 'pack_short: 255');
assert.deepEqual([1, 1], binary.packShort(257), 'pack_short: 256');

assert.equal(0, binary.unpackShort([0,0]), 'unpack_short: 0');
assert.equal(255, binary.unpackShort([0,255]), 'unpack_short: 255');
assert.equal(257, binary.unpackShort([1,1]), 'unpack_short: 257');

assert.deepEqual([0, 0, 0, 0], binary.packInt(0), 'pack_int: 0');
assert.deepEqual([0, 0, 0, 255], binary.packInt(255), 'pack_int: 255');
assert.deepEqual([109,115,112,105], binary.packInt('mspi'), 'pack_int: mspi');
assert.deepEqual([0, 0, 1, 1], binary.packInt(257), 'pack_int: 256');

assert.equal(0, binary.unpackInt([0,0,0,0]), 'unpack_int: 0');
assert.equal(1, binary.unpackInt([0,0,0,1]), 'unpack_int: 1');
assert.equal(257, binary.unpackInt([0,0,1,1]), 'unpack_int: 257');

assert.deepEqual([ 0, 0, 0, 0, 0, 0, 0, 1 ], binary.packLong(1), 'pack_long: 1');

assert.equal(1, binary.unpackLong([0,0,0,0,0,0,0,1]), 'unpack_long: 1');

assert.deepEqual([65, 66, 67], binary.packString('ABC'), 'pack_string: abc');;
assert.deepEqual([0xC2, 0xA2], binary.packString('\u00A2'), 'pack_string: U+00A2');;
assert.deepEqual([0xE2, 0x82, 0xAC], binary.packString('\u20AC'), 'pack_string: U+20AC');;

assert.deepEqual('ABC', binary.unpackString([65, 66, 67], 0, 3), 'unpack_string: abc');
assert.deepEqual('\u00a2', binary.unpackString([0xC2, 0xA2], 0, 2), 'unpack_string: \U+00A2');
assert.deepEqual('\u20AC', binary.unpackString([0xE2,0x82,0xAC], 0, 3), 'unpack_string: \U+20AC');
assert.deepEqual('\uFEFFCamino Del Sol', binary.unpackString([0xff, 0xfe, 0x43, 00, 0x61, 00, 0x6d, 00, 0x69, 00, 0x6e, 00, 0x6f, 00, 0x20, 00, 0x44, 00, 0x65, 00, 0x6c, 00, 0x20, 00, 0x53, 00, 0x6f, 00, 0x6c, 00], 0, 30, binary.characterEncoding.utf16));
github hellomatty / daap.js / lib / dmap.js View on Github external
var decode = exports.decode = function (buffer, index) {
  index = index || 0;

  var decodedTag = binary.unpackString(buffer, index, 4);
  
  return [
    decodedTag,
    unpacker(decodedTag)(buffer, index + 8, binary.unpackInt(buffer, index+4))
  ];
};
github hellomatty / daap.js / lib / song.js View on Github external
BinaryFile.prototype.getLongAt = function(offset) {
  return binary.unpackInt(this.getBytesAt(offset, 4));
}
github hellomatty / daap.js / lib / dmap.js View on Github external
return function (buffer, index, length) {
        var children = new Array();

        var ptr = 0;
        while (ptr < length) {
          var childLength = binary.unpackInt(buffer, index + ptr + 4);  

          children.push(decode(buffer, index + ptr));
  
          ptr += 8 + childLength;
        }

        return children;
      };
  }