Last active
July 3, 2019 02:16
-
-
Save tony612/92e0d95f1ba69274a69af132cbd030f9 to your computer and use it in GitHub Desktop.
Test node protobuf float
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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