any.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. // source: google/protobuf/any.proto
  2. /**
  3. * @fileoverview
  4. * @enhanceable
  5. * @suppress {missingRequire} reports error on implicit type usages.
  6. * @suppress {messageConventions} JS Compiler reports an error if a variable or
  7. * field starts with 'MSG_' and isn't a translatable message.
  8. * @public
  9. */
  10. // GENERATED CODE -- DO NOT EDIT!
  11. /* eslint-disable */
  12. // @ts-nocheck
  13. goog.provide('proto.google.protobuf.Any');
  14. goog.require('jspb.BinaryReader');
  15. goog.require('jspb.BinaryWriter');
  16. goog.require('jspb.Message');
  17. /**
  18. * Generated by JsPbCodeGenerator.
  19. * @param {Array=} opt_data Optional initial data array, typically from a
  20. * server response, or constructed directly in Javascript. The array is used
  21. * in place and becomes part of the constructed object. It is not cloned.
  22. * If no data is provided, the constructed object will be empty, but still
  23. * valid.
  24. * @extends {jspb.Message}
  25. * @constructor
  26. */
  27. proto.google.protobuf.Any = function(opt_data) {
  28. jspb.Message.initialize(this, opt_data, 0, -1, null, null);
  29. };
  30. goog.inherits(proto.google.protobuf.Any, jspb.Message);
  31. if (goog.DEBUG && !COMPILED) {
  32. /**
  33. * @public
  34. * @override
  35. */
  36. proto.google.protobuf.Any.displayName = 'proto.google.protobuf.Any';
  37. }
  38. if (jspb.Message.GENERATE_TO_OBJECT) {
  39. /**
  40. * Creates an object representation of this proto.
  41. * Field names that are reserved in JavaScript and will be renamed to pb_name.
  42. * Optional fields that are not set will be set to undefined.
  43. * To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
  44. * For the list of reserved names please see:
  45. * net/proto2/compiler/js/internal/generator.cc#kKeyword.
  46. * @param {boolean=} opt_includeInstance Deprecated. whether to include the
  47. * JSPB instance for transitional soy proto support:
  48. * http://goto/soy-param-migration
  49. * @return {!Object}
  50. */
  51. proto.google.protobuf.Any.prototype.toObject = function(opt_includeInstance) {
  52. return proto.google.protobuf.Any.toObject(opt_includeInstance, this);
  53. };
  54. /**
  55. * Static version of the {@see toObject} method.
  56. * @param {boolean|undefined} includeInstance Deprecated. Whether to include
  57. * the JSPB instance for transitional soy proto support:
  58. * http://goto/soy-param-migration
  59. * @param {!proto.google.protobuf.Any} msg The msg instance to transform.
  60. * @return {!Object}
  61. * @suppress {unusedLocalVariables} f is only used for nested messages
  62. */
  63. proto.google.protobuf.Any.toObject = function(includeInstance, msg) {
  64. var f, obj = {
  65. typeUrl: jspb.Message.getFieldWithDefault(msg, 1, ""),
  66. value: msg.getValue_asB64()
  67. };
  68. if (includeInstance) {
  69. obj.$jspbMessageInstance = msg;
  70. }
  71. return obj;
  72. };
  73. }
  74. /**
  75. * Deserializes binary data (in protobuf wire format).
  76. * @param {jspb.ByteSource} bytes The bytes to deserialize.
  77. * @return {!proto.google.protobuf.Any}
  78. */
  79. proto.google.protobuf.Any.deserializeBinary = function(bytes) {
  80. var reader = new jspb.BinaryReader(bytes);
  81. var msg = new proto.google.protobuf.Any;
  82. return proto.google.protobuf.Any.deserializeBinaryFromReader(msg, reader);
  83. };
  84. /**
  85. * Deserializes binary data (in protobuf wire format) from the
  86. * given reader into the given message object.
  87. * @param {!proto.google.protobuf.Any} msg The message object to deserialize into.
  88. * @param {!jspb.BinaryReader} reader The BinaryReader to use.
  89. * @return {!proto.google.protobuf.Any}
  90. */
  91. proto.google.protobuf.Any.deserializeBinaryFromReader = function(msg, reader) {
  92. while (reader.nextField()) {
  93. if (reader.isEndGroup()) {
  94. break;
  95. }
  96. var field = reader.getFieldNumber();
  97. switch (field) {
  98. case 1:
  99. var value = /** @type {string} */ (reader.readString());
  100. msg.setTypeUrl(value);
  101. break;
  102. case 2:
  103. var value = /** @type {!Uint8Array} */ (reader.readBytes());
  104. msg.setValue(value);
  105. break;
  106. default:
  107. reader.skipField();
  108. break;
  109. }
  110. }
  111. return msg;
  112. };
  113. /**
  114. * Serializes the message to binary data (in protobuf wire format).
  115. * @return {!Uint8Array}
  116. */
  117. proto.google.protobuf.Any.prototype.serializeBinary = function() {
  118. var writer = new jspb.BinaryWriter();
  119. proto.google.protobuf.Any.serializeBinaryToWriter(this, writer);
  120. return writer.getResultBuffer();
  121. };
  122. /**
  123. * Serializes the given message to binary data (in protobuf wire
  124. * format), writing to the given BinaryWriter.
  125. * @param {!proto.google.protobuf.Any} message
  126. * @param {!jspb.BinaryWriter} writer
  127. * @suppress {unusedLocalVariables} f is only used for nested messages
  128. */
  129. proto.google.protobuf.Any.serializeBinaryToWriter = function(message, writer) {
  130. var f = undefined;
  131. f = message.getTypeUrl();
  132. if (f.length > 0) {
  133. writer.writeString(
  134. 1,
  135. f
  136. );
  137. }
  138. f = message.getValue_asU8();
  139. if (f.length > 0) {
  140. writer.writeBytes(
  141. 2,
  142. f
  143. );
  144. }
  145. };
  146. /**
  147. * optional string type_url = 1;
  148. * @return {string}
  149. */
  150. proto.google.protobuf.Any.prototype.getTypeUrl = function() {
  151. return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ""));
  152. };
  153. /**
  154. * @param {string} value
  155. * @return {!proto.google.protobuf.Any} returns this
  156. */
  157. proto.google.protobuf.Any.prototype.setTypeUrl = function(value) {
  158. return jspb.Message.setProto3StringField(this, 1, value);
  159. };
  160. /**
  161. * optional bytes value = 2;
  162. * @return {!(string|Uint8Array)}
  163. */
  164. proto.google.protobuf.Any.prototype.getValue = function() {
  165. return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 2, ""));
  166. };
  167. /**
  168. * optional bytes value = 2;
  169. * This is a type-conversion wrapper around `getValue()`
  170. * @return {string}
  171. */
  172. proto.google.protobuf.Any.prototype.getValue_asB64 = function() {
  173. return /** @type {string} */ (jspb.Message.bytesAsB64(
  174. this.getValue()));
  175. };
  176. /**
  177. * optional bytes value = 2;
  178. * Note that Uint8Array is not supported on all browsers.
  179. * @see http://caniuse.com/Uint8Array
  180. * This is a type-conversion wrapper around `getValue()`
  181. * @return {!Uint8Array}
  182. */
  183. proto.google.protobuf.Any.prototype.getValue_asU8 = function() {
  184. return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8(
  185. this.getValue()));
  186. };
  187. /**
  188. * @param {!(string|Uint8Array)} value
  189. * @return {!proto.google.protobuf.Any} returns this
  190. */
  191. proto.google.protobuf.Any.prototype.setValue = function(value) {
  192. return jspb.Message.setProto3BytesField(this, 2, value);
  193. };
  194. /* This code will be inserted into generated code for
  195. * google/protobuf/any.proto. */
  196. /**
  197. * Returns the type name contained in this instance, if any.
  198. * @return {string|undefined}
  199. */
  200. proto.google.protobuf.Any.prototype.getTypeName = function() {
  201. return this.getTypeUrl().split('/').pop();
  202. };
  203. /**
  204. * Packs the given message instance into this Any.
  205. * For binary format usage only.
  206. * @param {!Uint8Array} serialized The serialized data to pack.
  207. * @param {string} name The type name of this message object.
  208. * @param {string=} opt_typeUrlPrefix the type URL prefix.
  209. */
  210. proto.google.protobuf.Any.prototype.pack = function(serialized, name,
  211. opt_typeUrlPrefix) {
  212. if (!opt_typeUrlPrefix) {
  213. opt_typeUrlPrefix = 'type.googleapis.com/';
  214. }
  215. if (opt_typeUrlPrefix.substr(-1) != '/') {
  216. this.setTypeUrl(opt_typeUrlPrefix + '/' + name);
  217. } else {
  218. this.setTypeUrl(opt_typeUrlPrefix + name);
  219. }
  220. this.setValue(serialized);
  221. };
  222. /**
  223. * @template T
  224. * Unpacks this Any into the given message object.
  225. * @param {function(Uint8Array):T} deserialize Function that will deserialize
  226. * the binary data properly.
  227. * @param {string} name The expected type name of this message object.
  228. * @return {?T} If the name matched the expected name, returns the deserialized
  229. * object, otherwise returns null.
  230. */
  231. proto.google.protobuf.Any.prototype.unpack = function(deserialize, name) {
  232. if (this.getTypeName() == name) {
  233. return deserialize(this.getValue_asU8());
  234. } else {
  235. return null;
  236. }
  237. };