nodejs的Buffer有办法像c的结构体那样用吗
2个回答
展开全部
可以使用ref和ref-struct模块
比如想要定义下面这样的结构
struct timeval {
time_t tv_sec; /* seconds since Jan. 1, 1970 */
suseconds_t tv_usec; /* and microseconds */
};
如果在nodejs里面用ref和ref-struct模块来定义,就按下面这种写法
var ref = require('ref');
var StructType = require('ref-struct');
// define the time types
var time_t = ref.types.long;
var suseconds_t = ref.types.long;
// define the "timeval" struct type
var timeval = StructType({
tv_sec: time_t,
tv_usec: suseconds_t
});
// now we can create instances of it
var tv = new timeval;
上面这些一般是配合ffi模块一起用的,
详情参考:
https://github.com/TooTallNate/ref-struct#readme
https://github.com/TooTallNate/ref#readme
http://github.com/node-ffi/node-ffi
比如想要定义下面这样的结构
struct timeval {
time_t tv_sec; /* seconds since Jan. 1, 1970 */
suseconds_t tv_usec; /* and microseconds */
};
如果在nodejs里面用ref和ref-struct模块来定义,就按下面这种写法
var ref = require('ref');
var StructType = require('ref-struct');
// define the time types
var time_t = ref.types.long;
var suseconds_t = ref.types.long;
// define the "timeval" struct type
var timeval = StructType({
tv_sec: time_t,
tv_usec: suseconds_t
});
// now we can create instances of it
var tv = new timeval;
上面这些一般是配合ffi模块一起用的,
详情参考:
https://github.com/TooTallNate/ref-struct#readme
https://github.com/TooTallNate/ref#readme
http://github.com/node-ffi/node-ffi
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2016-12-10
展开全部
Buffer是流,没有key/value结构,JS的key/value数据结构是object。
var u = {
name: "党志明",
message: "..."
}
u.name
u.name = ..
var u = {
name: "党志明",
message: "..."
}
u.name
u.name = ..
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询