# wspb

> protobuf and websocket

Latest version **1.0.25** (published 2023-10-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install wspb
pnpm add wspb
yarn add wspb
bun add wspb
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.25 |
| Published | 2023-10-23 |
| First published | 2022-09-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 1.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | xigalto |
| Maintainers | xigal |
| Keywords | protobuf, websocket |

## Links

- npm: https://www.npmjs.com/package/wspb
- Repository: https://e.coding.net/uc52/npm/wspb
- npm.io page: https://npm.io/package/wspb

## Dependencies (4)

- [long](https://npm.io/package/long.md) ^5.2.0
- [pako](https://npm.io/package/pako.md) ^2.0.4
- [buffer](https://npm.io/package/buffer.md) ^6.0.3
- [protobufjs](https://npm.io/package/protobufjs.md) ^7.1.1

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.25 (latest) — 2023-10-23
- 1.0.24 — 2023-10-23
- 1.0.23 — 2023-10-21
- 1.0.22 — 2023-10-20
- 1.0.21 — 2023-10-11
- 1.0.20 — 2023-10-08
- 1.0.19 — 2023-10-08
- 1.0.18 — 2023-10-02
- 1.0.17 — 2023-10-02
- 1.0.16 — 2023-10-02
- 1.0.15 — 2023-10-02
- 1.0.14 — 2023-10-02
- 1.0.13 — 2023-10-01
- 1.0.12 — 2023-10-01
- 1.0.11 — 2023-10-01
- … 11 more at https://npm.io/package/wspb/versions

## 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)
}


客户端
<script src="wspb.min.js"></script>
<script>
    let pb = new igame.ProtoManager()
    // 客户端的协议会被服务端自动同步，初始化为任何支持的类型都可以
    pb.initialzie(null,{coder:'pb'})

    // package
    let bytes = pb.package('prototypename',{...});

    // unpackage
    try{
        let data = pb.unpackage(bytes)
    }catch(e){
        console.error('unpackage error',e)
    }
</script>


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);

---
_Source: https://npm.io/package/wspb · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
