-
Notifications
You must be signed in to change notification settings - Fork 353
/
Copy pathfoo.ts
104 lines (90 loc) · 2.9 KB
/
foo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v1.173.0
// protoc v3.19.1
// source: foo.proto
/* eslint-disable */
import * as _m0 from "protobufjs/minimal";
import { Bar } from "./bar";
export interface Foo {
name: string;
bar: Bar | undefined;
}
function createBaseFoo(): Foo {
return { name: "", bar: undefined };
}
export const Foo = {
encode(message: Foo, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.name !== "") {
writer.uint32(10).string(message.name);
}
if (message.bar !== undefined) {
Bar.encode(message.bar, writer.uint32(18).fork()).ldelim();
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): Foo {
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseFoo();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
if (tag !== 10) {
break;
}
message.name = reader.string();
continue;
case 2:
if (tag !== 18) {
break;
}
message.bar = Bar.decode(reader, reader.uint32());
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skipType(tag & 7);
}
return message;
},
fromJSON(object: any): Foo {
return {
name: isSet(object.name) ? globalThis.String(object.name) : "",
bar: isSet(object.bar) ? Bar.fromJSON(object.bar) : undefined,
};
},
toJSON(message: Foo): unknown {
const obj: any = {};
if (message.name !== "") {
obj.name = message.name;
}
if (message.bar !== undefined) {
obj.bar = Bar.toJSON(message.bar);
}
return obj;
},
create<I extends Exact<DeepPartial<Foo>, I>>(base?: I): Foo {
return Foo.fromPartial(base ?? ({} as any));
},
fromPartial<I extends Exact<DeepPartial<Foo>, I>>(object: I): Foo {
const message = createBaseFoo();
message.name = object.name ?? "";
message.bar = (object.bar !== undefined && object.bar !== null) ? Bar.fromPartial(object.bar) : undefined;
return message;
},
};
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
type DeepPartial<T> = T extends Builtin ? T
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;
type KeysOfUnion<T> = T extends T ? keyof T : never;
type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}