Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ByteBuffer

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ByteBuffer

pack or unpack a byte array

  • 0.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-87.5%
Maintainers
1
Weekly downloads
 
Created
Source

nodejs版本的ByteBuffer和C++通信的利器!

var ByteBuffer = require('./ByteBuffer');

/*************************基本操作****************************/

//压包操作
var sbuf = new ByteBuffer();
var buffer = sbuf.string('abc123你好')//变长字符串,前两个字节表示长度
                       .int32(-999).uint32(999).float(-0.5)
                       .int64(9999999).double(-0.000005).short(32767).ushort(65535)
                       .byte(255)
                       .vstring('abcd',5)//定长字符串,不足的字节补0x00
                       .pack();//结尾调用打包方法

console.log(buffer);

//解包操作
var rbuf = new ByteBuffer(buffer);
//解包出来是一个数组
var arr = rbuf.string()//变长字符串,前两个字节表示长度
                    .int32().uint32().float()
                    .int64().double().short().ushort()
                    .byte()
                    .vstring(null,5)//定长字符串,不足的字节补0x00
                    .unpack();//结尾调用解包方法

console.log(arr);


/*************************更多操作****************************/

//指定字符编码(默认:utf8):utf8/ascii/
var sbuf = new ByteBuffer().encoding('ascii');

//指定字节序(默认:LittleEndian)
var sbuf = new ByteBuffer().bigEndian();

//指定数据在二进制的初始位置 默认是0
var sbuf = new ByteBuffer(buffer,2);

//插入数据到指定位置
var sbuf = new ByteBuffer();
sbuf.int32(9999,0);//把这个int32数据插入到ByteBuffer的第一个位置

//在打包的时候在开始位置插入一个short型表示包长(通信层中的包头)
var buffer = sbuf.pack(true);

install

npm install ByteBuffer -g

Keywords

FAQs

Package last updated on 24 Jul 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc