# pomelo-flatbuffer

> flatbuffer for pomelo

Latest version **2.0.5** (published 2022-02-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install pomelo-flatbuffer
pnpm add pomelo-flatbuffer
yarn add pomelo-flatbuffer
bun add pomelo-flatbuffer
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.5 |
| Published | 2022-02-14 |
| First published | 2017-06-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 1 |
| Unpacked size | 99.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Maintainers | frank198 |
| Keywords | pomelo, flatbuffer, pomelo flatbuffer, protobuff |

## Links

- npm: https://www.npmjs.com/package/pomelo-flatbuffer
- Repository: https://github.com/frank198/pomelo-flatbuffer
- Homepage: https://github.com/frank198/pomelo-flatbuffer#readme
- Issues: https://github.com/frank198/pomelo-flatbuffer/issues
- npm.io page: https://npm.io/package/pomelo-flatbuffer

## Dependencies (1)

- [flatbuffers](https://npm.io/package/flatbuffers.md) ^2.x

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 2.0.5 (latest) — 2022-02-14
- 2.1.1 — 2022-02-10
- 2.1.0 — 2022-02-10
- 2.0.1 — 2021-10-14
- 2.0.0 — 2019-01-15
- 1.2.0 — 2017-12-07
- 1.1.0 — 2017-10-25
- 1.0.2 — 2017-08-16
- 1.0.1 — 2017-08-16
- 0.0.3 — 2017-06-30
- 0.0.2 — 2017-06-29
- 0.0.1 — 2017-06-23

## README

# [FlatBuffer](https://github.com/google/flatbuffers)

# 使用说明

## pomelo 中安装与使用

### 安装
```bash
npm install pomelo-flatbuffer --save
```
### 使用
在 app.js 中添加一下脚本

```javascript
// app configuration
app.configure('development', 'gate|connector', () =>
{
	app.use(flatBuffer, {
		serverProtos : '/serverProtos.json',
        clientProtos : '/clientProtos.json',
        serverFBPath : '/serverBFBS/',
        clientFBPath : '/clientBFBS/'
	});
	app.set('connectorConfig',
		{
			connector   : pomelo.connectors.hybridconnector,
			// timeout:10,
			handshake   : handshake,
			heartbeat   : 5,
			useProtobuf : false,
			setNoDelay  : true,
			// disconnectOnTimeOut : true
			// ,distinctHost:true
		});
});
```

#### 参数说明
- serverProtos dafault: config/serverProtos.json  服务器发送到客户端的消息
- clientProtos default: config/clientProtos.json  客户端发送到服务器的消息
- serverFBPath default: config/serverBFBS/        flatbuffer 序列化服务器发送的数据（bfbs 格式文件）
- clientFBPath default: config/clientBFBS/        flatbuffer 反序列化服务器接受的数据（bfbs 格式文件）


## bfbs 文件生成
```sh
# cd tests
# flatc -o bfbsData  -b --schema flatSchema/*.fbs
```



## 实例使用

### 文件夹说明

- serverBFBS 服务器发送到客户端的消息， 和 serverProtos.json 一致
    - .json route与class对照表
    - .bfbs flatc生成的数据
  
- clientBFBS 客户端发送到服务器的消息， 和 clientProtos.json 一致
    - .json route与class对照表
    - .bfbs flatc生成的数据
    
- flatSchema flat文件的消息格式 

```javascript
const FlatBuffer = require('../lib/components/flatbuffer');
const flatBufferInstance = FlatBuffer(app, {
	serverProtos : '/serverProtos.json',
	clientProtos : '/clientProtos.json',
	serverFBPath : '/serverBFBS/',
	clientFBPath : '/clientBFBS/'
});

FlatBuffer.start(()=>{
    // 序列化数据
    const data = flatBufferInstance.encode('ItemDistances', exampleData.ItemDistances);
    // 反序列化数据
    flatBufferInstance.decode('ItemDistances', data);
})
```

### 测试

```bash
node ./test/PomeloFlatBuffer.js 
node ./test/FlatBufferTest.js
```

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