@ -1,6 +1,6 @@
/ *
*
* Copyright 2015 , Google Inc .
* Copyright 2015 - 2016 , Google Inc .
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
@ -42,7 +42,7 @@ var ProtoBuf = require('protobufjs');
var messages _proto = ProtoBuf . loadProtoFile (
_ _dirname + '/test_messages.proto' ) . build ( ) ;
describe ( 'Proto message serialize and deserialize' , function ( ) {
describe ( 'Proto message long int serialize and deserialize' , function ( ) {
var longSerialize = common . serializeCls ( messages _proto . LongValues ) ;
var longDeserialize = common . deserializeCls ( messages _proto . LongValues ) ;
var pos _value = '314159265358979' ;
@ -87,4 +87,52 @@ describe('Proto message serialize and deserialize', function() {
assert . strictEqual ( longDeserialize ( serialized ) . sfixed _64 . toString ( ) ,
neg _value ) ;
} ) ;
it ( 'should deserialize as a number with the right option set' , function ( ) {
var longNumDeserialize = common . deserializeCls ( messages _proto . LongValues ,
false , false ) ;
var serialized = longSerialize ( { int _64 : pos _value } ) ;
assert . strictEqual ( typeof longDeserialize ( serialized ) . int _64 , 'string' ) ;
/ * W i t h t h e l o n g s A s S t r i n g s o p t i o n d i s a b l e d , l o n g v a l u e s a r e r e p r e s e n t e d a s
* objects with 3 keys : low , high , and unsigned * /
assert . strictEqual ( typeof longNumDeserialize ( serialized ) . int _64 , 'object' ) ;
} ) ;
} ) ;
describe ( 'Proto message bytes serialize and deserialize' , function ( ) {
var sequenceSerialize = common . serializeCls ( messages _proto . SequenceValues ) ;
var sequenceDeserialize = common . deserializeCls (
messages _proto . SequenceValues ) ;
var sequenceBase64Deserialize = common . deserializeCls (
messages _proto . SequenceValues , true ) ;
var buffer _val = new Buffer ( [ 0x69 , 0xb7 ] ) ;
var base64 _val = 'abc=' ;
it ( 'should preserve a buffer' , function ( ) {
var serialized = sequenceSerialize ( { bytes _field : buffer _val } ) ;
var deserialized = sequenceDeserialize ( serialized ) ;
assert . strictEqual ( deserialized . bytes _field . compare ( buffer _val ) , 0 ) ;
} ) ;
it ( 'should accept base64 encoded strings' , function ( ) {
var serialized = sequenceSerialize ( { bytes _field : base64 _val } ) ;
var deserialized = sequenceDeserialize ( serialized ) ;
assert . strictEqual ( deserialized . bytes _field . compare ( buffer _val ) , 0 ) ;
} ) ;
it ( 'should output base64 encoded strings with an option set' , function ( ) {
var serialized = sequenceSerialize ( { bytes _field : base64 _val } ) ;
var deserialized = sequenceBase64Deserialize ( serialized ) ;
assert . strictEqual ( deserialized . bytes _field , base64 _val ) ;
} ) ;
/ * T h e n e x t t w o t e s t s a r e s p e c i f i c t e s t s t o v e r i f y t h a t i s s u e
* https : //github.com/grpc/grpc/issues/5174 has been fixed. They are skipped
* because they will not pass until a protobuf . js release has been published
* with a fix for https : //github.com/dcodeIO/protobuf.js/issues/390 */
it . skip ( 'should serialize a repeated field as packed by default' , function ( ) {
var expected _serialize = new Buffer ( [ 0x12 , 0x01 , 0x01 , 0x0a ] ) ;
var serialized = sequenceSerialize ( { repeated _field : [ 10 ] } ) ;
assert . strictEqual ( expected _serialize . compare ( serialized ) , 0 ) ;
} ) ;
it . skip ( 'should deserialize packed or unpacked repeated' , function ( ) {
var serialized = new Buffer ( [ 0x12 , 0x01 , 0x01 , 0x0a ] ) ;
assert . doesNotThrow ( function ( ) {
sequenceDeserialize ( serialized ) ;
} ) ;
} ) ;
} ) ;