Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bobvanderlinden/machinetalk-protobuf-node
https://github.com/bobvanderlinden/machinetalk-protobuf-node
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/bobvanderlinden/machinetalk-protobuf-node
- Owner: bobvanderlinden
- License: mit
- Created: 2015-09-13T13:19:55.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-09-13T13:47:23.000Z (about 9 years ago)
- Last Synced: 2024-04-15T00:15:40.264Z (7 months ago)
- Language: Protocol Buffer
- Size: 219 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
machinetalk-protobuf-node
=========================Protobuf declarations of Machinetalk for Node.js.
This project is the result of converting the protobuf declarations of [machinetalk-protobuf](https://github.com/machinekit/machinetalk-protobuf) to CommonJS files using [ProtoBuf.JS](https://github.com/dcodeIO/ProtoBuf.js).
This means this project uses the same API as ProtoBuf.JS.
## Installation
```
npm install machinetalk-protobuf
```## Usage
### Encoding a message container
```js
var machinetalkProtobuf = require('machinetalk-protobuf');// Define the message we want to encode.
var messageContainer = {
type: machinetalkProtobuf.message.ContainerType.MT_PING
};// Encode the message.
var encodedMessageContainer = machinetalkProtobuf.message.Container.encode(messageContainer);// Strip off excess bytes from the resulting buffer.
var encodedBuffer = encodedMessageContainer.buffer.slice(encodedMessageContainer.offset, encodedMessageContainer.limit);// Print the buffer.
console.log(encodedBuffer);```
This results in:
``````
### Decoding a message container
```js
var machinetalkProtobuf = require('../index.js');var encodedBuffer = new Buffer([0x08, 0xd2, 0x01]);
// Decode the message.
var decodedMessageContainer = machinetalkProtobuf.message.Container.decode(encodedBuffer);// decodedMessageContainer.type === machinetalkProtobuf.message.ContainerType.MT_PING
```