2.0.5 • Published 2 years ago

pomelo-flatbuffer v2.0.5

Weekly downloads
30
License
MIT
Repository
github
Last release
2 years ago

FlatBuffer

使用说明

pomelo 中安装与使用

安装

npm install pomelo-flatbuffer --save

使用

在 app.js 中添加一下脚本

// 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 文件生成

# 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文件的消息格式
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);
})

测试

node ./test/PomeloFlatBuffer.js 
node ./test/FlatBufferTest.js
2.1.1

2 years ago

2.0.5

2 years ago

2.1.0

2 years ago

2.0.1

3 years ago

2.0.0

5 years ago

1.2.0

6 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago