- Node.js Tutorial
- Node.js - Home
- Node.js - Introduction
- Node.js - Environment Setup
- Node.js - First Application
- Node.js - REPL Terminal
- Node.js - Command Line Options
- Node.js - Package Manager (NPM)
- Node.js - Callbacks Concept
- Node.js - Upload Files
- Node.js - Send an Email
- Node.js - Events
- Node.js - Event Loop
- Node.js - Event Emitter
- Node.js - Debugger
- Node.js - Global Objects
- Node.js - Console
- Node.js - Process
- Node.js - Scaling Application
- Node.js - Packaging
- Node.js - Express Framework
- Node.js - RESTFul API
- Node.js - Buffers
- Node.js - Streams
- Node.js - File System
- Node.js MySQL
- Node.js - MySQL Get Started
- Node.js - MySQL Create Database
- Node.js - MySQL Create Table
- Node.js - MySQL Insert Into
- Node.js - MySQL Select From
- Node.js - MySQL Where
- Node.js - MySQL Order By
- Node.js - MySQL Delete
- Node.js - MySQL Update
- Node.js - MySQL Join
- Node.js MongoDB
- Node.js - MongoDB Get Started
- Node.js - MongoDB Create Database
- Node.js - MongoDB Create Collection
- Node.js - MongoDB Insert
- Node.js - MongoDB Find
- Node.js - MongoDB Query
- Node.js - MongoDB Sort
- Node.js - MongoDB Delete
- Node.js - MongoDB Update
- Node.js - MongoDB Limit
- Node.js - MongoDB Join
- Node.js Modules
- Node.js - Modules
- Node.js - Built-in Modules
- Node.js - Utility Modules
- Node.js - Web Module
- Node.js Useful Resources
- Node.js - Quick Guide
- Node.js - Useful Resources
- Node.js - Dicussion
NodeJS v8.deserializer.readHeader() Method
The NodeJS v8.deserializer.readHeader() method of class v8.deserializer is used to read and validate the header in the internal buffer.
This method also ensures whether the header contains a valid serialization format version.
This method returns true if the header is valid, else it throws an error.
Syntax
Following is the syntax of the NodeJS v8.deserializer.readHeader() method −
v8.deserializer.readHeader()
Parameters
This method does not accept any parameters.
Return Value
This method reads the header of the internal buffer at the deserializer and validates it including the format version. If the header is valid, it returns true. Else it throws an error.
Example
In the following example, firstly, we are trying to write a header to the internal buffer using the v8.serializer.writeHeader() method. Then we are trying to read and validate the header using the v8.deserializer.readHeader() method.
// Importing the v8 module const v8 = require('v8'); // Defining the serializer object const serializer = new v8.Serializer(); // Writing the headers to the internal buffer serializer.writeHeader(); // Defining the deserializer object const deserializer = new v8.Deserializer(serializer.releaseBuffer()); // Reading the headers from internal buffer console.log(deserializer.readHeader()); // Printing the header values from internal buffer console.log(serializer.releaseBuffer());
Output
true <Buffer >
Example
In this example, we are trying to write a 32-bit unsigned integer instead of heading to the internal buffer. So, the readHeader() method will throw an error.
// Importing the v8 module const v8 = require('v8'); // Defining the serializer object const serializer = new v8.Serializer(); // Writing a 32-bit unsigned integer to the internal buffer serializer.writeUint32(7869); // Defining the deserializer object const deserializer = new v8.Deserializer(serializer.releaseBuffer()); // Reading the headers from internal buffer console.log(deserializer.readHeader()); // Printing the header values from internal buffer console.log(serializer.releaseBuffer());
Error
Following is the output of the above code −
/home/cg/root/63b66d48bc404/main.js:14 console.log(deserializer.readHeader()); ^ Error: Unable to deserialize cloned data due to invalid or unsupported version. at Object.<anonymous> (/home/cg/root/63b66d48bc404/main.js:14:26) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3) at Function.Module.runMain (internal/modules/cjs/loader.js:744:10) at startup (internal/bootstrap/node.js:238:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
To Continue Learning Please Login
Login with Google