protobuf

Protocol Buffers

1
npm -i -g protobufjs
1
pbjs -t json file1.proto file2.proto > bundle.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const protobuf = require('protobufjs');
const root = protobuf.Root.fromJSON(require('bundle.json'));

const AwesomeMessage = root.lookup('awesomepackage.AwesomeMessage');
var message = {
id: 1,
name: '类型1',
status: 'on',
type: 'type'
};

var buffer = AwesomeMessage.encode(message).finish();

message = AwesomeMessage.decode(buffer);
本站采用「署名 4.0 国际」进行许可。