Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yuanyu90221/node_protobuf_demo
https://github.com/yuanyu90221/node_protobuf_demo
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/yuanyu90221/node_protobuf_demo
- Owner: yuanyu90221
- Created: 2020-02-15T08:58:18.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-06-17T01:27:54.000Z (7 months ago)
- Last Synced: 2024-06-17T02:38:46.696Z (7 months ago)
- Language: JavaScript
- Size: 147 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nodejs with protobuf demo
## introduction
use node_module protobufjs to process protobuf protocol data
## protobuf format data
```protobuf==
package cover;message helloworld {
message helloCoverReq {
required string name = 1;
}message helloCoverRsp {
required int32 retcode = 1;
optional string reply = 2;
}
}
```## use protobufjs to load proto and decode, encode data
```javascript==
const protobuf = require('protobufjs');
const builder = protobuf.loadSync("./protos/cover.helloworld.proto");
const HelloCoverReq = builder.lookupType("cover.helloworld.helloCoverReq");
const HelloCoverRsp = builder.lookupType("cover.helloworld.helloCoverRsp");
// create object
const hCRspObj = HelloCoverRsp.create({
retcode: 0,
reply: 'reply from udp server'
});
// encode to Buffer
const msg = HelloCoverRsp.encode(hCRspObj).finish();// decode from buffer
HelloCoverReq.decode(message)
```