npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ByteBuffer

v0.3.0

Published

pack or unpack a byte array

Downloads

25

Readme

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

推荐结合ExBuffer来实现网络协议:https://github.com/play175/ExBuffer

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
                       .byteArray([65,66,67,68,69],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
                    .byteArray(null,5)//字节数组,不足字节补0x00
                    .unpack();//结尾调用解包方法

console.log(arr);


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

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

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

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

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

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

install

npm install ByteBuffer -g