参考
将缓冲实例转换为“ 指针 ”
这个模块的灵感来自旧的 Pointer 课程从节点-ffi,但与
使用节点快的意向 Buffer 实例而不是慢 C++ Pointer
课。 这两个概念以前非常相似,但现在这个单元
把指针和缓冲器的功能带过来 所以
现在缓冲器更强大了.
特征 :
- 获取任意的内存地址
Buffer实例 - 读取/写入 JavaScript 对象的引用
Buffer实例 - 读取/写作
Buffer实例的内存地址到其它Buffer实例 - 读取/写作
int64_t财务报告和审定财务报表uint64_t数据值(数字或字符串) - “类型”公约,这样您就可以指定缓冲器作为
int *, (中文(简体) ), 和随意参考/参考. - 提供缓冲实例
NULL指针
安装
安装方式 npm数字 :
$ npm install ref-napi
实例
参考和疏导
var ref = require('ref-napi')
// so we can all agree that a buffer with the int value written
// to it could be represented as an "int *"
var buf = new Buffer(4)
buf.writeInt32LE(12345, 0)
// first, what is the memory address of the buffer?
console.log(buf.hexAddress()) // ← '7FA89D006FD8'
// using `ref`, you can set the "type", and gain magic abilities!
buf.type = ref.types.int
// now we can dereference to get the "meaningful" value
console.log(buf.deref()) // ← 12345
// you can also get references to the original buffer if you need it.
// this buffer could be thought of as an "int **"
var one = buf.ref()
// and you can dereference all the way back down to an int
console.log(one.deref().deref()) // ← 12345
见 完整 API 文档 需要更多的实例.
"类型"接口
您可以在附件上轻松定义自己的“类型”对象 Buffer 实例.
它只需要是一个包含以下内容的普通 JavaScript 对象
属性 :
| 名称 | 数据类型 | 说明 |
|---|---|---|
size | 数目 | 持有此类型所需的字节大小 . |
indirection | 数目 | 缓冲的当前间接水平. 通常这样 1个,然后从 ref() 打电话 数值小于或等于 0 个 无效. |
get | 职能(缓冲、冲抵) | 当间接级别是时, 引用该类型的函数 1个。 。 。 . |
set | 函数(缓冲、冲抵、值) | 设置缓冲实例值时引用的函数 . |
name | 字符串 | (可选) 此类型调试时使用的名称 . |
alignment | 数目 | (可选) 此类型在被放入结构时的对齐 。 类型默认值 size。 。 。 . |
请检查date=中的日期值 (帮助) Wiki页面 已经知道 类型",用于列表 以及已知的外部类型.
例如,您可以定义一种“ bigint” 类型,该类型可以将缩写为
bigint 实例:
var ref = require('ref-napi')
var bigint = require('bigint')
// define the "type" instance according to the spec
var BigintType = {
size: ref.sizeof.int64
, indirection: 1
, get: function (buffer, offset) {
// return a bigint instance from the buffer
return bigint.fromBuffer(buffer)
}
, set: function (buffer, offset, value) {
// 'value' would be a bigint instance
var val = value.toString()
return ref.writeInt64(buffer, offset || 0, val)
}
}
// now we can create instances of the type from existing buffers.
// "buf" is some Buffer instance returned from some external data
// source, which should contain "bigint" binary data.
buf.type = BigintType
// and now you can create "bigint" instances using this generic "types" API
var val = buf.deref()
.add('1234')
.sqrt()
.shiftLeft(5)
构建文件
安装非依赖性 :
$ npm install
生成文件 :
$ npm run docs
不兼容的软件包
这个 ref-struct-napi 财务报告和审定财务报表
ref-array-napi 软件包
拥有与本模块相容的名字.
他们不是,如果你使用,你的应用程序会遇到崩溃
他们与 ref-napi。 。 。 .
使用 ref-struct-di
或者说 ref-array-di 换句话说.
许可证
(麻省理工学院的执照)
版权 (c) 2012 Nathan Rajlich <[email protected]> 版权 (c) 2017 Anna Henningsen <[email protected]>(N-API端口)
特此免费准许任何人获得 该软件和相关文件文件的副本(第2条) “软件”,在软件中不受限制地处理,包括 不限制使用、复制、修改、合并、出版、, 软件的分发、分版和/或销售,以及 允许获得软件的人这样做,但须符合下列条件: 下述条件:
上述版权通知和本许可通知应为: 列入软件的所有副本或大部分.
软件是提供的"是", 没有任何的警告, ,包括但不受限制的 紧迫性,特别是目的和非目的的证明. 绝对不能让警察或警察 (B) 合同行动、合同或其他责任, 产生、退出或与 软件或软件的使用或其他交易.