Node.js v8.Deserializer.readRawBytes() 方法
v8.Deserializer.readRawBytes() 方法是 v8.Deserializer 模块的内置应用程序编程接口,用于从解串器的给定长度的内部缓冲区读取原始缓冲区数据。用于自定义 Deserializer._readHostObject() 内部。
语法:
v8.Deserializer.readRawBytes( length );
参数:此方法接受上面提到的单个参数,如下所述:
- length:必填参数,指从解串器内部缓冲区中读取的缓冲区长度。
返回值:此方法从反序列化器的内部缓冲区中读取原始缓冲区数据,并将其作为缓冲数据返回。
以下示例说明了在 Node.js 中使用 v8.Deserializer.readRawBytes() 方法:
示例 1:文件名:index.js
// Accessing v8 module
const v8 = require('v8');
const serializer = new v8.Serializer();
// Calling v8.serializer.writeRawBytes()
serializer.writeRawBytes(v8.serialize(5783));
buff = serializer.releaseBuffer();
console.log(buff);
// Calling v8.deserializer.readRawBytes()
const deserializer = new v8.Deserializer(buff);
console.log(deserializer.readRawBytes(5));
使用以下命令运行index.js文件:
node index.js
输出:
示例 2:文件名:index.js
// Accessing v8 module
const v8 = require('v8');
const serializer = new v8.Serializer();
// Calling v8.serializer.writeRawBytes()
serializer.writeRawBytes(v8.serialize(29698));
serializer.writeRawBytes(v8.serialize("geeksforgeeks"));
serializer.writeRawBytes(v8.serialize(29698));
buff = serializer.releaseBuffer();
console.log(buff);
// Calling v8.deserializer.readRawBytes()
const deserializer = new v8.Deserializer(buff);
console.log(deserializer.readRawBytes(6));
console.log(deserializer.readRawBytes(17));
console.log(deserializer.readRawBytes(6));
使用以下命令运行index.js文件:
node index.js
输出:
参考: https://nodejs.org/api/v8.html#v8_deserializer_readrawbytes_length