Node.js – v8.deserialize() Method


The v8.deserialize() method provides a method to deserialize the serialized buffer back into the original text. This method uses the default deserializer with default options to read the original JS value from the buffer.

Syntax

v8.deserialize(buffer)

Parameters

  • buffer − The input buffer that will be de-serialized.

The function returns the original text output after de-serializing the input buffer.

Example 1

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

// v8.deserialize() Demo Example

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

// Initializing the data variable
var data = "Welcome to Tutorials Point !"

// Serializing the value
var serializedValue = v8.serialize(data);

// Printing the serialized and deserialized value
console.log('Serialized data : ', serializedValue)
console.log('Data after de-serializing', v8.deserialize(serializedValue))

Output

C:\home
ode>> node deserialize.js Serialized data : <Buffer ff 0d 22 1c 57 65 6c 63 6f 6d 65 20 74 6f 20 54 75 74 6f 72 69 61 6c 73 20 50 6f 69 6e 74 20 21> Data after de-serializing Welcome to Tutorials Point !

Example 2

Let’s have a look at one more example

// v8.deserialize() Demo Example

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

// Initializing the data variable
var data = "Welcome to Tutorials Point !"

// Serializing the value
var serializedValue = v8.serialize(data);

// Printing the serialized and deserialized value
console.log('Serialized data : ', serializedValue)
console.log('Data after de-serializing', v8.deserialize(serializedValue))

var number = v8.serialize(12345);
console.log('Serializing numbers', v8.serialize(number))
console.log('Data after de-serializing', v8.deserialize(number))

var decimal = v8.serialize(12345.543);
console.log('Serializing decimal', v8.serialize(decimal))
console.log('Data after de-serializing', v8.deserialize(decimal))

Output

C:\home
ode>> node deserialize.js Serialized data : <Buffer ff 0d 22 1c 57 65 6c 63 6f 6d 65 20 74 6f 20 54 75 74 6f 72 69 61 6c 73 20 50 6f 69 6e 74 20 21> Data after de-serializing Welcome to Tutorials Point ! Serializing numbers <Buffer ff 0d 5c 0a 06 ff 0d 49 f2 c0 01> Data after de-serializing 12345 Serializing decimal <Buffer ff 0d 5c 0a 0b ff 0d 4e dd 24 06 81 c5 1c c8 40> Data after de-serializing 12345.543

Updated on: 17-Aug-2021

463 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements