Skip to content
Related Articles

Related Articles

Improve Article
Node.js v8.Serializer.writeDouble() Method
  • Last Updated : 22 Jul, 2020

The v8.Serializer.writeDouble() method is an inbuilt application programming interface of the v8.Serializer module which is used to write a JS number value to the internal buffer. For use inside of custom serializer._writeHostObject().

Syntax:

v8.Serializer.writeDouble( Value );

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

  • value: It is required parameter, refers to JS number value to be written to the internal buffer.

Return Value: This method does not return anything but writes a JS number value to the internal buffer.

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



Example 1: Filename: index.js




// Accessing v8 module
const v8 = require('v8');
const serializer = new v8.Serializer();
  
// Calling v8.serializer.writeDouble() 
serializer.writeDouble(5783.3984);
console.log(serializer.releaseBuffer());

Run index.js file using the following command:

node index.js

Output:

<Buffer ba da 8a fd 65 97 b6 40>

Example 2: Filename: index.js




// Accessing v8 module
const v8 = require('v8');
const serializer = new v8.Serializer();
  
// Calling v8.serializer.writeRawBytes() 
console.log(serializer.releaseBuffer());
  
// User defined Function
function writeDoubleData(data) {
    serializer.writeDouble(data);
    console.log(serializer.releaseBuffer());
}
  
// Function Call
writeDoubleData(123.44);

Run index.js file using the following command:

node index.js

Output:

<Buffer >
<Buffer 5c 8f c2 f5 28 dc 5e 40>

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :