Open In App

Node.js v8.Serializer.writeUint32() Method

Last Updated : 22 Jul, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The v8.Serializer.writeUint32() method is an inbuilt application programming interface of the v8.Serializer module, which is used to write the raw 32-bit integer value to the internal buffer. For use inside of custom serializer._writeHostObject().

Syntax:

v8.Serializer.writeUint32( value );

Parameters: This method accepts single parameter as mentioned above and described below.

  • value: It is a required parameter, refers to a 32-bit integer to be written to the internal buffer.

Return Value: This method does not return anything but writes a raw 32-bit integer value to the internal buffer.

Below examples illustrate the use of v8.Serializer.writeUint32() method in Node.js:

Example 1:

Filename: index.js




// Accessing v8 module
const v8 = require('v8');
const serializer = new v8.Serializer();
  
// Calling v8.serializer.writeUint32() 
console.log(serializer.releaseBuffer());
serializer.writeUint32(29698);
console.log(serializer.releaseBuffer());
  
// Writing two 32 bits number one
// after another
console.log("writing two 32 bits "
    + "number one after another");
  
serializer.writeUint32(29698);
serializer.writeUint32(29698);
console.log(serializer.releaseBuffer());
  
console.log("reading after write");
  
// Calling v8.serializer.writeUint32() 
serializer.writeUint32(5783);
  
// Calling v8.deserializer.readUint32() 
const deserializer = new 
    v8.Deserializer(serializer.releaseBuffer());
console.log(deserializer.readUint32());


Run index.js file using the following command:

node index.js

Output:

Undefined
<Buffer 97 2d>

Example 2:

Filename: index.js





Run index.js file using the following command:

node index.js

Output:

<Buffer >
<Buffer 82 e8 01>
writing two 32 bits number one after another
<Buffer 82 e8 01 82 e8 01>
reading after write
5783

Reference: https://nodejs.org/api/v8.html#v8_serializer_writeuint32_value



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads