|
1 | | -// Code generated by protoc-gen-ts_proto. DO NOT EDIT. |
2 | | -// versions: |
3 | | -// protoc-gen-ts_proto v2.8.3 |
4 | | -// protoc unknown |
5 | | -// source: google/protobuf/duration.proto |
6 | | - |
7 | | -/* eslint-disable */ |
8 | | -import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire"; |
9 | | -import Long from "long"; |
10 | | - |
11 | | -export const protobufPackage = "google.protobuf"; |
12 | | - |
| 1 | +// @generated by protobuf-ts 2.9.1 with parameter long_type_string,client_grpc1,generate_dependencies |
| 2 | +// @generated from protobuf file "google/protobuf/duration.proto" (package "google.protobuf", syntax proto3) |
| 3 | +// tslint:disable |
| 4 | +// |
| 5 | +// Protocol Buffers - Google's data interchange format |
| 6 | +// Copyright 2008 Google Inc. All rights reserved. |
| 7 | +// https://developers.google.com/protocol-buffers/ |
| 8 | +// |
| 9 | +// Redistribution and use in source and binary forms, with or without |
| 10 | +// modification, are permitted provided that the following conditions are |
| 11 | +// met: |
| 12 | +// |
| 13 | +// * Redistributions of source code must retain the above copyright |
| 14 | +// notice, this list of conditions and the following disclaimer. |
| 15 | +// * Redistributions in binary form must reproduce the above |
| 16 | +// copyright notice, this list of conditions and the following disclaimer |
| 17 | +// in the documentation and/or other materials provided with the |
| 18 | +// distribution. |
| 19 | +// * Neither the name of Google Inc. nor the names of its |
| 20 | +// contributors may be used to endorse or promote products derived from |
| 21 | +// this software without specific prior written permission. |
| 22 | +// |
| 23 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 24 | +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 25 | +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 26 | +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 27 | +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 28 | +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 29 | +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 30 | +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 31 | +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 32 | +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 33 | +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 34 | +// |
| 35 | +import type { BinaryWriteOptions } from "@protobuf-ts/runtime"; |
| 36 | +import type { IBinaryWriter } from "@protobuf-ts/runtime"; |
| 37 | +import { WireType } from "@protobuf-ts/runtime"; |
| 38 | +import type { BinaryReadOptions } from "@protobuf-ts/runtime"; |
| 39 | +import type { IBinaryReader } from "@protobuf-ts/runtime"; |
| 40 | +import { UnknownFieldHandler } from "@protobuf-ts/runtime"; |
| 41 | +import type { PartialMessage } from "@protobuf-ts/runtime"; |
| 42 | +import { reflectionMergePartial } from "@protobuf-ts/runtime"; |
| 43 | +import { MESSAGE_TYPE } from "@protobuf-ts/runtime"; |
| 44 | +import { typeofJsonValue } from "@protobuf-ts/runtime"; |
| 45 | +import type { JsonValue } from "@protobuf-ts/runtime"; |
| 46 | +import type { JsonReadOptions } from "@protobuf-ts/runtime"; |
| 47 | +import type { JsonWriteOptions } from "@protobuf-ts/runtime"; |
| 48 | +import { PbLong } from "@protobuf-ts/runtime"; |
| 49 | +import { MessageType } from "@protobuf-ts/runtime"; |
13 | 50 | /** |
14 | 51 | * A Duration represents a signed, fixed-length span of time represented |
15 | 52 | * as a count of seconds and fractions of seconds at nanosecond |
@@ -69,121 +106,125 @@ export const protobufPackage = "google.protobuf"; |
69 | 106 | * encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should |
70 | 107 | * be expressed in JSON format as "3.000000001s", and 3 seconds and 1 |
71 | 108 | * microsecond should be expressed in JSON format as "3.000001s". |
| 109 | + * |
| 110 | + * |
| 111 | + * @generated from protobuf message google.protobuf.Duration |
72 | 112 | */ |
73 | 113 | export interface Duration { |
74 | | - /** |
75 | | - * Signed seconds of the span of time. Must be from -315,576,000,000 |
76 | | - * to +315,576,000,000 inclusive. Note: these bounds are computed from: |
77 | | - * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years |
78 | | - */ |
79 | | - seconds: Long; |
80 | | - /** |
81 | | - * Signed fractions of a second at nanosecond resolution of the span |
82 | | - * of time. Durations less than one second are represented with a 0 |
83 | | - * `seconds` field and a positive or negative `nanos` field. For durations |
84 | | - * of one second or more, a non-zero value for the `nanos` field must be |
85 | | - * of the same sign as the `seconds` field. Must be from -999,999,999 |
86 | | - * to +999,999,999 inclusive. |
87 | | - */ |
88 | | - nanos: number; |
89 | | -} |
90 | | - |
91 | | -function createBaseDuration(): Duration { |
92 | | - return { seconds: Long.ZERO, nanos: 0 }; |
| 114 | + /** |
| 115 | + * Signed seconds of the span of time. Must be from -315,576,000,000 |
| 116 | + * to +315,576,000,000 inclusive. Note: these bounds are computed from: |
| 117 | + * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years |
| 118 | + * |
| 119 | + * @generated from protobuf field: int64 seconds = 1; |
| 120 | + */ |
| 121 | + seconds: string; |
| 122 | + /** |
| 123 | + * Signed fractions of a second at nanosecond resolution of the span |
| 124 | + * of time. Durations less than one second are represented with a 0 |
| 125 | + * `seconds` field and a positive or negative `nanos` field. For durations |
| 126 | + * of one second or more, a non-zero value for the `nanos` field must be |
| 127 | + * of the same sign as the `seconds` field. Must be from -999,999,999 |
| 128 | + * to +999,999,999 inclusive. |
| 129 | + * |
| 130 | + * @generated from protobuf field: int32 nanos = 2; |
| 131 | + */ |
| 132 | + nanos: number; |
93 | 133 | } |
94 | | - |
95 | | -export const Duration: MessageFns<Duration> = { |
96 | | - encode(message: Duration, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { |
97 | | - if (!message.seconds.equals(Long.ZERO)) { |
98 | | - writer.uint32(8).int64(message.seconds.toString()); |
| 134 | +// @generated message type with reflection information, may provide speed optimized methods |
| 135 | +class Duration$Type extends MessageType<Duration> { |
| 136 | + constructor() { |
| 137 | + super("google.protobuf.Duration", [ |
| 138 | + { no: 1, name: "seconds", kind: "scalar", T: 3 /*ScalarType.INT64*/ }, |
| 139 | + { no: 2, name: "nanos", kind: "scalar", T: 5 /*ScalarType.INT32*/ } |
| 140 | + ]); |
99 | 141 | } |
100 | | - if (message.nanos !== 0) { |
101 | | - writer.uint32(16).int32(message.nanos); |
102 | | - } |
103 | | - return writer; |
104 | | - }, |
105 | | - |
106 | | - decode(input: BinaryReader | Uint8Array, length?: number): Duration { |
107 | | - const reader = input instanceof BinaryReader ? input : new BinaryReader(input); |
108 | | - const end = length === undefined ? reader.len : reader.pos + length; |
109 | | - const message = createBaseDuration(); |
110 | | - while (reader.pos < end) { |
111 | | - const tag = reader.uint32(); |
112 | | - switch (tag >>> 3) { |
113 | | - case 1: { |
114 | | - if (tag !== 8) { |
115 | | - break; |
116 | | - } |
117 | | - |
118 | | - message.seconds = Long.fromString(reader.int64().toString()); |
119 | | - continue; |
| 142 | + /** |
| 143 | + * Encode `Duration` to JSON string like "3.000001s". |
| 144 | + */ |
| 145 | + internalJsonWrite(message: Duration, options: JsonWriteOptions): JsonValue { |
| 146 | + let s = PbLong.from(message.seconds).toNumber(); |
| 147 | + if (s > 315576000000 || s < -315576000000) |
| 148 | + throw new Error("Duration value out of range."); |
| 149 | + let text = message.seconds.toString(); |
| 150 | + if (s === 0 && message.nanos < 0) |
| 151 | + text = "-" + text; |
| 152 | + if (message.nanos !== 0) { |
| 153 | + let nanosStr = Math.abs(message.nanos).toString(); |
| 154 | + nanosStr = "0".repeat(9 - nanosStr.length) + nanosStr; |
| 155 | + if (nanosStr.substring(3) === "000000") |
| 156 | + nanosStr = nanosStr.substring(0, 3); |
| 157 | + else if (nanosStr.substring(6) === "000") |
| 158 | + nanosStr = nanosStr.substring(0, 6); |
| 159 | + text += "." + nanosStr; |
120 | 160 | } |
121 | | - case 2: { |
122 | | - if (tag !== 16) { |
123 | | - break; |
124 | | - } |
125 | | - |
126 | | - message.nanos = reader.int32(); |
127 | | - continue; |
| 161 | + return text + "s"; |
| 162 | + } |
| 163 | + /** |
| 164 | + * Decode `Duration` from JSON string like "3.000001s" |
| 165 | + */ |
| 166 | + internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: Duration): Duration { |
| 167 | + if (typeof json !== "string") |
| 168 | + throw new Error("Unable to parse Duration from JSON " + typeofJsonValue(json) + ". Expected string."); |
| 169 | + let match = json.match(/^(-?)([0-9]+)(?:\.([0-9]+))?s/); |
| 170 | + if (match === null) |
| 171 | + throw new Error("Unable to parse Duration from JSON string. Invalid format."); |
| 172 | + if (!target) |
| 173 | + target = this.create(); |
| 174 | + let [, sign, secs, nanos] = match; |
| 175 | + let longSeconds = PbLong.from(sign + secs); |
| 176 | + if (longSeconds.toNumber() > 315576000000 || longSeconds.toNumber() < -315576000000) |
| 177 | + throw new Error("Unable to parse Duration from JSON string. Value out of range."); |
| 178 | + target.seconds = longSeconds.toString(); |
| 179 | + if (typeof nanos == "string") { |
| 180 | + let nanosStr = sign + nanos + "0".repeat(9 - nanos.length); |
| 181 | + target.nanos = parseInt(nanosStr); |
128 | 182 | } |
129 | | - } |
130 | | - if ((tag & 7) === 4 || tag === 0) { |
131 | | - break; |
132 | | - } |
133 | | - reader.skip(tag & 7); |
| 183 | + return target; |
134 | 184 | } |
135 | | - return message; |
136 | | - }, |
137 | | - |
138 | | - fromJSON(object: any): Duration { |
139 | | - return { |
140 | | - seconds: isSet(object.seconds) ? Long.fromValue(object.seconds) : Long.ZERO, |
141 | | - nanos: isSet(object.nanos) ? globalThis.Number(object.nanos) : 0, |
142 | | - }; |
143 | | - }, |
144 | | - |
145 | | - toJSON(message: Duration): unknown { |
146 | | - const obj: any = {}; |
147 | | - if (!message.seconds.equals(Long.ZERO)) { |
148 | | - obj.seconds = (message.seconds || Long.ZERO).toString(); |
| 185 | + create(value?: PartialMessage<Duration>): Duration { |
| 186 | + const message = { seconds: "0", nanos: 0 }; |
| 187 | + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); |
| 188 | + if (value !== undefined) |
| 189 | + reflectionMergePartial<Duration>(this, message, value); |
| 190 | + return message; |
149 | 191 | } |
150 | | - if (message.nanos !== 0) { |
151 | | - obj.nanos = Math.round(message.nanos); |
| 192 | + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Duration): Duration { |
| 193 | + let message = target ?? this.create(), end = reader.pos + length; |
| 194 | + while (reader.pos < end) { |
| 195 | + let [fieldNo, wireType] = reader.tag(); |
| 196 | + switch (fieldNo) { |
| 197 | + case /* int64 seconds */ 1: |
| 198 | + message.seconds = reader.int64().toString(); |
| 199 | + break; |
| 200 | + case /* int32 nanos */ 2: |
| 201 | + message.nanos = reader.int32(); |
| 202 | + break; |
| 203 | + default: |
| 204 | + let u = options.readUnknownField; |
| 205 | + if (u === "throw") |
| 206 | + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); |
| 207 | + let d = reader.skip(wireType); |
| 208 | + if (u !== false) |
| 209 | + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); |
| 210 | + } |
| 211 | + } |
| 212 | + return message; |
| 213 | + } |
| 214 | + internalBinaryWrite(message: Duration, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { |
| 215 | + /* int64 seconds = 1; */ |
| 216 | + if (message.seconds !== "0") |
| 217 | + writer.tag(1, WireType.Varint).int64(message.seconds); |
| 218 | + /* int32 nanos = 2; */ |
| 219 | + if (message.nanos !== 0) |
| 220 | + writer.tag(2, WireType.Varint).int32(message.nanos); |
| 221 | + let u = options.writeUnknownFields; |
| 222 | + if (u !== false) |
| 223 | + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); |
| 224 | + return writer; |
152 | 225 | } |
153 | | - return obj; |
154 | | - }, |
155 | | - |
156 | | - create(base?: DeepPartial<Duration>): Duration { |
157 | | - return Duration.fromPartial(base ?? {}); |
158 | | - }, |
159 | | - fromPartial(object: DeepPartial<Duration>): Duration { |
160 | | - const message = createBaseDuration(); |
161 | | - message.seconds = (object.seconds !== undefined && object.seconds !== null) |
162 | | - ? Long.fromValue(object.seconds) |
163 | | - : Long.ZERO; |
164 | | - message.nanos = object.nanos ?? 0; |
165 | | - return message; |
166 | | - }, |
167 | | -}; |
168 | | - |
169 | | -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; |
170 | | - |
171 | | -export type DeepPartial<T> = T extends Builtin ? T |
172 | | - : T extends Long ? string | number | Long : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> |
173 | | - : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> |
174 | | - : T extends { $case: string } ? { [K in keyof Omit<T, "$case">]?: DeepPartial<T[K]> } & { $case: T["$case"] } |
175 | | - : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> } |
176 | | - : Partial<T>; |
177 | | - |
178 | | -function isSet(value: any): boolean { |
179 | | - return value !== null && value !== undefined; |
180 | | -} |
181 | | - |
182 | | -export interface MessageFns<T> { |
183 | | - encode(message: T, writer?: BinaryWriter): BinaryWriter; |
184 | | - decode(input: BinaryReader | Uint8Array, length?: number): T; |
185 | | - fromJSON(object: any): T; |
186 | | - toJSON(message: T): unknown; |
187 | | - create(base?: DeepPartial<T>): T; |
188 | | - fromPartial(object: DeepPartial<T>): T; |
189 | 226 | } |
| 227 | +/** |
| 228 | + * @generated MessageType for protobuf message google.protobuf.Duration |
| 229 | + */ |
| 230 | +export const Duration = new Duration$Type(); |
0 commit comments