Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// the start of the message body block
const offsetBodyStart = binaryStream.length;
// the end of the message body block
const offsetBodyEnd = binaryStream.buffer.length;
this.totalBodySize += (offsetBodyEnd - offsetBodyStart);
this.offsetBodyStart = offsetBodyStart;
// add message body to a queue
// note : Buffer.slice create a shared memory !
// use Buffer.clone
const sharedBuffer = chunk.slice(offsetBodyStart, offsetBodyEnd);
const clonedBuffer = createFastUninitializedBuffer(sharedBuffer.length);
sharedBuffer.copy(clonedBuffer, 0, 0);
this.blocks.push(clonedBuffer);
return true;
}
function packTcpMessage(msgType, encodableObject) {
assert(is_valid_msg_type(msgType));
const messageChunk = createFastUninitializedBuffer(encodableObject.binaryStoreSize() + 8);
// encode encodeableObject in a packet
const stream = new BinaryStream(messageChunk);
encodeMessage(msgType, encodableObject, stream);
return messageChunk;
}
export function packTcpMessage(msgType: string, encodableObject: BaseUAObject): Buffer {
assert(is_valid_msg_type(msgType));
const messageChunk = createFastUninitializedBuffer(encodableObject.binaryStoreSize() + 8);
// encode encodeableObject in a packet
const stream = new BinaryStream(messageChunk);
encodeMessage(msgType, encodableObject, stream);
return messageChunk;
}
export function randomByteString(value: any, len: number): ByteString {
len = len || getRandomInt(1, 200);
const b = createFastUninitializedBuffer(len);
for (let i = 0; i < len; i++) {
b.writeUInt8(getRandomInt(0, 255), i);
}
return b;
}
public createChunk(msgType: string, chunkType: string, length: number): Buffer {
assert(msgType === "MSG");
assert(this._pendingBuffer === undefined, "createChunk has already been called ( use write first)");
const totalLength = length + this.headerSize;
const buffer = createFastUninitializedBuffer(totalLength);
writeTCPMessageHeader("MSG", chunkType, totalLength, buffer);
this._pendingBuffer = buffer;
return buffer;
}
export function makebuffer_from_trace(func: string | Function): Buffer {
if (typeof func === "string") {
return makeBuffer(hexString(func as string));
}
return makeBuffer(hexString(inlineText(func)));
}