How to use the bytebuffer.Long.fromNumber 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 EOSIO / eosjs / src / format.js View on Github external
function decodeName(value, littleEndian = true) {
  value = ULong(value)

  // convert from LITTLE_ENDIAN
  let beHex = ''
  const bytes = littleEndian ? value.toBytesLE() : value.toBytesBE()
  for(const b of bytes) {
    const n = Number(b).toString(16)
    beHex += (n.length === 1 ? '0' : '') + n
  }
  beHex += '0'.repeat(16 - beHex.length)

  const fiveBits = Long.fromNumber(0x1f, true)
  const fourBits = Long.fromNumber(0x0f, true)
  const beValue = Long.fromString(beHex, true, 16)

  let str = ''
  let tmp = beValue

  for(let i = 0; i <= 12; i++) {
    const c = charmap[tmp.and(i === 0 ? fourBits : fiveBits)]
    str = c + str
    tmp = tmp.shiftRight(i === 0 ? 4 : 5)
  }
  str = str.replace(/\.+$/, '') // remove trailing dots (all of them)

  // console.log('decodeName', str, beValue.toString(), value.toString(), JSON.stringify(beValue.toString(2).split(/(.....)/).slice(1)))

  return str
github EOSIO / eosjs / src / format.js View on Github external
function decodeName(value, littleEndian = true) {
  value = ULong(value)

  // convert from LITTLE_ENDIAN
  let beHex = ''
  const bytes = littleEndian ? value.toBytesLE() : value.toBytesBE()
  for(const b of bytes) {
    const n = Number(b).toString(16)
    beHex += (n.length === 1 ? '0' : '') + n
  }
  beHex += '0'.repeat(16 - beHex.length)

  const fiveBits = Long.fromNumber(0x1f, true)
  const fourBits = Long.fromNumber(0x0f, true)
  const beValue = Long.fromString(beHex, true, 16)

  let str = ''
  let tmp = beValue

  for(let i = 0; i <= 12; i++) {
    const c = charmap[tmp.and(i === 0 ? fourBits : fiveBits)]
    str = c + str
    tmp = tmp.shiftRight(i === 0 ? 4 : 5)
  }
  str = str.replace(/\.+$/, '') // remove trailing dots (all of them)

  // console.log('decodeName', str, beValue.toString(), value.toString(), JSON.stringify(beValue.toString(2).split(/(.....)/).slice(1)))

  return str
}
github peerplays-network / peerplays-core-gui / lib / chain / src / TransactionHelper.js View on Github external
unique_nonce_uint64() {
    let entropy = this.update_entropy();

    let long = Long.fromNumber(Date.now());
    long = long.shiftLeft(8).or(Long.fromNumber(entropy));
    // console.log('unique_nonce_uint64 shift8\t',ByteBuffer.allocate(8).writeUint64(long).toHex(0))
    return long.toString();
  },
github svk31 / graphenejs-lib / lib / chain / src / TransactionHelper.js View on Github external
helper.unique_nonce_uint64=function() {
    var entropy = helper.unique_nonce_entropy = ((() => {

            if (helper.unique_nonce_entropy === null) {
                //console.log('... secureRandom.randomUint8Array(1)[0]',secureRandom.randomUint8Array(1)[0])
                return parseInt(secureRandom.randomUint8Array(1)[0]);
            } else {
                return ++helper.unique_nonce_entropy % 256;
            }
    })()
    );
    var long = Long.fromNumber(Date.now());
    //console.log('unique_nonce_uint64 date\t',ByteBuffer.allocate(8).writeUint64(long).toHex(0))
    //console.log('unique_nonce_uint64 entropy\t',ByteBuffer.allocate(8).writeUint64(Long.fromNumber(entropy)).toHex(0))
    long = long.shiftLeft(8).or(Long.fromNumber(entropy));
    //console.log('unique_nonce_uint64 shift8\t',ByteBuffer.allocate(8).writeUint64(long).toHex(0))
    return long.toString();
};
github bitshares / bitsharesjs / lib / chain / src / ObjectId.js View on Github external
toLong() {
        return Long.fromNumber(this.space)
            .shiftLeft(56)
            .or(
                Long.fromNumber(this.type)
                    .shiftLeft(48)
                    .or(this.instance)
            );
    }
github peerplays-network / peerplays-core-gui / lib / chain / src / ObjectId.js View on Github external
toLong() {
        return Long.fromNumber(this.space).shiftLeft(56).or(
            Long.fromNumber(this.type).shiftLeft(48).or(this.instance)
        );
    }
github steemit / steem-js / src / auth / serializer / src / object_id.js View on Github external
var Long = (require('bytebuffer')).Long;

var v = require('./validation');
var DB_MAX_INSTANCE_ID = Long.fromNumber(((Math.pow(2,48))-1));

class ObjectId {
    
    constructor(space,type,instance){
        this.space = space;
        this.type = type;
        this.instance = instance;
        var instance_string = this.instance.toString();
        var object_id = `${this.space}.${this.type}.${instance_string}`;
        if (!v.is_digits(instance_string)) {
            throw new `Invalid object id ${object_id}`();
        }
    }
    
    static fromString(value){
        if (
github steemit / steem-js / src / auth / serializer / src / object_id.js View on Github external
toLong() {
        return Long.fromNumber(this.space).shiftLeft(56).or(
            Long.fromNumber(this.type).shiftLeft(48).or(this.instance)
        );
    }
github peerplays-network / peerplays-core-gui / lib / chain / src / ObjectId.js View on Github external
toLong() {
        return Long.fromNumber(this.space).shiftLeft(56).or(
            Long.fromNumber(this.type).shiftLeft(48).or(this.instance)
        );
    }