• Node.js Video Tutorials

NodeJS v8.deserializer.readUnit32() Method



The NodeJS v8.deserializer.readUnit32() method of class v8.deserializer is used to read a raw 32-bit unsigned integer and return it.

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 deserializer._readHostObject() that is used to read some kind of host object.

Syntax

Following is the syntax of the NodeJS v8.deserializer.readUnit32() method

v8.deserializer.readUnit32()

Parameters

This method does not accept any parameters.

Return Value

This method reads and returns the raw 32-bit unsigned integer value from the buffer.

Example

In the example below, we are trying to write a raw 32-bit unsigned integer to the internal buffer using the v8.serializer.writeUnit32() method. Then we are trying to read that raw 32-bit unsigned integer present in the internal buffer using the v8.deserializer.readUnit32() method.

const v8 = require('v8');
const serializer = new v8.Serializer();
  
// Calling v8.serializer.writeUint32() 
serializer.writeUint32(98764567);
  
// Calling v8.deserializer.readUint32() 
const deserializer = new v8.Deserializer(serializer.releaseBuffer());

console.log(deserializer.readUint32());

Output

If we compile and run the above code, the output is as follows.

98764567

Example

Following is another example of readUnit32() method of class v8.deserializer.

const v8 = require('v8');
const serializer = new v8.Serializer();  
console.log(serializer.releaseBuffer());
serializer.writeUint32(876543);
buffer = serializer.releaseBuffer();
console.log("Internal Buffer data is:");
console.log(buffer);
const deserializer = new v8.Deserializer(buffer);
console.log("After deserializing, the data: ");
console.log(deserializer.readUint32());

Output

<Buffer >
Internal Buffer data is:
<Buffer ff bf 35>
After deserializing, the data: 
876543
nodejs_v8_module.htm
Advertisements