machinetalk-protobuf

1.0.1 • Public • Published

machinetalk-protobuf-node

Protobuf declarations of Machinetalk for Node.js.

This project is the result of converting the protobuf declarations of machinetalk-protobuf to CommonJS files using ProtoBuf.JS.

This means this project uses the same API as ProtoBuf.JS.

Installation

npm install machinetalk-protobuf

Usage

Encoding a message container

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:

<Buffer 08 d2 01>

Decoding a message container

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

Package Sidebar

Install

npm i machinetalk-protobuf

Weekly Downloads

2

Version

1.0.1

License

MIT

Last publish

Collaborators

  • bobvanderlinden