NodeJS v8.serializer.writeRawBytes() Method
The NodeJS v8.serializer.writeRawBytes() method of class v8.serializer is used to write raw bytes into the serializer's internal buffer. The term raw byte" means an uninterpreted byte values.
Syntax
Following is the syntax of the NodeJS v8.serializer.writeRawBytes() method −
v8.serializer.writeRawBytes(buffer)
Parameters
This method accepts only one parameter.
buffer − A Buffer, TypedArray, DataView that will be written to the internal buffer.
Return Value
This method returns undefined instead, it Writes raw bytes into the serializer's internal buffer.
Example
In the example, we are trying to write raw bytes into the serializer's internal buffer using NodeJS v8.serializer.writeRawBytes() method.
const v8 = require('v8');
const serializer = new v8.Serializer();
// Writing raw bytes after serializing with v8
console.log(serializer.writeRawBytes(v8.serialize('TutorialsPoint')));
Output
As we can see in the output below, the writeRawBytes() method returns undefined instead, it writes the raw bytes (that are passed as parameter) to the internal buffer.
undefined
Example
In the following example below, we are trying to write raw bytes to the serializer's internal buffer. Then we are releasing the internal buffer to check whether the raw bytes are written or not.
const v8 = require('v8');
const serializer = new v8.Serializer();
let data = 'TutorialsPoint';
// Writing raw bytes after serializing
console.log(serializer.writeRawBytes(v8.serialize(data)));
console.log(serializer.releaseBuffer());
Output
undefined <Buffer ff 0d 22 0e 54 75 74 6f 72 69 61 6c 73 50 6f 69 6e 74>
Example
In this example, we are trying to pass a typedArray as a rawbytes that will be written to the serializer's internal buffer.
const v8 = require('v8');
const serializer = new v8.Serializer();
const typedArray = new Int8Array(4);
typedArray[0] = 5;
typedArray[1] = 7;
typedArray[2] = 9;
typedArray[3] = 11;
console.log(serializer.writeRawBytes(v8.serialize(typedArray)));
console.log(serializer.releaseBuffer());
Output
undefined <Buffer ff 0d 5c 00 04 05 07 09 0b>