function getLengthEncoding(n, special) {
  if(n < 0) throw new Error('Cannot write negative length encoding: ' + n);
  if(!special) {
    if(n <= 0x3F) {
      return new Buffer([n]);
    }else if (n <= 0x3FFF) {
      return new Buffer([0x40 | (n >> 8), n & 0xFF]);
    }else if (n <= 0xFFFFFFFF) {
      var buffer = new Buffer(5);
      buffer.writeUInt8(0x80, 0);
      buffer.writeUInt32BE(n, 1);
      return buffer;
    }
    throw new Error('Failed to write length encoding: ' + n);
  }else{
    if (n > 0x3F) {
      throw new Error('Cannot encode ' + n + ' using special length encoding');
    }
    return new Buffer([0xC0 | n]);
  }
}
function getLengthEncoding(n, special) {
  if(n < 0) throw new Error('Cannot write negative length encoding: ' + n);
  if(!special) {
    if(n <= 0x3F) {
      return new Buffer([n]);
    }else if (n <= 0x3FFF) {
      return new Buffer([0x40 | (n >> 8), n & 0xFF]);
    }else if (n <= 0xFFFFFFFF) {
      var buffer = new Buffer(5);
      buffer.writeUInt8(0x80, 0);
      buffer.writeUInt32BE(n, 1);
      return buffer;
    }
    throw new Error('Failed to write length encoding: ' + n);
  }else{
    if (n > 0x3F) {
      throw new Error('Cannot encode ' + n + ' using special length encoding');
    }
    return new Buffer([0xC0 | n]);
  }
}
function getLengthEncoding ( n , special ) { if ( n < 0 ) throw new Error ( 'Cannot write negative length encoding: ' + n ) ; if ( ! special ) { if ( n <= 0x3F ) { return new Buffer ( [ n ] ) ; } else if ( n <= 0x3FFF ) { return new Buffer ( [ 0x40 | ( n >> 8 ) , n & 0xFF ] ) ; } else if ( n <= 0xFFFFFFFF ) { var buffer = new Buffer ( 5 ) ; buffer . writeUInt8 ( 0x80 , 0 ) ; buffer . writeUInt32BE ( n , 1 ) ; return buffer ; } throw new Error ( 'Failed to write length encoding: ' + n ) ; } else { if ( n > 0x3F ) { throw new Error ( 'Cannot encode ' + n + ' using special length encoding' ) ; } return new Buffer ( [ 0xC0 | n ] ) ; } }
Get a buffer with the length encoding.
Get a buffer with the length encoding .