Skip to content

Commit

Permalink
Fixed serialization order of sfixed64, fixes #536
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Dec 10, 2016
1 parent 67449db commit 66be598
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 7 deletions.
4 changes: 2 additions & 2 deletions dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/protobuf.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ WriterPrototype.fixed64 = function write_fixed64(value) {
*/
WriterPrototype.sfixed64 = function write_sfixed64(value) {
var bits = LongBits.from(value).zzEncode();
return this.push(writeFixed32, 4, bits.hi).push(writeFixed32, 4, bits.lo);
return this.push(writeFixed32, 4, bits.lo).push(writeFixed32, 4, bits.hi);
};

var writeFloat = typeof Float32Array !== 'undefined'
Expand Down
38 changes: 38 additions & 0 deletions tests/sfixed64-grpc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var tape = require("tape");

var protobuf = require("..");

tape.test("sfixed64 for grpc", function(test) {

var root = protobuf.Root.fromJSON({
nested: {
test: {
nested: {
Test: {
fields: {
int_64: {
type: 'sfixed64',
id: 1
}
}
}
}
}
}
});

var Test = root.lookup("test.Test");

var buffer = Test.encode({
int_64: '-9095674951825889465'
}).finish();

test.equal(buffer.length, 9, "should encode a total of 9 bytes");
test.equal(buffer[0], 9, "should encode id 1, wireType 1");

var decoded = Test.decode(buffer);
test.ok(decoded.int_64 == '-9095674951825889465', "should decode back the original value");

test.end();

});

0 comments on commit 66be598

Please sign in to comment.