Node.js – v8.serializer.writeUint32() 方法
v8.serializer.writeUint32() 方法用于写入一个未经处理的 32 位无符号整数。此函数主要在自定义的 serializer._writeHostObject() 中使用。
语法
v8.serializer.writeUint32(value)
参数
- value − 此参数输入需要写入内部缓冲区的 32 位整数。
此函数不返回任何内容,而是将传递的值写入内部缓冲区。
示例 1
创建一个名为 "writeUint32.js" 的文件,并复制以下代码段。创建文件后,使用 "node writeUint32.js" 命令运行此代码。
// v8.deserialize() Demo Example // Importing the v8 module const v8 = require('v8'); // Initializing the v8 Serializer object const serializer = new v8.Serializer(); // Adding 32-bit integer to internal buffer. // This will return undefined since it only adds to buffer console.log(serializer.writeUint32(7869)); // Releasing and printing the internal buffer console.log(serializer.releaseBuffer());
输出
C:\home
ode>> node writeUint32.js undefined <Buffer bd 3d>
示例 2
我们再来看一个示例
// v8.serializer.writeUint32() Demo Example // Importing v8 module const v8 = require('v8'); const serializer = new v8.Serializer(); // Calling v8.serializer.writeUint32() console.log(serializer.releaseBuffer()); // Writing the same 32-bit integer twice serializer.writeUint32(7869); serializer.writeUint32(7869); // Adding the above value to internal buffer console.log(serializer.releaseBuffer()); // Writing the same 32-bit integer again serializer.writeUint32(7869); // console.log(serializer.releaseBuffer()); console.log("Reading the same value after adding to buffer"); // Calling v8.deserializer.readUint32() const deserializer = new v8.Deserializer(serializer.releaseBuffer()); // Deserializing the internal buffer console.log(deserializer.readUint32());
输出
C:\home
ode>> node writeUint32.js <Buffer > <Buffer bd 3d bd 3d> Reading the same value after adding to buffer 7869
广告