-
Notifications
You must be signed in to change notification settings - Fork 22
/
ServiceDescriptorProto.ts
122 lines (114 loc) · 3.91 KB
/
ServiceDescriptorProto.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import {
Type as MethodDescriptorProto,
encodeJson as encodeJson_1,
decodeJson as decodeJson_1,
encodeBinary as encodeBinary_1,
decodeBinary as decodeBinary_1,
} from "./MethodDescriptorProto.ts";
import {
Type as ServiceOptions,
encodeJson as encodeJson_2,
decodeJson as decodeJson_2,
encodeBinary as encodeBinary_2,
decodeBinary as decodeBinary_2,
} from "./ServiceOptions.ts";
import {
tsValueToJsonValueFns,
jsonValueToTsValueFns,
} from "../../../../core/runtime/json/scalar.ts";
import {
WireMessage,
WireType,
} from "../../../../core/runtime/wire/index.ts";
import {
default as serialize,
} from "../../../../core/runtime/wire/serialize.ts";
import {
tsValueToWireValueFns,
wireValueToTsValueFns,
} from "../../../../core/runtime/wire/scalar.ts";
import {
default as deserialize,
} from "../../../../core/runtime/wire/deserialize.ts";
export declare namespace $.google.protobuf {
export type ServiceDescriptorProto = {
name?: string;
method: MethodDescriptorProto[];
options?: ServiceOptions;
}
}
export type Type = $.google.protobuf.ServiceDescriptorProto;
export function getDefaultValue(): $.google.protobuf.ServiceDescriptorProto {
return {
name: undefined,
method: [],
options: undefined,
};
}
export function createValue(partialValue: Partial<$.google.protobuf.ServiceDescriptorProto>): $.google.protobuf.ServiceDescriptorProto {
return {
...getDefaultValue(),
...partialValue,
};
}
export function encodeJson(value: $.google.protobuf.ServiceDescriptorProto): unknown {
const result: any = {};
if (value.name !== undefined) result.name = tsValueToJsonValueFns.string(value.name);
result.method = value.method.map(value => encodeJson_1(value));
if (value.options !== undefined) result.options = encodeJson_2(value.options);
return result;
}
export function decodeJson(value: any): $.google.protobuf.ServiceDescriptorProto {
const result = getDefaultValue();
if (value.name !== undefined) result.name = jsonValueToTsValueFns.string(value.name);
result.method = value.method?.map((value: any) => decodeJson_1(value)) ?? [];
if (value.options !== undefined) result.options = decodeJson_2(value.options);
return result;
}
export function encodeBinary(value: $.google.protobuf.ServiceDescriptorProto): Uint8Array {
const result: WireMessage = [];
if (value.name !== undefined) {
const tsValue = value.name;
result.push(
[1, tsValueToWireValueFns.string(tsValue)],
);
}
for (const tsValue of value.method) {
result.push(
[2, { type: WireType.LengthDelimited as const, value: encodeBinary_1(tsValue) }],
);
}
if (value.options !== undefined) {
const tsValue = value.options;
result.push(
[3, { type: WireType.LengthDelimited as const, value: encodeBinary_2(tsValue) }],
);
}
return serialize(result);
}
export function decodeBinary(binary: Uint8Array): $.google.protobuf.ServiceDescriptorProto {
const result = getDefaultValue();
const wireMessage = deserialize(binary);
const wireFields = new Map(wireMessage);
field: {
const wireValue = wireFields.get(1);
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.string(wireValue);
if (value === undefined) break field;
result.name = value;
}
collection: {
const wireValues = wireMessage.filter(([fieldNumber]) => fieldNumber === 2).map(([, wireValue]) => wireValue);
const value = wireValues.map((wireValue) => wireValue.type === WireType.LengthDelimited ? decodeBinary_1(wireValue.value) : undefined).filter(x => x !== undefined);
if (!value.length) break collection;
result.method = value as any;
}
field: {
const wireValue = wireFields.get(3);
if (wireValue === undefined) break field;
const value = wireValue.type === WireType.LengthDelimited ? decodeBinary_2(wireValue.value) : undefined;
if (value === undefined) break field;
result.options = value;
}
return result;
}