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

c-st-js

v1.0.3

Published

c-style binary data pack & unpack

Downloads

2

Readme

cstruct-js

c-style binary data pack & unpack

安装

npm install c-st-js --save

例子

(function () {
    'use strict';

    var _ = require('c-struct');
    var NetMsgHead = require('../netmsg_head.js');
    var NetMsgMsgId = require('../netmsg_msgid.js');

    module.exports = ClientVertifyReq;

    var CMD = NetMsgMsgId.ClientVertifyReqMsgID;
    var structName = 'ClientVertifyReq';
    function ClientVertifyReq() {
        this.Source = 0;
        this.UID = 0;
        this.Token = "";
    }

    var _ClientVertifyReq = new _.Schema({
        Source: _.type.uint8,
        UID: _.type.uint64,
        Token: _.type.string(32)
    });

    _.register(structName, _ClientVertifyReq);


    var proto = ClientVertifyReq.prototype;

    proto.encode = function () {
        var self = this;
        var msgbuf = _.packSync(structName, {
            Source: self.Source,
            UID: self.UID,
            Token: self.Token
        });
        return Buffer.concat([new NetMsgHead(msgbuf.length, CMD).encode(), msgbuf]);
    };

    proto.decode = function (buf) {
        var head = new NetMsgHead(0, 0);
        head.decode(buf);
        var obj = _.unpackSync(structName, buf.slice(NetMsgHead.len));
        this.Source = obj.Source;
        this.UID = obj.UID;
        this.Token = obj.Token;
    };
})();

编写目的

本项目参考了 https://github.com/majimboo/c-struct

但是 c-struct 有以下问题:

  • 有BUG,打包的数据是错误的...
  • 不能对接其他系统。主要原因,打包的string类型,不带长度信息。
  • 无法简单的fork修改。因为项目使用npm做包管理。fork修改的,不方便npm publish。

因以上原因,将基于c-struct项目代码,做如下功能:

  • 修复BUG,正确pack & unpack
  • string类型数据,打包后格式为 [string length + string data]

参考项目

https://github.com/majimboo/c-struct

TODO

  • 去除Schema,本质上Schema是多余的,存在多次定义,可以合并到一块。

  • 提供2进制数据字段

  • 提供浮点数类型