Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
}
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();
},
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();
};
toLong() {
return Long.fromNumber(this.space)
.shiftLeft(56)
.or(
Long.fromNumber(this.type)
.shiftLeft(48)
.or(this.instance)
);
}
toLong() {
return Long.fromNumber(this.space).shiftLeft(56).or(
Long.fromNumber(this.type).shiftLeft(48).or(this.instance)
);
}
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 (
toLong() {
return Long.fromNumber(this.space).shiftLeft(56).or(
Long.fromNumber(this.type).shiftLeft(48).or(this.instance)
);
}
toLong() {
return Long.fromNumber(this.space).shiftLeft(56).or(
Long.fromNumber(this.type).shiftLeft(48).or(this.instance)
);
}