-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathMutation.ts
More file actions
194 lines (186 loc) · 6.26 KB
/
Copy pathMutation.ts
File metadata and controls
194 lines (186 loc) · 6.26 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// @ts-nocheck
import {
Type as KvValue,
encodeJson as encodeJson_1,
decodeJson as decodeJson_1,
encodeBinary as encodeBinary_1,
decodeBinary as decodeBinary_1,
} from "./KvValue.ts";
import {
Type as MutationType,
name2num,
num2name,
} from "./MutationType.ts";
import {
tsValueToJsonValueFns,
jsonValueToTsValueFns,
} from "../../../../../runtime/json/scalar.ts";
import {
WireMessage,
WireType,
} from "../../../../../runtime/wire/index.ts";
import {
default as serialize,
} from "../../../../../runtime/wire/serialize.ts";
import {
tsValueToWireValueFns,
wireValueToTsValueFns,
} from "../../../../../runtime/wire/scalar.ts";
import {
default as Long,
} from "../../../../../runtime/Long.ts";
import {
default as deserialize,
} from "../../../../../runtime/wire/deserialize.ts";
export declare namespace $.com.deno.kv.datapath {
export type Mutation = {
key: Uint8Array;
value?: KvValue;
mutationType: MutationType;
expireAtMs: string;
sumMin: Uint8Array;
sumMax: Uint8Array;
sumClamp: boolean;
}
}
export type Type = $.com.deno.kv.datapath.Mutation;
export function getDefaultValue(): $.com.deno.kv.datapath.Mutation {
return {
key: new Uint8Array(),
value: undefined,
mutationType: "M_UNSPECIFIED",
expireAtMs: "0",
sumMin: new Uint8Array(),
sumMax: new Uint8Array(),
sumClamp: false,
};
}
export function createValue(partialValue: Partial<$.com.deno.kv.datapath.Mutation>): $.com.deno.kv.datapath.Mutation {
return {
...getDefaultValue(),
...partialValue,
};
}
export function encodeJson(value: $.com.deno.kv.datapath.Mutation): unknown {
const result: any = {};
if (value.key !== undefined) result.key = tsValueToJsonValueFns.bytes(value.key);
if (value.value !== undefined) result.value = encodeJson_1(value.value);
if (value.mutationType !== undefined) result.mutationType = tsValueToJsonValueFns.enum(value.mutationType);
if (value.expireAtMs !== undefined) result.expireAtMs = tsValueToJsonValueFns.int64(value.expireAtMs);
if (value.sumMin !== undefined) result.sumMin = tsValueToJsonValueFns.bytes(value.sumMin);
if (value.sumMax !== undefined) result.sumMax = tsValueToJsonValueFns.bytes(value.sumMax);
if (value.sumClamp !== undefined) result.sumClamp = tsValueToJsonValueFns.bool(value.sumClamp);
return result;
}
export function decodeJson(value: any): $.com.deno.kv.datapath.Mutation {
const result = getDefaultValue();
if (value.key !== undefined) result.key = jsonValueToTsValueFns.bytes(value.key);
if (value.value !== undefined) result.value = decodeJson_1(value.value);
if (value.mutationType !== undefined) result.mutationType = jsonValueToTsValueFns.enum(value.mutationType) as MutationType;
if (value.expireAtMs !== undefined) result.expireAtMs = jsonValueToTsValueFns.int64(value.expireAtMs);
if (value.sumMin !== undefined) result.sumMin = jsonValueToTsValueFns.bytes(value.sumMin);
if (value.sumMax !== undefined) result.sumMax = jsonValueToTsValueFns.bytes(value.sumMax);
if (value.sumClamp !== undefined) result.sumClamp = jsonValueToTsValueFns.bool(value.sumClamp);
return result;
}
export function encodeBinary(value: $.com.deno.kv.datapath.Mutation): Uint8Array {
const result: WireMessage = [];
if (value.key !== undefined) {
const tsValue = value.key;
result.push(
[1, tsValueToWireValueFns.bytes(tsValue)],
);
}
if (value.value !== undefined) {
const tsValue = value.value;
result.push(
[2, { type: WireType.LengthDelimited as const, value: encodeBinary_1(tsValue) }],
);
}
if (value.mutationType !== undefined) {
const tsValue = value.mutationType;
result.push(
[3, { type: WireType.Varint as const, value: new Long(name2num[tsValue as keyof typeof name2num]) }],
);
}
if (value.expireAtMs !== undefined) {
const tsValue = value.expireAtMs;
result.push(
[4, tsValueToWireValueFns.int64(tsValue)],
);
}
if (value.sumMin !== undefined) {
const tsValue = value.sumMin;
result.push(
[5, tsValueToWireValueFns.bytes(tsValue)],
);
}
if (value.sumMax !== undefined) {
const tsValue = value.sumMax;
result.push(
[6, tsValueToWireValueFns.bytes(tsValue)],
);
}
if (value.sumClamp !== undefined) {
const tsValue = value.sumClamp;
result.push(
[7, tsValueToWireValueFns.bool(tsValue)],
);
}
return serialize(result);
}
export function decodeBinary(binary: Uint8Array): $.com.deno.kv.datapath.Mutation {
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.bytes(wireValue);
if (value === undefined) break field;
result.key = value;
}
field: {
const wireValue = wireFields.get(2);
if (wireValue === undefined) break field;
const value = wireValue.type === WireType.LengthDelimited ? decodeBinary_1(wireValue.value) : undefined;
if (value === undefined) break field;
result.value = value;
}
field: {
const wireValue = wireFields.get(3);
if (wireValue === undefined) break field;
const value = wireValue.type === WireType.Varint ? num2name[wireValue.value[0] as keyof typeof num2name] : undefined;
if (value === undefined) break field;
result.mutationType = value;
}
field: {
const wireValue = wireFields.get(4);
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.int64(wireValue);
if (value === undefined) break field;
result.expireAtMs = value;
}
field: {
const wireValue = wireFields.get(5);
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.bytes(wireValue);
if (value === undefined) break field;
result.sumMin = value;
}
field: {
const wireValue = wireFields.get(6);
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.bytes(wireValue);
if (value === undefined) break field;
result.sumMax = value;
}
field: {
const wireValue = wireFields.get(7);
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.bool(wireValue);
if (value === undefined) break field;
result.sumClamp = value;
}
return result;
}