How to use the allocate function from bytebuffer

Find comprehensive JavaScript bytebuffer.allocate code examples handpicked from public code repositorys.

843
844
845
846
847
848
849
850
851
852
853
854
855


function createMachineID(val_bb3, val_ff2, val_3b3) {
	// Machine IDs are binary KV objects with root key MessageObject and three hashes named BB3, FF2, and 3B3.
	// I don't feel like writing a proper BinaryKV serializer, so this will work fine.


	let buffer = ByteBuffer.allocate(155, ByteBuffer.LITTLE_ENDIAN);
	buffer.writeByte(0); // 1 byte, total 1
	buffer.writeCString("MessageObject"); // 14 bytes, total 15


	buffer.writeByte(1); // 1 byte, total 16
fork icon137
star icon643
watch icon0

451
452
453
454
455
456
457
458
459
460

// Make the header
let hdrBuf;
if (header.msg == EMsg.ChannelEncryptResponse) {
	// since we're setting up the encrypted channel, we use this very minimal header
	hdrBuf = ByteBuffer.allocate(4 + 8 + 8, ByteBuffer.LITTLE_ENDIAN);
	hdrBuf.writeUint32(header.msg);
	hdrBuf.writeUint64(header.targetJobID || JOBID_NONE);
	hdrBuf.writeUint64(jobIdSource || header.sourceJobID || JOBID_NONE);
} else if (header.proto) {
fork icon137
star icon643
watch icon0

+ 353 other calls in file

148
149
150
151
152
153
154
155
156
157
        unique_nonce_entropy = parseInt(b[0] << 8 | b[1], 10);
    }
    var long = Long.fromNumber(Date.now());
    var entropy = ++unique_nonce_entropy % 0xFFFF;
    // console.log('uniqueNonce date\t', ByteBuffer.allocate(8).writeUint64(long).toHex(0))
    // console.log('uniqueNonce entropy\t', ByteBuffer.allocate(8).writeUint64(Long.fromNumber(entropy)).toHex(0))
    long = long.shiftLeft(16).or(Long.fromNumber(entropy));
    // console.log('uniqueNonce final\t', ByteBuffer.allocate(8).writeUint64(long).toHex(0))
    return long.toString();
}
fork icon0
star icon0
watch icon1

+ 2 other calls in file