1.0.1 • Published 5 years ago

npm-tlv-parse v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

egg-thing-parser

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-thing-parser --save

Usage

// {app_root}/config/plugin.js
exports.thingParser = {
  enable: true,
  package: 'egg-thing-parser'
}

Configuration

// {app_root}/config/config.default.js
exports.thingParser = {}

see config/config.default.js for more detail.

Example

数据解析

// TLV数据解析:app.thing.tlv.parser.parse(buffer)
// 输入:Buffer
// 输出:
{
  version: "1.0.0",
  time: "xxxxxx", // 时间戳
  data: {
    id:1, // 4字节无符号整数
    method: "notify", // 枚举值 - ['read', 'write', 'notify', 'reset', 'recovery', 'resp']
    code: 3;
    groupId: 3, // 组合功能点Id
    params: {
      3: {
        value: {
          1: {
            value: "xxxx",
            type: "boolean", // 数据类型 - ['boolean', 'enum', 'integer', 'float', 'buffer', 'string', 'exception']
            resource: "common", // 资源类型 - ['common', 'static', 'combine']
            message: "property" // 消息类型 - ['property', 'device', 'event', 'system']
          }
        },
        type: "buffer", // 数据类型 - ['boolean', 'enum', 'integer', 'float', 'buffer', 'string', 'exception']
        resource: "combine", // 资源类型 - ['common', 'static', 'combine']
        message: "property" // 消息类型 - ['property', 'device', 'event', 'system']
      },
      2: {
        value: "xxxx",
        type: "boolean", // 数据类型 - ['boolean', 'enum', 'integer', 'float', 'buffer', 'string', 'exception']
        resource: "static", // 资源类型 - ['common', 'static', 'combine']
        message: "property" // 消息类型 - ['property', 'device', 'event', 'system']
      }
    }
  }
}

数据封装

// TLV数据封装: app.thing.tlv.packager.package(json)
// 输出:Buffer
// 输入:
{
  version: '1.0.0', // 版本号:1.0.0
  method: 'read', // 操作码 [ 'read', 'write', 'notify', 'reset', 'recovery' ]
  groupId: 123, // 组合功能点值
  data: [{
      resourceId: 2222, // 普通功能点值
      valueType: 'string', // 数据类型 [ 'boolean', 'enum', 'integer', 'float', 'buffer', 'exception', 'string' ]
      value: 'asdf'
    } // 普通功能点数据
  ]
  // required: [ 'version', 'method', 'data' ],
}

Questions & Suggestions

Please open an issue here.

License

MIT