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 = ; // Define the message we want to encode.var messageContainer = type: machinetalkProtobufmessageContainerTypeMT_PING; // Encode the message.var encodedMessageContainer = machinetalkProtobufmessageContainer; // Strip off excess bytes from the resulting buffer.var encodedBuffer = encodedMessageContainerbuffer; // Print the buffer.console;
This results in:
<Buffer 08 d2 01>
Decoding a message container
var machinetalkProtobuf = ; var encodedBuffer = 0x08 0xd2 0x01; // Decode the message.var decodedMessageContainer = machinetalkProtobufmessageContainer; // decodedMessageContainer.type === machinetalkProtobuf.message.ContainerType.MT_PING