Last active
February 29, 2020 11:32
-
-
Save Vivek205/88493682a897cb95935dfd81e3378683 to your computer and use it in GitHub Desktop.
Generated Stub Files
This file contains 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
/** | |
* @fileoverview | |
* @enhanceable | |
* @suppress {messageConventions} JS Compiler reports an error if a variable or | |
* field starts with 'MSG_' and isn't a translatable message. | |
* @public | |
*/ | |
// GENERATED CODE -- DO NOT EDIT! | |
/* eslint-disable */ | |
var jspb = require('google-protobuf'); | |
var goog = jspb; | |
var global = Function('return this')(); | |
goog.exportSymbol('proto.com.book.Book', null, global); | |
goog.exportSymbol('proto.com.book.BookStore', null, global); | |
goog.exportSymbol('proto.com.book.EnumSample', null, global); | |
goog.exportSymbol('proto.com.book.GetBookRequest', null, global); | |
goog.exportSymbol('proto.com.book.GetBookViaAuthor', null, global); | |
/** | |
* Generated by JsPbCodeGenerator. | |
* @param {Array=} opt_data Optional initial data array, typically from a | |
* server response, or constructed directly in Javascript. The array is used | |
* in place and becomes part of the constructed object. It is not cloned. | |
* If no data is provided, the constructed object will be empty, but still | |
* valid. | |
* @extends {jspb.Message} | |
* @constructor | |
*/ | |
proto.com.book.Book = function(opt_data) { | |
jspb.Message.initialize(this, opt_data, 0, -1, null, null); | |
}; | |
goog.inherits(proto.com.book.Book, jspb.Message); | |
if (goog.DEBUG && !COMPILED) { | |
proto.com.book.Book.displayName = 'proto.com.book.Book'; | |
} | |
if (jspb.Message.GENERATE_TO_OBJECT) { | |
/** | |
* Creates an object representation of this proto suitable for use in Soy templates. | |
* Field names that are reserved in JavaScript and will be renamed to pb_name. | |
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default. | |
* For the list of reserved names please see: | |
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. | |
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance | |
* for transitional soy proto support: http://goto/soy-param-migration | |
* @return {!Object} | |
*/ | |
proto.com.book.Book.prototype.toObject = function(opt_includeInstance) { | |
return proto.com.book.Book.toObject(opt_includeInstance, this); | |
}; | |
/** | |
* Static version of the {@see toObject} method. | |
* @param {boolean|undefined} includeInstance Whether to include the JSPB | |
* instance for transitional soy proto support: | |
* http://goto/soy-param-migration | |
* @param {!proto.com.book.Book} msg The msg instance to transform. | |
* @return {!Object} | |
* @suppress {unusedLocalVariables} f is only used for nested messages | |
*/ | |
proto.com.book.Book.toObject = function(includeInstance, msg) { | |
var f, obj = { | |
isbn: jspb.Message.getFieldWithDefault(msg, 1, 0), | |
title: jspb.Message.getFieldWithDefault(msg, 2, ""), | |
author: jspb.Message.getFieldWithDefault(msg, 3, "") | |
}; | |
if (includeInstance) { | |
obj.$jspbMessageInstance = msg; | |
} | |
return obj; | |
}; | |
} | |
/** | |
* Deserializes binary data (in protobuf wire format). | |
* @param {jspb.ByteSource} bytes The bytes to deserialize. | |
* @return {!proto.com.book.Book} | |
*/ | |
proto.com.book.Book.deserializeBinary = function(bytes) { | |
var reader = new jspb.BinaryReader(bytes); | |
var msg = new proto.com.book.Book; | |
return proto.com.book.Book.deserializeBinaryFromReader(msg, reader); | |
}; | |
/** | |
* Deserializes binary data (in protobuf wire format) from the | |
* given reader into the given message object. | |
* @param {!proto.com.book.Book} msg The message object to deserialize into. | |
* @param {!jspb.BinaryReader} reader The BinaryReader to use. | |
* @return {!proto.com.book.Book} | |
*/ | |
proto.com.book.Book.deserializeBinaryFromReader = function(msg, reader) { | |
while (reader.nextField()) { | |
if (reader.isEndGroup()) { | |
break; | |
} | |
var field = reader.getFieldNumber(); | |
switch (field) { | |
case 1: | |
var value = /** @type {number} */ (reader.readInt64()); | |
msg.setIsbn(value); | |
break; | |
case 2: | |
var value = /** @type {string} */ (reader.readString()); | |
msg.setTitle(value); | |
break; | |
case 3: | |
var value = /** @type {string} */ (reader.readString()); | |
msg.setAuthor(value); | |
break; | |
default: | |
reader.skipField(); | |
break; | |
} | |
} | |
return msg; | |
}; | |
/** | |
* Serializes the message to binary data (in protobuf wire format). | |
* @return {!Uint8Array} | |
*/ | |
proto.com.book.Book.prototype.serializeBinary = function() { | |
var writer = new jspb.BinaryWriter(); | |
proto.com.book.Book.serializeBinaryToWriter(this, writer); | |
return writer.getResultBuffer(); | |
}; | |
/** | |
* Serializes the given message to binary data (in protobuf wire | |
* format), writing to the given BinaryWriter. | |
* @param {!proto.com.book.Book} message | |
* @param {!jspb.BinaryWriter} writer | |
* @suppress {unusedLocalVariables} f is only used for nested messages | |
*/ | |
proto.com.book.Book.serializeBinaryToWriter = function(message, writer) { | |
var f = undefined; | |
f = message.getIsbn(); | |
if (f !== 0) { | |
writer.writeInt64( | |
1, | |
f | |
); | |
} | |
f = message.getTitle(); | |
if (f.length > 0) { | |
writer.writeString( | |
2, | |
f | |
); | |
} | |
f = message.getAuthor(); | |
if (f.length > 0) { | |
writer.writeString( | |
3, | |
f | |
); | |
} | |
}; | |
/** | |
* optional int64 isbn = 1; | |
* @return {number} | |
*/ | |
proto.com.book.Book.prototype.getIsbn = function() { | |
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 1, 0)); | |
}; | |
/** @param {number} value */ | |
proto.com.book.Book.prototype.setIsbn = function(value) { | |
jspb.Message.setProto3IntField(this, 1, value); | |
}; | |
/** | |
* optional string title = 2; | |
* @return {string} | |
*/ | |
proto.com.book.Book.prototype.getTitle = function() { | |
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, "")); | |
}; | |
/** @param {string} value */ | |
proto.com.book.Book.prototype.setTitle = function(value) { | |
jspb.Message.setProto3StringField(this, 2, value); | |
}; | |
/** | |
* optional string author = 3; | |
* @return {string} | |
*/ | |
proto.com.book.Book.prototype.getAuthor = function() { | |
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, "")); | |
}; | |
/** @param {string} value */ | |
proto.com.book.Book.prototype.setAuthor = function(value) { | |
jspb.Message.setProto3StringField(this, 3, value); | |
}; | |
/** | |
* Generated by JsPbCodeGenerator. | |
* @param {Array=} opt_data Optional initial data array, typically from a | |
* server response, or constructed directly in Javascript. The array is used | |
* in place and becomes part of the constructed object. It is not cloned. | |
* If no data is provided, the constructed object will be empty, but still | |
* valid. | |
* @extends {jspb.Message} | |
* @constructor | |
*/ | |
proto.com.book.GetBookRequest = function(opt_data) { | |
jspb.Message.initialize(this, opt_data, 0, -1, null, null); | |
}; | |
goog.inherits(proto.com.book.GetBookRequest, jspb.Message); | |
if (goog.DEBUG && !COMPILED) { | |
proto.com.book.GetBookRequest.displayName = 'proto.com.book.GetBookRequest'; | |
} | |
if (jspb.Message.GENERATE_TO_OBJECT) { | |
/** | |
* Creates an object representation of this proto suitable for use in Soy templates. | |
* Field names that are reserved in JavaScript and will be renamed to pb_name. | |
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default. | |
* For the list of reserved names please see: | |
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. | |
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance | |
* for transitional soy proto support: http://goto/soy-param-migration | |
* @return {!Object} | |
*/ | |
proto.com.book.GetBookRequest.prototype.toObject = function(opt_includeInstance) { | |
return proto.com.book.GetBookRequest.toObject(opt_includeInstance, this); | |
}; | |
/** | |
* Static version of the {@see toObject} method. | |
* @param {boolean|undefined} includeInstance Whether to include the JSPB | |
* instance for transitional soy proto support: | |
* http://goto/soy-param-migration | |
* @param {!proto.com.book.GetBookRequest} msg The msg instance to transform. | |
* @return {!Object} | |
* @suppress {unusedLocalVariables} f is only used for nested messages | |
*/ | |
proto.com.book.GetBookRequest.toObject = function(includeInstance, msg) { | |
var f, obj = { | |
isbn: jspb.Message.getFieldWithDefault(msg, 1, 0) | |
}; | |
if (includeInstance) { | |
obj.$jspbMessageInstance = msg; | |
} | |
return obj; | |
}; | |
} | |
/** | |
* Deserializes binary data (in protobuf wire format). | |
* @param {jspb.ByteSource} bytes The bytes to deserialize. | |
* @return {!proto.com.book.GetBookRequest} | |
*/ | |
proto.com.book.GetBookRequest.deserializeBinary = function(bytes) { | |
var reader = new jspb.BinaryReader(bytes); | |
var msg = new proto.com.book.GetBookRequest; | |
return proto.com.book.GetBookRequest.deserializeBinaryFromReader(msg, reader); | |
}; | |
/** | |
* Deserializes binary data (in protobuf wire format) from the | |
* given reader into the given message object. | |
* @param {!proto.com.book.GetBookRequest} msg The message object to deserialize into. | |
* @param {!jspb.BinaryReader} reader The BinaryReader to use. | |
* @return {!proto.com.book.GetBookRequest} | |
*/ | |
proto.com.book.GetBookRequest.deserializeBinaryFromReader = function(msg, reader) { | |
while (reader.nextField()) { | |
if (reader.isEndGroup()) { | |
break; | |
} | |
var field = reader.getFieldNumber(); | |
switch (field) { | |
case 1: | |
var value = /** @type {number} */ (reader.readInt64()); | |
msg.setIsbn(value); | |
break; | |
default: | |
reader.skipField(); | |
break; | |
} | |
} | |
return msg; | |
}; | |
/** | |
* Serializes the message to binary data (in protobuf wire format). | |
* @return {!Uint8Array} | |
*/ | |
proto.com.book.GetBookRequest.prototype.serializeBinary = function() { | |
var writer = new jspb.BinaryWriter(); | |
proto.com.book.GetBookRequest.serializeBinaryToWriter(this, writer); | |
return writer.getResultBuffer(); | |
}; | |
/** | |
* Serializes the given message to binary data (in protobuf wire | |
* format), writing to the given BinaryWriter. | |
* @param {!proto.com.book.GetBookRequest} message | |
* @param {!jspb.BinaryWriter} writer | |
* @suppress {unusedLocalVariables} f is only used for nested messages | |
*/ | |
proto.com.book.GetBookRequest.serializeBinaryToWriter = function(message, writer) { | |
var f = undefined; | |
f = message.getIsbn(); | |
if (f !== 0) { | |
writer.writeInt64( | |
1, | |
f | |
); | |
} | |
}; | |
/** | |
* optional int64 isbn = 1; | |
* @return {number} | |
*/ | |
proto.com.book.GetBookRequest.prototype.getIsbn = function() { | |
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 1, 0)); | |
}; | |
/** @param {number} value */ | |
proto.com.book.GetBookRequest.prototype.setIsbn = function(value) { | |
jspb.Message.setProto3IntField(this, 1, value); | |
}; | |
/** | |
* Generated by JsPbCodeGenerator. | |
* @param {Array=} opt_data Optional initial data array, typically from a | |
* server response, or constructed directly in Javascript. The array is used | |
* in place and becomes part of the constructed object. It is not cloned. | |
* If no data is provided, the constructed object will be empty, but still | |
* valid. | |
* @extends {jspb.Message} | |
* @constructor | |
*/ | |
proto.com.book.GetBookViaAuthor = function(opt_data) { | |
jspb.Message.initialize(this, opt_data, 0, -1, null, null); | |
}; | |
goog.inherits(proto.com.book.GetBookViaAuthor, jspb.Message); | |
if (goog.DEBUG && !COMPILED) { | |
proto.com.book.GetBookViaAuthor.displayName = 'proto.com.book.GetBookViaAuthor'; | |
} | |
if (jspb.Message.GENERATE_TO_OBJECT) { | |
/** | |
* Creates an object representation of this proto suitable for use in Soy templates. | |
* Field names that are reserved in JavaScript and will be renamed to pb_name. | |
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default. | |
* For the list of reserved names please see: | |
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. | |
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance | |
* for transitional soy proto support: http://goto/soy-param-migration | |
* @return {!Object} | |
*/ | |
proto.com.book.GetBookViaAuthor.prototype.toObject = function(opt_includeInstance) { | |
return proto.com.book.GetBookViaAuthor.toObject(opt_includeInstance, this); | |
}; | |
/** | |
* Static version of the {@see toObject} method. | |
* @param {boolean|undefined} includeInstance Whether to include the JSPB | |
* instance for transitional soy proto support: | |
* http://goto/soy-param-migration | |
* @param {!proto.com.book.GetBookViaAuthor} msg The msg instance to transform. | |
* @return {!Object} | |
* @suppress {unusedLocalVariables} f is only used for nested messages | |
*/ | |
proto.com.book.GetBookViaAuthor.toObject = function(includeInstance, msg) { | |
var f, obj = { | |
author: jspb.Message.getFieldWithDefault(msg, 1, "") | |
}; | |
if (includeInstance) { | |
obj.$jspbMessageInstance = msg; | |
} | |
return obj; | |
}; | |
} | |
/** | |
* Deserializes binary data (in protobuf wire format). | |
* @param {jspb.ByteSource} bytes The bytes to deserialize. | |
* @return {!proto.com.book.GetBookViaAuthor} | |
*/ | |
proto.com.book.GetBookViaAuthor.deserializeBinary = function(bytes) { | |
var reader = new jspb.BinaryReader(bytes); | |
var msg = new proto.com.book.GetBookViaAuthor; | |
return proto.com.book.GetBookViaAuthor.deserializeBinaryFromReader(msg, reader); | |
}; | |
/** | |
* Deserializes binary data (in protobuf wire format) from the | |
* given reader into the given message object. | |
* @param {!proto.com.book.GetBookViaAuthor} msg The message object to deserialize into. | |
* @param {!jspb.BinaryReader} reader The BinaryReader to use. | |
* @return {!proto.com.book.GetBookViaAuthor} | |
*/ | |
proto.com.book.GetBookViaAuthor.deserializeBinaryFromReader = function(msg, reader) { | |
while (reader.nextField()) { | |
if (reader.isEndGroup()) { | |
break; | |
} | |
var field = reader.getFieldNumber(); | |
switch (field) { | |
case 1: | |
var value = /** @type {string} */ (reader.readString()); | |
msg.setAuthor(value); | |
break; | |
default: | |
reader.skipField(); | |
break; | |
} | |
} | |
return msg; | |
}; | |
/** | |
* Serializes the message to binary data (in protobuf wire format). | |
* @return {!Uint8Array} | |
*/ | |
proto.com.book.GetBookViaAuthor.prototype.serializeBinary = function() { | |
var writer = new jspb.BinaryWriter(); | |
proto.com.book.GetBookViaAuthor.serializeBinaryToWriter(this, writer); | |
return writer.getResultBuffer(); | |
}; | |
/** | |
* Serializes the given message to binary data (in protobuf wire | |
* format), writing to the given BinaryWriter. | |
* @param {!proto.com.book.GetBookViaAuthor} message | |
* @param {!jspb.BinaryWriter} writer | |
* @suppress {unusedLocalVariables} f is only used for nested messages | |
*/ | |
proto.com.book.GetBookViaAuthor.serializeBinaryToWriter = function(message, writer) { | |
var f = undefined; | |
f = message.getAuthor(); | |
if (f.length > 0) { | |
writer.writeString( | |
1, | |
f | |
); | |
} | |
}; | |
/** | |
* optional string author = 1; | |
* @return {string} | |
*/ | |
proto.com.book.GetBookViaAuthor.prototype.getAuthor = function() { | |
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); | |
}; | |
/** @param {string} value */ | |
proto.com.book.GetBookViaAuthor.prototype.setAuthor = function(value) { | |
jspb.Message.setProto3StringField(this, 1, value); | |
}; | |
/** | |
* Generated by JsPbCodeGenerator. | |
* @param {Array=} opt_data Optional initial data array, typically from a | |
* server response, or constructed directly in Javascript. The array is used | |
* in place and becomes part of the constructed object. It is not cloned. | |
* If no data is provided, the constructed object will be empty, but still | |
* valid. | |
* @extends {jspb.Message} | |
* @constructor | |
*/ | |
proto.com.book.BookStore = function(opt_data) { | |
jspb.Message.initialize(this, opt_data, 0, -1, null, null); | |
}; | |
goog.inherits(proto.com.book.BookStore, jspb.Message); | |
if (goog.DEBUG && !COMPILED) { | |
proto.com.book.BookStore.displayName = 'proto.com.book.BookStore'; | |
} | |
if (jspb.Message.GENERATE_TO_OBJECT) { | |
/** | |
* Creates an object representation of this proto suitable for use in Soy templates. | |
* Field names that are reserved in JavaScript and will be renamed to pb_name. | |
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default. | |
* For the list of reserved names please see: | |
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. | |
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance | |
* for transitional soy proto support: http://goto/soy-param-migration | |
* @return {!Object} | |
*/ | |
proto.com.book.BookStore.prototype.toObject = function(opt_includeInstance) { | |
return proto.com.book.BookStore.toObject(opt_includeInstance, this); | |
}; | |
/** | |
* Static version of the {@see toObject} method. | |
* @param {boolean|undefined} includeInstance Whether to include the JSPB | |
* instance for transitional soy proto support: | |
* http://goto/soy-param-migration | |
* @param {!proto.com.book.BookStore} msg The msg instance to transform. | |
* @return {!Object} | |
* @suppress {unusedLocalVariables} f is only used for nested messages | |
*/ | |
proto.com.book.BookStore.toObject = function(includeInstance, msg) { | |
var f, obj = { | |
name: jspb.Message.getFieldWithDefault(msg, 1, ""), | |
booksMap: (f = msg.getBooksMap()) ? f.toObject(includeInstance, undefined) : [] | |
}; | |
if (includeInstance) { | |
obj.$jspbMessageInstance = msg; | |
} | |
return obj; | |
}; | |
} | |
/** | |
* Deserializes binary data (in protobuf wire format). | |
* @param {jspb.ByteSource} bytes The bytes to deserialize. | |
* @return {!proto.com.book.BookStore} | |
*/ | |
proto.com.book.BookStore.deserializeBinary = function(bytes) { | |
var reader = new jspb.BinaryReader(bytes); | |
var msg = new proto.com.book.BookStore; | |
return proto.com.book.BookStore.deserializeBinaryFromReader(msg, reader); | |
}; | |
/** | |
* Deserializes binary data (in protobuf wire format) from the | |
* given reader into the given message object. | |
* @param {!proto.com.book.BookStore} msg The message object to deserialize into. | |
* @param {!jspb.BinaryReader} reader The BinaryReader to use. | |
* @return {!proto.com.book.BookStore} | |
*/ | |
proto.com.book.BookStore.deserializeBinaryFromReader = function(msg, reader) { | |
while (reader.nextField()) { | |
if (reader.isEndGroup()) { | |
break; | |
} | |
var field = reader.getFieldNumber(); | |
switch (field) { | |
case 1: | |
var value = /** @type {string} */ (reader.readString()); | |
msg.setName(value); | |
break; | |
case 2: | |
var value = msg.getBooksMap(); | |
reader.readMessage(value, function(message, reader) { | |
jspb.Map.deserializeBinary(message, reader, jspb.BinaryReader.prototype.readInt64, jspb.BinaryReader.prototype.readString); | |
}); | |
break; | |
default: | |
reader.skipField(); | |
break; | |
} | |
} | |
return msg; | |
}; | |
/** | |
* Serializes the message to binary data (in protobuf wire format). | |
* @return {!Uint8Array} | |
*/ | |
proto.com.book.BookStore.prototype.serializeBinary = function() { | |
var writer = new jspb.BinaryWriter(); | |
proto.com.book.BookStore.serializeBinaryToWriter(this, writer); | |
return writer.getResultBuffer(); | |
}; | |
/** | |
* Serializes the given message to binary data (in protobuf wire | |
* format), writing to the given BinaryWriter. | |
* @param {!proto.com.book.BookStore} message | |
* @param {!jspb.BinaryWriter} writer | |
* @suppress {unusedLocalVariables} f is only used for nested messages | |
*/ | |
proto.com.book.BookStore.serializeBinaryToWriter = function(message, writer) { | |
var f = undefined; | |
f = message.getName(); | |
if (f.length > 0) { | |
writer.writeString( | |
1, | |
f | |
); | |
} | |
f = message.getBooksMap(true); | |
if (f && f.getLength() > 0) { | |
f.serializeBinary(2, writer, jspb.BinaryWriter.prototype.writeInt64, jspb.BinaryWriter.prototype.writeString); | |
} | |
}; | |
/** | |
* optional string name = 1; | |
* @return {string} | |
*/ | |
proto.com.book.BookStore.prototype.getName = function() { | |
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); | |
}; | |
/** @param {string} value */ | |
proto.com.book.BookStore.prototype.setName = function(value) { | |
jspb.Message.setProto3StringField(this, 1, value); | |
}; | |
/** | |
* map<int64, string> books = 2; | |
* @param {boolean=} opt_noLazyCreate Do not create the map if | |
* empty, instead returning `undefined` | |
* @return {!jspb.Map<number,string>} | |
*/ | |
proto.com.book.BookStore.prototype.getBooksMap = function(opt_noLazyCreate) { | |
return /** @type {!jspb.Map<number,string>} */ ( | |
jspb.Message.getMapField(this, 2, opt_noLazyCreate, | |
null)); | |
}; | |
proto.com.book.BookStore.prototype.clearBooksMap = function() { | |
this.getBooksMap().clear(); | |
}; | |
/** | |
* @enum {number} | |
*/ | |
proto.com.book.EnumSample = { | |
UNKNOWN: 0, | |
STARTED: 1, | |
RUNNING: 1 | |
}; | |
goog.object.extend(exports, proto.com.book); |
This file contains 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
// package: com.book | |
// file: Book.proto | |
/* eslint-disable */ | |
var Book_pb = require("./Book_pb"); | |
var grpc = require("@improbable-eng/grpc-web").grpc; | |
var BookService = (function () { | |
function BookService() {} | |
BookService.serviceName = "com.book.BookService"; | |
return BookService; | |
}()); | |
BookService.GetBook = { | |
methodName: "GetBook", | |
service: BookService, | |
requestStream: false, | |
responseStream: false, | |
requestType: Book_pb.GetBookRequest, | |
responseType: Book_pb.Book | |
}; | |
BookService.GetBooksViaAuthor = { | |
methodName: "GetBooksViaAuthor", | |
service: BookService, | |
requestStream: false, | |
responseStream: true, | |
requestType: Book_pb.GetBookViaAuthor, | |
responseType: Book_pb.Book | |
}; | |
BookService.GetGreatestBook = { | |
methodName: "GetGreatestBook", | |
service: BookService, | |
requestStream: true, | |
responseStream: false, | |
requestType: Book_pb.GetBookRequest, | |
responseType: Book_pb.Book | |
}; | |
BookService.GetBooks = { | |
methodName: "GetBooks", | |
service: BookService, | |
requestStream: true, | |
responseStream: true, | |
requestType: Book_pb.GetBookRequest, | |
responseType: Book_pb.Book | |
}; | |
exports.BookService = BookService; | |
function BookServiceClient(serviceHost, options) { | |
this.serviceHost = serviceHost; | |
this.options = options || {}; | |
} | |
BookServiceClient.prototype.getBook = function getBook(requestMessage, metadata, callback) { | |
if (arguments.length === 2) { | |
callback = arguments[1]; | |
} | |
var client = grpc.unary(BookService.GetBook, { | |
request: requestMessage, | |
host: this.serviceHost, | |
metadata: metadata, | |
transport: this.options.transport, | |
debug: this.options.debug, | |
onEnd: function (response) { | |
if (callback) { | |
if (response.status !== grpc.Code.OK) { | |
var err = new Error(response.statusMessage); | |
err.code = response.status; | |
err.metadata = response.trailers; | |
callback(err, null); | |
} else { | |
callback(null, response.message); | |
} | |
} | |
} | |
}); | |
return { | |
cancel: function () { | |
callback = null; | |
client.close(); | |
} | |
}; | |
}; | |
BookServiceClient.prototype.getBooksViaAuthor = function getBooksViaAuthor(requestMessage, metadata) { | |
var listeners = { | |
data: [], | |
end: [], | |
status: [] | |
}; | |
var client = grpc.invoke(BookService.GetBooksViaAuthor, { | |
request: requestMessage, | |
host: this.serviceHost, | |
metadata: metadata, | |
transport: this.options.transport, | |
debug: this.options.debug, | |
onMessage: function (responseMessage) { | |
listeners.data.forEach(function (handler) { | |
handler(responseMessage); | |
}); | |
}, | |
onEnd: function (status, statusMessage, trailers) { | |
listeners.end.forEach(function (handler) { | |
handler(); | |
}); | |
listeners.status.forEach(function (handler) { | |
handler({ code: status, details: statusMessage, metadata: trailers }); | |
}); | |
listeners = null; | |
} | |
}); | |
return { | |
on: function (type, handler) { | |
listeners[type].push(handler); | |
return this; | |
}, | |
cancel: function () { | |
listeners = null; | |
client.close(); | |
} | |
}; | |
}; | |
BookServiceClient.prototype.getGreatestBook = function getGreatestBook(metadata) { | |
var listeners = { | |
end: [], | |
status: [] | |
}; | |
var client = grpc.client(BookService.GetGreatestBook, { | |
host: this.serviceHost, | |
metadata: metadata, | |
transport: this.options.transport | |
}); | |
client.onEnd(function (status, statusMessage, trailers) { | |
listeners.end.forEach(function (handler) { | |
handler(); | |
}); | |
listeners.status.forEach(function (handler) { | |
handler({ code: status, details: statusMessage, metadata: trailers }); | |
}); | |
listeners = null; | |
}); | |
return { | |
on: function (type, handler) { | |
listeners[type].push(handler); | |
return this; | |
}, | |
write: function (requestMessage) { | |
if (!client.started) { | |
client.start(metadata); | |
} | |
client.send(requestMessage); | |
return this; | |
}, | |
end: function () { | |
client.finishSend(); | |
}, | |
cancel: function () { | |
listeners = null; | |
client.close(); | |
} | |
}; | |
}; | |
BookServiceClient.prototype.getBooks = function getBooks(metadata) { | |
var listeners = { | |
data: [], | |
end: [], | |
status: [] | |
}; | |
var client = grpc.client(BookService.GetBooks, { | |
host: this.serviceHost, | |
metadata: metadata, | |
transport: this.options.transport | |
}); | |
client.onEnd(function (status, statusMessage, trailers) { | |
listeners.end.forEach(function (handler) { | |
handler(); | |
}); | |
listeners.status.forEach(function (handler) { | |
handler({ code: status, details: statusMessage, metadata: trailers }); | |
}); | |
listeners = null; | |
}); | |
client.onMessage(function (message) { | |
listeners.data.forEach(function (handler) { | |
handler(message); | |
}) | |
}); | |
client.start(metadata); | |
return { | |
on: function (type, handler) { | |
listeners[type].push(handler); | |
return this; | |
}, | |
write: function (requestMessage) { | |
client.send(requestMessage); | |
return this; | |
}, | |
end: function () { | |
client.finishSend(); | |
}, | |
cancel: function () { | |
listeners = null; | |
client.close(); | |
} | |
}; | |
}; | |
exports.BookServiceClient = BookServiceClient; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment