这个v8.deserializer.readRawBytes()方法用于从解串器的内部缓冲区读取原始字节。它本质上返回缓冲区而不反序列化它。输入参数 ‘length’ 指的是在将原始字节写入同一内部缓冲区时传递的缓冲区长度。
用法
v8.deserializer.readRawBytes(length)
参数
它需要一个参数 -
length- 此参数接受传递给的缓冲区长度的输入serializer.writeRawBytes()。
Example 1
创建一个文件名"readRawBytes.js"并复制以下代码片段。创建文件后,使用命令“node readRawBytes.js”运行此代码。
// v8.serializer.readRawBytes() Demo Example
// Importing the v8 module
const v8 = require('v8');
// Initializing the serializer object
const serializer = new v8.Serializer();
// Wriitng the data to the internal buffer
serializer.writeRawBytes(v8.serialize(12345));
// Initializing the serializer object
const deserializer = new
v8.Deserializer(serializer.releaseBuffer());
// Reading the raw bytes data from internal buffer
console.log(deserializer.readRawBytes(6));
输出
C:\home\node>> node readRawBytes.js <Buffer ff 0d 49 f2 c0 01>
Example 2
让我们再看一个例子
// v8.serializer.readRawBytes() Demo Example
// Importing the v8 module
const v8 = require('v8');
// Initializing the serializer object
const serializer = new v8.Serializer();
var buffer;
// Wriitng the data to the internal buffer
function writeRawBytes(data, len) {
serializer.writeRawBytes(v8.serialize(data));
buffer = serializer.releaseBuffer();
console.log("Data written & Retrieved:")
console.log(buffer)
readRawBytes(len);
}
// Reading the raw bytes data from internal buffer
function readRawBytes(len) {
const deserializer = new v8.Deserializer(buffer);
console.log(deserializer.readRawBytes(len));
}
writeRawBytes(9876, 6)
writeRawBytes('Welcome to TutorialsPoint', 29)
writeRawBytes(12345, 6)
输出
C:\home\node>> node readRawBytes.js Data written & Retrieved: <Buffer ff 0d 49 a8 9a 01> <Buffer ff 0d 49 a8 9a 01> Data written & Retrieved: <Buffer ff 0d 22 19 57 65 6c 63 6f 6d 65 20 74 6f 20 54 75 74 6f 72 69 61 6c 73 50 6f 69 6e 74> <Buffer ff 0d 22 19 57 65 6c 63 6f 6d 65 20 74 6f 20 54 75 74 6f 72 69 61 6c 73 50 6f 69 6e 74> Data written & Retrieved: <Buffer ff 0d 49 f2 c0 01> <Buffer ff 0d 49 f2 c0 01>
相关用法
- Node.js v8.deserializer.readUint32()用法及代码示例
- Node.js v8.deserializer.readValue()用法及代码示例
- Node.js v8.deserializer.readUint64()用法及代码示例
- Node.js v8.deserializer.readHeader()用法及代码示例
- Node.js v8.deserialize()用法及代码示例
- Node.js v8.getHeapSpaceStatistics()用法及代码示例
- Node.js v8.serializer.writeRawBytes()用法及代码示例
- Node.js v8.Deserializer.readUint32()用法及代码示例
- Node.js v8.serializer.releaseBuffer()用法及代码示例
- Node.js v8.Serializer.writeUint32()用法及代码示例
- Node.js v8.serializer.writeUint32()用法及代码示例
- Node.js v8.Serializer.releaseBuffer()用法及代码示例
- Node.js v8.Serializer.writeUint64()用法及代码示例
- Node.js v8.serializer.writeUint64()用法及代码示例
- Node.js v8.cachedDataVersionTag()用法及代码示例
- Node.js v8.serializer.writeDouble()用法及代码示例
- Node.js v8.getHeapStatistics()用法及代码示例
- Node.js v8.Deserializer.readDouble()用法及代码示例
- Node.js v8.Deserializer.readUint64()用法及代码示例
- Node.js v8.Serializer.writeRawBytes()用法及代码示例
注:本文由纯净天空筛选整理自Mayank Agarwal大神的英文原创作品 Node.js – v8.deserializer.readRawBytes() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。