@ -44,9 +44,20 @@ var _ = require('lodash');
/ * *
/ * *
* Get a function that deserializes a specific type of protobuf .
* Get a function that deserializes a specific type of protobuf .
* @ param { function ( ) } cls The constructor of the message type to deserialize
* @ param { function ( ) } cls The constructor of the message type to deserialize
* @ param { bool = } binaryAsBase64 Deserialize bytes fields as base64 strings
* instead of Buffers . Defaults to false
* @ param { bool = } longsAsStrings Deserialize long values as strings instead of
* objects . Defaults to true
* @ return { function ( Buffer ) : cls } The deserialization function
* @ return { function ( Buffer ) : cls } The deserialization function
* /
* /
exports . deserializeCls = function deserializeCls ( cls ) {
exports . deserializeCls = function deserializeCls ( cls , binaryAsBase64 ,
longsAsStrings ) {
if ( binaryAsBase64 === undefined || binaryAsBase64 === null ) {
binaryAsBase64 = false ;
}
if ( longsAsStrings === undefined || longsAsStrings === null ) {
longsAsStrings = true ;
}
/ * *
/ * *
* Deserialize a buffer to a message object
* Deserialize a buffer to a message object
* @ param { Buffer } arg _buf The buffer to deserialize
* @ param { Buffer } arg _buf The buffer to deserialize
@ -55,7 +66,7 @@ exports.deserializeCls = function deserializeCls(cls) {
return function deserialize ( arg _buf ) {
return function deserialize ( arg _buf ) {
// Convert to a native object with binary fields as Buffers (first argument)
// Convert to a native object with binary fields as Buffers (first argument)
// and longs as strings (second argument)
// and longs as strings (second argument)
return cls . decode ( arg _buf ) . toRaw ( false , true ) ;
return cls . decode ( arg _buf ) . toRaw ( binaryAsBase64 , longsAsStrings ) ;
} ;
} ;
} ;
} ;
@ -119,19 +130,28 @@ exports.wrapIgnoreNull = function wrapIgnoreNull(func) {
/ * *
/ * *
* Return a map from method names to method attributes for the service .
* Return a map from method names to method attributes for the service .
* @ param { ProtoBuf . Reflect . Service } service The service to get attributes for
* @ param { ProtoBuf . Reflect . Service } service The service to get attributes for
* @ param { Object = } options Options to apply to these attributes
* @ return { Object } The attributes map
* @ return { Object } The attributes map
* /
* /
exports . getProtobufServiceAttrs = function getProtobufServiceAttrs ( service ) {
exports . getProtobufServiceAttrs = function getProtobufServiceAttrs ( service ,
options ) {
var prefix = '/' + fullyQualifiedName ( service ) + '/' ;
var prefix = '/' + fullyQualifiedName ( service ) + '/' ;
var binaryAsBase64 , longsAsStrings ;
if ( options ) {
binaryAsBase64 = options . binaryAsBase64 ;
longsAsStrings = options . longsAsStrings ;
}
return _ . object ( _ . map ( service . children , function ( method ) {
return _ . object ( _ . map ( service . children , function ( method ) {
return [ _ . camelCase ( method . name ) , {
return [ _ . camelCase ( method . name ) , {
path : prefix + method . name ,
path : prefix + method . name ,
requestStream : method . requestStream ,
requestStream : method . requestStream ,
responseStream : method . responseStream ,
responseStream : method . responseStream ,
requestSerialize : serializeCls ( method . resolvedRequestType . build ( ) ) ,
requestSerialize : serializeCls ( method . resolvedRequestType . build ( ) ) ,
requestDeserialize : deserializeCls ( method . resolvedRequestType . build ( ) ) ,
requestDeserialize : deserializeCls ( method . resolvedRequestType . build ( ) ,
binaryAsBase64 , longsAsStrings ) ,
responseSerialize : serializeCls ( method . resolvedResponseType . build ( ) ) ,
responseSerialize : serializeCls ( method . resolvedResponseType . build ( ) ) ,
responseDeserialize : deserializeCls ( method . resolvedResponseType . build ( ) )
responseDeserialize : deserializeCls ( method . resolvedResponseType . build ( ) ,
binaryAsBase64 , longsAsStrings )
} ] ;
} ] ;
} ) ) ;
} ) ) ;
} ;
} ;