How to use the bytebuffer.prototype function in bytebuffer

To help you get started, we’ve selected a few bytebuffer 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 RiseVision / rise-node / tests / unit / logic / transactions / createmultisig.spec.ts View on Github external
before(() => {
      toRestore.writeByte = ByteBuffer.prototype.writeByte;
      toRestore.writeInt  = ByteBuffer.prototype.writeInt;
      toRestore.writeLong = (ByteBuffer.prototype as any).writeLong;
      toRestore.toBuffer  = ByteBuffer.prototype.toBuffer;
      toRestore.flip      = ByteBuffer.prototype.flip;
    });
    beforeEach(() => {
github RiseVision / rise-node / tests / unit / logic / transaction.spec.ts View on Github external
before(() => {
      toRestore.writeByte = ByteBuffer.prototype.writeByte;
      toRestore.writeInt  = ByteBuffer.prototype.writeInt;
      toRestore.writeLong = (ByteBuffer.prototype as any).writeLong;
      toRestore.flip      = ByteBuffer.prototype.flip;
    });
    beforeEach(() => {
github RiseVision / rise-node / tests / unit / logic / transactions / createmultisig.spec.ts View on Github external
before(() => {
      toRestore.writeByte = ByteBuffer.prototype.writeByte;
      toRestore.writeInt  = ByteBuffer.prototype.writeInt;
      toRestore.writeLong = (ByteBuffer.prototype as any).writeLong;
      toRestore.toBuffer  = ByteBuffer.prototype.toBuffer;
      toRestore.flip      = ByteBuffer.prototype.flip;
    });
    beforeEach(() => {
github RiseVision / rise-node / tests / unit / logic / transaction.spec.ts View on Github external
before(() => {
      toRestore.writeByte = ByteBuffer.prototype.writeByte;
      toRestore.writeInt  = ByteBuffer.prototype.writeInt;
      toRestore.writeLong = (ByteBuffer.prototype as any).writeLong;
      toRestore.flip      = ByteBuffer.prototype.flip;
    });
    beforeEach(() => {
github saul / demofile / ext / bytebuffer.js View on Github external
}

  return this.readBytes(length, offset);
};

ByteBuffer.prototype.readIBytes = function (offset) {
  var length = this.readInt32(offset);

  if (typeof offset !== 'undefined') {
    offset += 4;
  }

  return this.readBytes(length, offset);
};

ByteBuffer.prototype.toSlicedBuffer = function () {
  return this.buffer.slice(this.offset, this.limit);
};

module.exports = ByteBuffer;
github saul / demofile / ext / bytebuffer.js View on Github external
var ByteBuffer = require('bytebuffer');

ByteBuffer.prototype.readVBytes = function (offset) {
  var length = this.readVarint32(offset);

  if (typeof offset !== 'undefined') {
    offset += length.length;
    length = length.value;
  }

  return this.readBytes(length, offset);
};

ByteBuffer.prototype.readIBytes = function (offset) {
  var length = this.readInt32(offset);

  if (typeof offset !== 'undefined') {
    offset += 4;
  }
github chainside / btcnodejs / tools / bytebuffer.js View on Github external
const ByteBuffer = require("bytebuffer");
const $ = require("./conversions");

ByteBuffer.prototype.writeVarint = function (int, offset = undefined) {
    if (0 < int && int < 0xfd) {
        return {value: int, length: 1};
    } else if (0xfd < int && int <= 0xffff) {
        return {
            value: parseInt("0xFD" + $.bytesToHex($.numToBytes(int, 2)), 16),
            length: 2
        };
    } else if (0xffff < int && int <= 0xffffffff) {
        return {
            value: parseInt("0xFE" + $.bytesToHex($.numToBytes(int, 4)), 16),
            length: 4
        };
    } else if (0xffffffff < int && int <= 0xffffffffffffffff) {
        return {
            value: parseInt("0xFF" + $.bytesToHex($.numToBytes(int, 8)), 16),
            length: 8
github saul / demofile / ext / bytebuffer.js View on Github external
var ByteBuffer = require('bytebuffer');

ByteBuffer.prototype.readVBytes = function (offset) {
  var length = this.readVarint32(offset);

  if (typeof offset !== 'undefined') {
    offset += length.length;
    length = length.value;
  }

  return this.readBytes(length, offset);
};

ByteBuffer.prototype.readIBytes = function (offset) {
  var length = this.readInt32(offset);

  if (typeof offset !== 'undefined') {
    offset += 4;
  }

  return this.readBytes(length, offset);
};

ByteBuffer.prototype.toSlicedBuffer = function () {
  return this.buffer.slice(this.offset, this.limit);
};

module.exports = ByteBuffer;
github chainside / btcnodejs / tools / bytebuffer.js View on Github external
} else if (0xffff < int && int <= 0xffffffff) {
        return {
            value: parseInt("0xFE" + $.bytesToHex($.numToBytes(int, 4)), 16),
            length: 4
        };
    } else if (0xffffffff < int && int <= 0xffffffffffffffff) {
        return {
            value: parseInt("0xFF" + $.bytesToHex($.numToBytes(int, 8)), 16),
            length: 8
        };
    } else {
        throw ("Wrong value for varint: ", int.toString("hex"));
    }
};

ByteBuffer.prototype.parseVarint = function (offset = undefined) {
    const header = parseInt(this.toHex(offset, offset + 1), 16);

    if (0 <= header && header < 0xfd) {
        return {
            value: header,
            length: 1
        };
    } else if (header === 0xfd) {

        return {
            value: parseInt(this.toHex(offset + 1, offset + 3)),
            length: 2
        };
    } else if (header === 0xfe) {

        return {