• Node.js Video Tutorials

NodeJS - writeUnit32() Method



The NodeJS v8.serializer.writeUnit32() method of class v8.serializer is used to write a raw 32-bit unsigned integer to the internal buffer.

The Unit32 is a 32-bit unsigned integer that has a minimum value of 0 and a maximum value of 4,294,967,295 (inclusive).

This method is mainly used inside the custom serializer._writeHostObject() that is used to write some kind of host object.

Syntax

Following is the syntax of the NodeJS v8.serializer.writeUnit32() method

v8.serializer.writeUnit32(value)

Parameters

This method accepts only one parameter.

  • value − A 32-bit unsigned integer that will be written inside the internal buffer.

Return Value

This method returns undefined instead, it writes the passed value (raw 32-bit integer) to the internal buffer.

Example

In the following example, we are trying to write a raw 32-bit unsigned integer to the internal buffer using v8.serializer.writeUnit32() method.

const v8 = require('v8');
const serializer = new v8.Serializer();
console.log(serializer.writeUint32(8792));

Output

As we can see in the output below, the writeUnit32() method returns undefined instead, it writes the passed value to the internal buffer.

undefined

Example

In the example below, we are trying to write a 32-bit unsigned integer to the internal buffer. Then we are releasing the internal buffer to check whether the 32-bit unsigned integer is written or not.

const v8 = require('v8');
const serializer = new v8.Serializer();
console.log(serializer.releaseBuffer());
serializer.writeUint32(32432532);
console.log(serializer.releaseBuffer());

Output

<Buffer >
<Buffer 94 c3 bb 0f>

Example

If we write multiple 32-bit unsigned integers to the internal buffer, the integers will be added sequentially.

const v8 = require('v8');
const serializer = new v8.Serializer();
serializer.writeUint32(8792);
serializer.writeUint32(8792);
serializer.writeUint32(8792);
console.log(serializer.releaseBuffer());

Output

<Buffer d8 44 d8 44 d8 44>
nodejs_v8_module.htm
Advertisements