All Projects → leizongmin → node-lei-proto

leizongmin / node-lei-proto

Licence: MIT License
简单的Buffer编码/解析模块

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to node-lei-proto

StringConvert
A simple C++11 based helper for converting string between a various charset
Stars: ✭ 16 (+14.29%)
Mutual labels:  encode, decode
Luapbintf
Binding Protobuf 3 to Lua 5.3
Stars: ✭ 122 (+771.43%)
Mutual labels:  protobuf, buffer
He
A robust HTML entity encoder/decoder written in JavaScript.
Stars: ✭ 2,973 (+21135.71%)
Mutual labels:  encode, decode
alawmulaw
A-Law and mu-Law codecs in JavaScript.
Stars: ✭ 22 (+57.14%)
Mutual labels:  encode, decode
morse
Morse Code Library in Go
Stars: ✭ 75 (+435.71%)
Mutual labels:  encode, decode
Silk V3 Decoder
kn007's blog
Stars: ✭ 1,832 (+12985.71%)
Mutual labels:  encode, decode
Androidcamera
🔥🔥🔥自定义Android相机(仿抖音 TikTok),其中功能包括视频人脸识别贴纸,美颜,分段录制,视频裁剪,视频帧处理,获取视频关键帧,视频旋转,添加滤镜,添加水印,合成Gif到视频,文字转视频,图片转视频,音视频合成,音频变声处理,SoundTouch,Fmod音频处理。 Android camera(imitation Tik Tok), which includes video editor,audio editor,video face recognition stickers, segment recording,video cropping, video frame processing, get the first video frame, key frame, v…
Stars: ✭ 2,112 (+14985.71%)
Mutual labels:  encode, decode
time decode
A timestamp and date decoder written for python 3
Stars: ✭ 24 (+71.43%)
Mutual labels:  encode, decode
janus-gateway-live
RTMP edge speed with janus-gateway
Stars: ✭ 38 (+171.43%)
Mutual labels:  encode, decode
fastproto
FastProto is a binary data processing tool written in Java.
Stars: ✭ 65 (+364.29%)
Mutual labels:  encode, decode
libutf8
A whatwg compliant UTF8 encoding and decoding library
Stars: ✭ 32 (+128.57%)
Mutual labels:  encode, decode
FireSnapshot
A useful Firebase-Cloud-Firestore Wrapper with Codable.
Stars: ✭ 56 (+300%)
Mutual labels:  encode, decode
crypthash-net
CryptHash.NET is a .NET multi-target library to encrypt/decrypt/hash/encode/decode strings and files, with an optional .NET Core multiplatform console utility.
Stars: ✭ 33 (+135.71%)
Mutual labels:  encode, decode
WWW2020-grec
Future Data Helps Training: Modeling Future Contexts for Session-based Recommendation
Stars: ✭ 17 (+21.43%)
Mutual labels:  encode
ppx deriving protobuf
A Protocol Buffers codec generator for OCaml
Stars: ✭ 76 (+442.86%)
Mutual labels:  protobuf
rails-microservices-book
A guide to building distributed Ruby on Rails applications using Protocol Buffers, NATS and RabbitMQ
Stars: ✭ 23 (+64.29%)
Mutual labels:  protobuf
pinus-parse-interface
parse interface to pinus-protobuf JSON
Stars: ✭ 25 (+78.57%)
Mutual labels:  protobuf
fieldmask-utils
Protobuf Field Mask Go utils
Stars: ✭ 127 (+807.14%)
Mutual labels:  protobuf
nimpb
Protocol Buffers for Nim
Stars: ✭ 29 (+107.14%)
Mutual labels:  protobuf
vtprotobuf
A Protocol Buffers compiler that generates optimized marshaling & unmarshaling Go code for ProtoBuf APIv2
Stars: ✭ 418 (+2885.71%)
Mutual labels:  protobuf

lei-proto

简单的Buffer编码/解析模块

安装

npm install lei-proto

使用

const parseProto = require('lei-proto');

const p = parseProto([
  ['a', 'uint', 1],
  ['b', 'int', 1],
  ['c', 'float'],
  ['d', 'double'],
  ['e', 'string', 1],
  ['f', 'buffer', 1]
]);

const b = p.encode(1, 2, 3.3, 4.4, 'a', new Buffer('b'));
// 或者
// const b = p.encodeEx({a: 1, b: 2, c: 3.3, d: 4.4, e: 'a', f: new Buffer('b')});
const c = p.decode(b);
console.log(b);
// => <Buffer 01 02 40 53 33 33 40 11 99 99 99 99 99 9a 61 62>
console.log(c);
// => { a: 1, b: 2, c: 3.299999952316284, d: 4.4, e: 'a', f: <Buffer 62> }

规则:['名称', '数据类型', 长度, '字节顺序BE/LE']

支持的数据类型:

  • uint 需要指定长度,字节顺序默认BE
  • int 需要指定长度,字节顺序默认BE
  • float 长度为4
  • double 长度为4
  • string 需要指定长度,当其为最后一项时可省略长度(表示不定长)
  • buffer 需要指定长度,当其为最后一项时可省略长度(表示不定长)

具体使用方法参考单元测试。

性能提示

  • Buffer.from(str) 接口比较慢,所以最后一项尽量不要使用不定长的 stringbuffer
  • 如果可能,尽量使用 buffer 而不使用 string 类型
  • 尽量缓存 Buffer 对象,避免多次创建

The MIT License

The MIT License (MIT)

Copyright (c) 2015-2018 Zongmin Lei <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].