wspb
v1.0.25
Published
protobuf and websocket
Downloads
11
Readme
protobuf兼容
protobufjs https://protobufjs.github.io/protobuf.js/ buffer https://github.com/feross/buffer pako https://github.com/nodeca/pako#readme
安装 npm i wspb
使用
服务端: const {ProtoManager} = require('wspb') let pb = new ProtoManager() pb.initialzie('google proto file text',{coder:'pb'})
// package let bytes = pb.package('prototypename',{...});
// unpackage try{ let data = pb.unpackage(bytes) }catch(e){ console.error('unpackage error',e) }
客户端
const {ProtoManager} = require('wspb')
方法一,使用协议解码或者编码消息 let pb = new ProtoManager() pb.initialzie('',{coder:'ipb'})
// 打包消息 let bytes = pb.package('prototypename',{...});
// 解包消息 try{ let data = pb.unpackage(bytes) }catch(e){ console.error('unpackage error',e) }
方法二、使用socket
const {Socket} = require('wspb'); let c = new Socket(); c.on('prototypename',(name,data)=>{ }); c.connect('ws://xxxxx'); c.send('prototypename',data);