這個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\node>> 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\node>> node writeUint32.js
<Buffer >
<Buffer bd 3d bd 3d>
Reading the same value after adding to buffer
7869
相關用法
- Node.js v8.serializer.writeUint64()用法及代碼示例
- Node.js v8.serializer.writeRawBytes()用法及代碼示例
- Node.js v8.serializer.writeDouble()用法及代碼示例
- Node.js v8.serializer.writeHeader()用法及代碼示例
- Node.js v8.serializer.writeValue()用法及代碼示例
- Node.js v8.serializer.releaseBuffer()用法及代碼示例
- Node.js v8.serialize()用法及代碼示例
- Node.js v8.getHeapSpaceStatistics()用法及代碼示例
- Node.js v8.deserializer.readRawBytes()用法及代碼示例
- Node.js v8.deserializer.readUint32()用法及代碼示例
- Node.js v8.Deserializer.readUint32()用法及代碼示例
- Node.js v8.Serializer.writeUint32()用法及代碼示例
- Node.js v8.Serializer.releaseBuffer()用法及代碼示例
- Node.js v8.Serializer.writeUint64()用法及代碼示例
- Node.js v8.cachedDataVersionTag()用法及代碼示例
- Node.js v8.getHeapStatistics()用法及代碼示例
- Node.js v8.deserializer.readValue()用法及代碼示例
- Node.js v8.Deserializer.readDouble()用法及代碼示例
- Node.js v8.deserializer.readUint64()用法及代碼示例
- Node.js v8.Deserializer.readUint64()用法及代碼示例
注:本文由純淨天空篩選整理自Mayank Agarwal大神的英文原創作品 Node.js – v8.serializer.writeUint32() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。