Skip to content
Related Articles

Related Articles

Improve Article
Node.js v8.Deserializer.readValue() Method
  • Last Updated : 23 Jul, 2020

The v8.Deserializer.readValue() method is an inbuilt application programming interface of the v8.Deserializer module which is used to read the JS value from serialized data as present in a buffer.

Syntax:

v8.Deserializer.readValue();

Parameters: This method does not accept any parameters.

Return Value: This method reads JS value from serialized representation as present in a buffer and returns it on successful reading.

Below examples illustrate the use of v8.Deserializer.readValue() method in Node.js:



Example 1: Filename: index.js




// Accessing v8 module
const v8 = require('v8');
const serializer = new v8.Serializer();
  
// Calling v8.serializer.writeValue() 
console.log(serializer.writeValue("GeeksforGeeks"));
  
// Calling v8.deserializer.readValue() 
const deserializer = new v8.Deserializer(
            serializer.releaseBuffer());
              
console.log(deserializer.readValue());

Run index.js file using the following command:

node index.js

Output:

true
GeeksforGeeks

Example 2: Filename: index.js




// Accessing v8 module
const v8 = require('v8');
const serializer = new v8.Serializer();
  
// Calling v8.serializer.writeValue() 
console.log(serializer.writeValue(839475.3495));
buff = serializer.releaseBuffer();
console.log("buffer data is:");
console.log(buff);
  
// Calling v8.deserializer.readValue() 
const deserializer = new v8.Deserializer(buff);
  
console.log("deserialized data: " 
        + deserializer.readValue());

Run index.js file using the following command:

node index.js

Output:

true
buffer data is:
<Buffer 4e fc a9 f1 b2 66 9e 29 41>
deserialized data: 839475.3495

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :