Node.js – v8.deserializer.readValue() Method


The v8.deserializer.readValue() method is used for deserializing the JavaScript value that is saved in the internal buffer and then return it to the user or system.

Syntax

v8.deserializer.readValue()

Parameters

Create a file with the name "readValue.js" and copy the following code snippet. After creating the file, use the command "node readValue.js" to run this code.

Example 1

Create a file with the name "readValue.js" and copy the following code snippet. After creating the file, use the command "node readValue.js" to run this code.

// v8.serializer.readValue() Demo Example

// Importing the v8 module
const v8 = require('v8');

// Defining the serializer object
const serializer = new v8.Serializer();

// Writing some value to internal buffer
console.log(serializer.writeValue('Welcome to TutorialsPoint'));

// Defining the deserializer object
const deserializer = new
v8.Deserializer(serializer.releaseBuffer());

// Reading the headers from internal buffer
console.log(deserializer.readValue());

Output

C:\home
ode>> node readValue.js true Welcome to TutorialsPoint

Example 2

Let’s have a look at one more example

// v8.serializer.readValue() Demo Example

// Importing the v8 module
const v8 = require('v8');

// Defining the serializer object
const serializer = new v8.Serializer();
var buffer = '';

// Serializing the input value
function serialize(input_value) {
   serializer.writeValue(input_value);
   // Printing the serialized value
   buffer = serializer.releaseBuffer();
   console.log(buffer);
   deserialize(buffer);
}

// Deserializing the input buffer
function deserialize(buffer) {
   // Defining the deserializer object
   const deserializer = new v8.Deserializer(buffer);
   console.log(deserializer.readValue());
}

serialize('TutorialsPoint')
serialize(1234)
serialize('Hello')

Output

C:\home
ode>> node readValue.js <Buffer 22 0e 54 75 74 6f 72 69 61 6c 73 50 6f 69 6e 74> TutorialsPoint <Buffer 49 a4 13> 1234 <Buffer 22 05 48 65 6c 6c 6f> Hello

Updated on: 18-Aug-2021

76 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements