timestamp.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. // source: google/protobuf/timestamp.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.Timestamp');
  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.Timestamp = function(opt_data) {
  28. jspb.Message.initialize(this, opt_data, 0, -1, null, null);
  29. };
  30. goog.inherits(proto.google.protobuf.Timestamp, jspb.Message);
  31. if (goog.DEBUG && !COMPILED) {
  32. /**
  33. * @public
  34. * @override
  35. */
  36. proto.google.protobuf.Timestamp.displayName = 'proto.google.protobuf.Timestamp';
  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.Timestamp.prototype.toObject = function(opt_includeInstance) {
  52. return proto.google.protobuf.Timestamp.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.Timestamp} msg The msg instance to transform.
  60. * @return {!Object}
  61. * @suppress {unusedLocalVariables} f is only used for nested messages
  62. */
  63. proto.google.protobuf.Timestamp.toObject = function(includeInstance, msg) {
  64. var f, obj = {
  65. seconds: jspb.Message.getFieldWithDefault(msg, 1, 0),
  66. nanos: jspb.Message.getFieldWithDefault(msg, 2, 0)
  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.Timestamp}
  78. */
  79. proto.google.protobuf.Timestamp.deserializeBinary = function(bytes) {
  80. var reader = new jspb.BinaryReader(bytes);
  81. var msg = new proto.google.protobuf.Timestamp;
  82. return proto.google.protobuf.Timestamp.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.Timestamp} msg The message object to deserialize into.
  88. * @param {!jspb.BinaryReader} reader The BinaryReader to use.
  89. * @return {!proto.google.protobuf.Timestamp}
  90. */
  91. proto.google.protobuf.Timestamp.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 {number} */ (reader.readInt64());
  100. msg.setSeconds(value);
  101. break;
  102. case 2:
  103. var value = /** @type {number} */ (reader.readInt32());
  104. msg.setNanos(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.Timestamp.prototype.serializeBinary = function() {
  118. var writer = new jspb.BinaryWriter();
  119. proto.google.protobuf.Timestamp.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.Timestamp} message
  126. * @param {!jspb.BinaryWriter} writer
  127. * @suppress {unusedLocalVariables} f is only used for nested messages
  128. */
  129. proto.google.protobuf.Timestamp.serializeBinaryToWriter = function(message, writer) {
  130. var f = undefined;
  131. f = message.getSeconds();
  132. if (f !== 0) {
  133. writer.writeInt64(
  134. 1,
  135. f
  136. );
  137. }
  138. f = message.getNanos();
  139. if (f !== 0) {
  140. writer.writeInt32(
  141. 2,
  142. f
  143. );
  144. }
  145. };
  146. /**
  147. * optional int64 seconds = 1;
  148. * @return {number}
  149. */
  150. proto.google.protobuf.Timestamp.prototype.getSeconds = function() {
  151. return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 1, 0));
  152. };
  153. /**
  154. * @param {number} value
  155. * @return {!proto.google.protobuf.Timestamp} returns this
  156. */
  157. proto.google.protobuf.Timestamp.prototype.setSeconds = function(value) {
  158. return jspb.Message.setProto3IntField(this, 1, value);
  159. };
  160. /**
  161. * optional int32 nanos = 2;
  162. * @return {number}
  163. */
  164. proto.google.protobuf.Timestamp.prototype.getNanos = function() {
  165. return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0));
  166. };
  167. /**
  168. * @param {number} value
  169. * @return {!proto.google.protobuf.Timestamp} returns this
  170. */
  171. proto.google.protobuf.Timestamp.prototype.setNanos = function(value) {
  172. return jspb.Message.setProto3IntField(this, 2, value);
  173. };
  174. /* This code will be inserted into generated code for
  175. * google/protobuf/timestamp.proto. */
  176. /**
  177. * Returns a JavaScript 'Date' object corresponding to this Timestamp.
  178. * @return {!Date}
  179. */
  180. proto.google.protobuf.Timestamp.prototype.toDate = function() {
  181. var seconds = this.getSeconds();
  182. var nanos = this.getNanos();
  183. return new Date((seconds * 1000) + (nanos / 1000000));
  184. };
  185. /**
  186. * Sets the value of this Timestamp object to be the given Date.
  187. * @param {!Date} value The value to set.
  188. */
  189. proto.google.protobuf.Timestamp.prototype.fromDate = function(value) {
  190. this.setSeconds(Math.floor(value.getTime() / 1000));
  191. this.setNanos(value.getMilliseconds() * 1000000);
  192. };
  193. /**
  194. * Factory method that returns a Timestamp object with value equal to
  195. * the given Date.
  196. * @param {!Date} value The value to set.
  197. * @return {!proto.google.protobuf.Timestamp}
  198. */
  199. proto.google.protobuf.Timestamp.fromDate = function(value) {
  200. var timestamp = new proto.google.protobuf.Timestamp();
  201. timestamp.fromDate(value);
  202. return timestamp;
  203. };