Skip to content

Instantly share code, notes, and snippets.

@tony612
Last active July 3, 2019 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tony612/92e0d95f1ba69274a69af132cbd030f9 to your computer and use it in GitHub Desktop.
Save tony612/92e0d95f1ba69274a69af132cbd030f9 to your computer and use it in GitHub Desktop.
Test node protobuf float
var protobuf = require('protobufjs');
protobuf.load("test.proto", function (err, root) {
if (err)
throw err;
var Message = root.lookupType("test.Message");
var payload = { foo1: 123.0, foo2: 123.5 };
var errMsg = Message.verify(payload);
if (errMsg)
throw Error(errMsg);
var message = Message.create(payload);
var buffer = Message.encode(message).finish();
var message = Message.decode(buffer);
console.log(message);
// Message { foo1: 123, foo2: 123.5 }
});
syntax = "proto3";
package test;
message Message {
float foo1 = 1;
float foo2 = 2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment