typia 5.2.0 → 5.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/executable/TypiaSetupWizard.js +13 -13
- package/lib/executable/TypiaSetupWizard.js.map +1 -1
- package/package.json +1 -1
- package/src/executable/TypiaSetupWizard.ts +15 -13
- package/src/factories/internal/metadata/emplace_metadata_object.ts +150 -150
- package/src/functional/$clone.ts +4 -4
- package/src/http.ts +1149 -1149
- package/src/json.ts +648 -648
- package/src/misc.ts +651 -651
- package/src/programmers/IsProgrammer.ts +252 -252
- package/src/programmers/TypiaProgrammer.ts +169 -169
- package/src/programmers/helpers/OptionPredicator.ts +15 -15
- package/src/programmers/json/JsonStringifyProgrammer.ts +964 -964
- package/src/protobuf.ts +887 -887
- package/src/transformers/ITransformOptions.ts +62 -62
package/src/protobuf.ts
CHANGED
|
@@ -1,887 +1,887 @@
|
|
|
1
|
-
import { Namespace } from "./functional/Namespace";
|
|
2
|
-
|
|
3
|
-
import { IValidation } from "./IValidation";
|
|
4
|
-
import { Resolved } from "./Resolved";
|
|
5
|
-
|
|
6
|
-
/* ===========================================================
|
|
7
|
-
PROTOCOL BUFFER
|
|
8
|
-
- MESSAGE
|
|
9
|
-
- DECODE
|
|
10
|
-
- ENCODE
|
|
11
|
-
- FACTORY FUNCTIONS
|
|
12
|
-
==============================================================
|
|
13
|
-
SCHEMA
|
|
14
|
-
----------------------------------------------------------- */
|
|
15
|
-
/**
|
|
16
|
-
* > You must configure the generic argument `T`.
|
|
17
|
-
*
|
|
18
|
-
* Protocol Buffer Message Schema.
|
|
19
|
-
*
|
|
20
|
-
* Creates a Protocol Buffer Message Schema from a TypeScript type. The message
|
|
21
|
-
* schema would be returned as a string value, and it can be used to share with
|
|
22
|
-
* other developers/languages/frameworks.
|
|
23
|
-
*
|
|
24
|
-
* For reference, Protocol Buffer has lots of restrictions, so that expression power
|
|
25
|
-
* of Protocol Buffer is not enough strong to fully meet the TypeScript type specs.
|
|
26
|
-
* In such reason, if you put a TypeScript type that is not compatible with Protocol
|
|
27
|
-
* Buffer, this function would throw compilation errors.
|
|
28
|
-
*
|
|
29
|
-
* - [Restrictions of Protocol Buffer](https://typia.io/docs/protobuf/message/#restrictions)
|
|
30
|
-
*
|
|
31
|
-
* @template T Target type
|
|
32
|
-
* @returns Protocol Buffer Message Schema.
|
|
33
|
-
*
|
|
34
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
35
|
-
*/
|
|
36
|
-
export function message(): never;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Protocol Buffer Message Schema.
|
|
40
|
-
*
|
|
41
|
-
* Creates a Protocol Buffer Message Schema from a TypeScript type. The message
|
|
42
|
-
* schema would be returned as a string value, and it can be used to share with
|
|
43
|
-
* other developers/languages/frameworks.
|
|
44
|
-
*
|
|
45
|
-
* For reference, Protocol Buffer has lots of restrictions, so that expression power
|
|
46
|
-
* of Protocol Buffer is not enough strong to fully meet the TypeScript type specs.
|
|
47
|
-
* In such reason, if you put a TypeScript type that is not compatible with Protocol
|
|
48
|
-
* Buffer, this function would throw compilation errors.
|
|
49
|
-
*
|
|
50
|
-
* @template T Target type
|
|
51
|
-
* @returns Protocol Buffer Message Schema.
|
|
52
|
-
*
|
|
53
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
54
|
-
*/
|
|
55
|
-
export function message<T>(): string;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @internal
|
|
59
|
-
*/
|
|
60
|
-
export function message(): never {
|
|
61
|
-
halt("message");
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/* -----------------------------------------------------------
|
|
65
|
-
DECODE
|
|
66
|
-
----------------------------------------------------------- */
|
|
67
|
-
/**
|
|
68
|
-
* > You must configure the generic argument `T`.
|
|
69
|
-
*
|
|
70
|
-
* Protocol Buffer Decoder.
|
|
71
|
-
*
|
|
72
|
-
* `typia.protobuf.decode()` is a function decoding a binary data of Protocol Buffer
|
|
73
|
-
* format to a TypeScript instance.
|
|
74
|
-
*
|
|
75
|
-
* For reference, as Protocol Buffer handles binary data directly, there's no way
|
|
76
|
-
* when `input` binary data was not encoded from the `T` typed value. In that case,
|
|
77
|
-
* unexpected behavior or internal error would be occured. Therefore, I recommend you
|
|
78
|
-
* to encode binary data of Protocol Buffer from type safe encode functions like below.
|
|
79
|
-
* Use {@link encode} function only when you can ensure it.
|
|
80
|
-
*
|
|
81
|
-
* - {@link assertEncode}
|
|
82
|
-
* - {@link isEncode}
|
|
83
|
-
* - {@link validateEncode}
|
|
84
|
-
*
|
|
85
|
-
* Also, `typia` is providing type safe decoders like {@link assertDecode}, but it
|
|
86
|
-
* is just for additional type validation like `number & Minimum<7>` or
|
|
87
|
-
* `string & Format<"uuid">` cases, that are represented by
|
|
88
|
-
* [custom tags](https://typia.io/docs/validators/tags). Thus, I repeat that,
|
|
89
|
-
* you've to ensure the type safety when using decoder functions.
|
|
90
|
-
*
|
|
91
|
-
* @template T Expected type of decoded value
|
|
92
|
-
* @param input Protobuf Buffer binary data
|
|
93
|
-
* @returns Decoded value
|
|
94
|
-
*
|
|
95
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
96
|
-
*/
|
|
97
|
-
export function decode(input: Uint8Array): never;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Protocol Buffer Decoder.
|
|
101
|
-
*
|
|
102
|
-
* `typia.protobuf.decode()` is a function decoding a binary data of Protocol Buffer
|
|
103
|
-
* format to a TypeScript instance.
|
|
104
|
-
*
|
|
105
|
-
* For reference, as Protocol Buffer handles binary data directly, there's no way
|
|
106
|
-
* when `input` binary data was not encoded from the `T` typed value. In that case,
|
|
107
|
-
* unexpected behavior or internal error would be occured. Therefore, I recommend you
|
|
108
|
-
* to encode binary data of Protocol Buffer from type safe encode functions like below.
|
|
109
|
-
* Use {@link encode} function only when you can ensure it.
|
|
110
|
-
*
|
|
111
|
-
* - {@link assertEncode}
|
|
112
|
-
* - {@link isEncode}
|
|
113
|
-
* - {@link validateEncode}
|
|
114
|
-
*
|
|
115
|
-
* Also, `typia` is providing type safe decoders like {@link assertDecode}, but it
|
|
116
|
-
* is just for additional type validation like `number & Minimum<7>` or
|
|
117
|
-
* `string & Format<"uuid">` cases, that are represented by
|
|
118
|
-
* [custom tags](https://typia.io/docs/validators/tags). Thus, I repeat that,
|
|
119
|
-
* you've to ensure the type safety when using decoder functions.
|
|
120
|
-
*
|
|
121
|
-
* @template T Expected type of decoded value
|
|
122
|
-
* @param input Protobuf Buffer binary data
|
|
123
|
-
* @returns Decoded value
|
|
124
|
-
*
|
|
125
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
126
|
-
*/
|
|
127
|
-
export function decode<T>(input: Uint8Array): Resolved<T>;
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* @internal
|
|
131
|
-
*/
|
|
132
|
-
export function decode(): never {
|
|
133
|
-
halt("decode");
|
|
134
|
-
}
|
|
135
|
-
Object.assign(decode, Namespace.protobuf.decode("decode"));
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* > You must configure the generic argument `T`.
|
|
139
|
-
*
|
|
140
|
-
* Protocol Buffer Decoder wity type assertion, but not safe.
|
|
141
|
-
*
|
|
142
|
-
* `typia.protobuf.assertDecode()` is a combination function of {@link decode} and
|
|
143
|
-
* {@link assert} function. Therefore, it decodes a binary data of Protocol Buffer to
|
|
144
|
-
* a TypeScript instance, and performs type assertion process. If decoded value is
|
|
145
|
-
* following the type `T`, it returns the decoded value. Otherwise, it throws
|
|
146
|
-
* {@link TypeGuardError} instead.
|
|
147
|
-
*
|
|
148
|
-
* However, note that, this validation is not always safe. It just performs additional
|
|
149
|
-
* type assertion like `number & Minimum<7>` or `string & Format<"uuid">` cases,
|
|
150
|
-
* that are represented by [custom tags](https://typia.io/docs/validators/tags).
|
|
151
|
-
* Therefore, when using `typia.protobuf.assertDecode<T>()` function, you have to
|
|
152
|
-
* ensure the type safety by yourself.
|
|
153
|
-
*
|
|
154
|
-
* In such type safety reason, I recommend you to use type safe encode functions.
|
|
155
|
-
*
|
|
156
|
-
* - {@link assertEncode}
|
|
157
|
-
* - {@link isEncode}
|
|
158
|
-
* - {@link validateEncode}
|
|
159
|
-
*
|
|
160
|
-
* @template T Expected type of decoded value
|
|
161
|
-
* @param input Protobuf Buffer binary data
|
|
162
|
-
* @returns Decoded value
|
|
163
|
-
*
|
|
164
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
165
|
-
*/
|
|
166
|
-
export function assertDecode(input: Uint8Array): never;
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Protocol Buffer Decoder wity type assertion, but not safe.
|
|
170
|
-
*
|
|
171
|
-
* `typia.protobuf.assertDecode()` is a combination function of {@link decode} and
|
|
172
|
-
* {@link assert} function. Therefore, it decodes a binary data of Protocol Buffer to
|
|
173
|
-
* a TypeScript instance, and performs type assertion process. If decoded value is
|
|
174
|
-
* following the type `T`, it returns the decoded value. Otherwise, it throws
|
|
175
|
-
* {@link TypeGuardError} instead.
|
|
176
|
-
*
|
|
177
|
-
* However, note that, this validation is not always safe. It just performs additional
|
|
178
|
-
* type assertion like `number & Minimum<7>` or `string & Format<"uuid">` cases,
|
|
179
|
-
* that are represented by [custom tags](https://typia.io/docs/validators/tags).
|
|
180
|
-
* Therefore, when using `typia.protobuf.assertDecode<T>()` function, you have to
|
|
181
|
-
* ensure the type safety by yourself.
|
|
182
|
-
*
|
|
183
|
-
* In such type safety reason, I recommend you to use type safe encode functions.
|
|
184
|
-
*
|
|
185
|
-
* - {@link assertEncode}
|
|
186
|
-
* - {@link isEncode}
|
|
187
|
-
* - {@link validateEncode}
|
|
188
|
-
*
|
|
189
|
-
* @template T Expected type of decoded value
|
|
190
|
-
* @param input Protobuf Buffer binary data
|
|
191
|
-
* @returns Decoded value
|
|
192
|
-
*
|
|
193
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
194
|
-
*/
|
|
195
|
-
export function assertDecode<T>(input: Uint8Array): Resolved<T>;
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* @internal
|
|
199
|
-
*/
|
|
200
|
-
export function assertDecode(): never {
|
|
201
|
-
halt("assertDecode");
|
|
202
|
-
}
|
|
203
|
-
Object.assign(assertDecode, Namespace.assert("protobuf.assertDecode"));
|
|
204
|
-
Object.assign(assertDecode, Namespace.protobuf.decode("assertDecode"));
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* > You must configure the generic argument `T`.
|
|
208
|
-
*
|
|
209
|
-
* Protocol Buffer Decoder wity type checking, but not safe.
|
|
210
|
-
*
|
|
211
|
-
* `typia.protobuf.isDecode()` is a combination function of {@link decode} and
|
|
212
|
-
* {@link is} function. Therefore, it decodes a binary data of Protocol Buffer to
|
|
213
|
-
* a TypeScript instance, and performs type checking process. If decoded value is
|
|
214
|
-
* following the type `T`, it returns the decoded value. Otherwise, it returns
|
|
215
|
-
* `null` value instead.
|
|
216
|
-
*
|
|
217
|
-
* However, note that, this validation is not always safe. It just performs additional
|
|
218
|
-
* type checking like `number & Minimum<7>` or `string & Format<"uuid">` cases,
|
|
219
|
-
* that are represented by [custom tags](https://typia.io/docs/validators/tags).
|
|
220
|
-
* Therefore, when using `typia.protobuf.isDecode<T>()` function, you have to
|
|
221
|
-
* ensure the type safety by yourself.
|
|
222
|
-
*
|
|
223
|
-
* In such type safety reason, I recommend you to use type safe encode functions.
|
|
224
|
-
*
|
|
225
|
-
* - {@link assertEncode}
|
|
226
|
-
* - {@link isEncode}
|
|
227
|
-
* - {@link validateEncode}
|
|
228
|
-
*
|
|
229
|
-
* @template T Expected type of decoded value
|
|
230
|
-
* @param input Protobuf Buffer binary data
|
|
231
|
-
* @returns Decoded value
|
|
232
|
-
*
|
|
233
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
234
|
-
*/
|
|
235
|
-
export function isDecode(input: Uint8Array): never;
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Protocol Buffer Decoder wity type checking, but not safe.
|
|
239
|
-
*
|
|
240
|
-
* `typia.protobuf.isDecode()` is a combination function of {@link decode} and
|
|
241
|
-
* {@link is} function. Therefore, it decodes a binary data of Protocol Buffer to
|
|
242
|
-
* a TypeScript instance, and performs type checking process. If decoded value is
|
|
243
|
-
* following the type `T`, it returns the decoded value. Otherwise, it returns
|
|
244
|
-
* `null` value instead.
|
|
245
|
-
*
|
|
246
|
-
* However, note that, this validation is not always safe. It just performs additional
|
|
247
|
-
* type checking like `number & Minimum<7>` or `string & Format<"uuid">` cases,
|
|
248
|
-
* that are represented by [custom tags](https://typia.io/docs/validators/tags).
|
|
249
|
-
* Therefore, when using `typia.protobuf.isDecode<T>()` function, you have to
|
|
250
|
-
* ensure the type safety by yourself.
|
|
251
|
-
*
|
|
252
|
-
* In such type safety reason, I recommend you to use type safe encode functions.
|
|
253
|
-
*
|
|
254
|
-
* - {@link assertEncode}
|
|
255
|
-
* - {@link isEncode}
|
|
256
|
-
* - {@link validateEncode}
|
|
257
|
-
*
|
|
258
|
-
* @template T Expected type of decoded value
|
|
259
|
-
* @param input Protobuf Buffer binary data
|
|
260
|
-
* @returns Decoded value
|
|
261
|
-
*
|
|
262
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
263
|
-
*/
|
|
264
|
-
export function isDecode<T>(input: Uint8Array): Resolved<T> | null;
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* @internal
|
|
268
|
-
*/
|
|
269
|
-
export function isDecode(): never {
|
|
270
|
-
halt("isDecode");
|
|
271
|
-
}
|
|
272
|
-
Object.assign(isDecode, Namespace.is());
|
|
273
|
-
Object.assign(isDecode, Namespace.protobuf.decode("isDecode"));
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* > You must configure the generic argument `T`.
|
|
277
|
-
*
|
|
278
|
-
* Protocol Buffer Decoder wity type validation, but not safe.
|
|
279
|
-
*
|
|
280
|
-
* `typia.protobuf.validateDecode()` is a combination function of {@link decode} and
|
|
281
|
-
* {@link validate} function. Therefore, it decodes a binary data of Protocol Buffer to
|
|
282
|
-
* a TypeScript instance, and performs type validation process. If decoded value is
|
|
283
|
-
* following the type `T`, it returns the decoded value with
|
|
284
|
-
* {@link IValidation.ISuccess} typed instance. Otherwise, it returns
|
|
285
|
-
* {@link IValidation.IFailure} value instead with detailed error reasons.
|
|
286
|
-
*
|
|
287
|
-
* However, note that, this validation is not always safe. It just performs additional
|
|
288
|
-
* type validation like `number & Minimum<7>` or `string & Format<"uuid">` cases,
|
|
289
|
-
* that are represented by [custom tags](https://typia.io/docs/validators/tags).
|
|
290
|
-
* Therefore, when using `typia.protobuf.validateDecode<T>()` function, you have to
|
|
291
|
-
* ensure the type safety by yourself.
|
|
292
|
-
*
|
|
293
|
-
* In such type safety reason, I recommend you to use type safe encode functions.
|
|
294
|
-
*
|
|
295
|
-
* - {@link assertEncode}
|
|
296
|
-
* - {@link isEncode}
|
|
297
|
-
* - {@link validateEncode}
|
|
298
|
-
*
|
|
299
|
-
* @template T Expected type of decoded value
|
|
300
|
-
* @param input Protobuf Buffer binary data
|
|
301
|
-
* @returns Decoded value
|
|
302
|
-
*
|
|
303
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
304
|
-
*/
|
|
305
|
-
export function validateDecode(input: Uint8Array): never;
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Protocol Buffer Decoder wity type validation, but not safe.
|
|
309
|
-
*
|
|
310
|
-
* `typia.protobuf.validateDecode()` is a combination function of {@link decode} and
|
|
311
|
-
* {@link validate} function. Therefore, it decodes a binary data of Protocol Buffer to
|
|
312
|
-
* a TypeScript instance, and performs type validation process. If decoded value is
|
|
313
|
-
* following the type `T`, it returns the decoded value with
|
|
314
|
-
* {@link IValidation.ISuccess} typed instance. Otherwise, it returns
|
|
315
|
-
* {@link IValidation.IFailure} value instead with detailed error reasons.
|
|
316
|
-
*
|
|
317
|
-
* However, note that, this validation is not always safe. It just performs additional
|
|
318
|
-
* type validation like `number & Minimum<7>` or `string & Format<"uuid">` cases,
|
|
319
|
-
* that are represented by [custom tags](https://typia.io/docs/validators/tags).
|
|
320
|
-
* Therefore, when using `typia.protobuf.validateDecode<T>()` function, you have to
|
|
321
|
-
* ensure the type safety by yourself.
|
|
322
|
-
*
|
|
323
|
-
* In such type safety reason, I recommend you to use type safe encode functions.
|
|
324
|
-
*
|
|
325
|
-
* - {@link assertEncode}
|
|
326
|
-
* - {@link isEncode}
|
|
327
|
-
* - {@link validateEncode}
|
|
328
|
-
*
|
|
329
|
-
* @template T Expected type of decoded value
|
|
330
|
-
* @param input Protobuf Buffer binary data
|
|
331
|
-
* @returns Decoded value
|
|
332
|
-
*
|
|
333
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
334
|
-
*/
|
|
335
|
-
export function validateDecode<T>(input: Uint8Array): IValidation<Resolved<T>>;
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* @internal
|
|
339
|
-
*/
|
|
340
|
-
export function validateDecode(): never {
|
|
341
|
-
halt("validateDecode");
|
|
342
|
-
}
|
|
343
|
-
Object.assign(validateDecode, Namespace.validate());
|
|
344
|
-
Object.assign(validateDecode, Namespace.protobuf.decode("validateDecode"));
|
|
345
|
-
|
|
346
|
-
/* -----------------------------------------------------------
|
|
347
|
-
ENCODE
|
|
348
|
-
----------------------------------------------------------- */
|
|
349
|
-
/**
|
|
350
|
-
* Protocol Buffer Encoder.
|
|
351
|
-
*
|
|
352
|
-
* Converts an input value to a binary data of Protocol Buffer format.
|
|
353
|
-
*
|
|
354
|
-
* For reference, this `typia.protobuf.encode()` does not validate the `input` value.
|
|
355
|
-
* It just believes that the `input` value is valid and converts it to a binary data
|
|
356
|
-
* directly. Therefore, if you can't ensure the `input` value type, it would better to
|
|
357
|
-
* call one of below functions intead.
|
|
358
|
-
*
|
|
359
|
-
* - {@link assertEncode}
|
|
360
|
-
* - {@link isEncode}
|
|
361
|
-
* - {@link validateEncode}
|
|
362
|
-
*
|
|
363
|
-
* By the way, you know what? Expression power of Protocol Buffer is not enough strong
|
|
364
|
-
* to fully meet the TypeScript type specs. In such reason, if you put a TypeScript
|
|
365
|
-
* type that is not compatible with Protocol Buffer, this function would throw
|
|
366
|
-
* compilation errors.
|
|
367
|
-
*
|
|
368
|
-
* - [Restrictions of Protocol Buffer](https://typia.io/docs/protobuf/message/#restrictions)
|
|
369
|
-
*
|
|
370
|
-
* @template T Type of the value input
|
|
371
|
-
* @param input A value to encode
|
|
372
|
-
* @returns Encoded binary data
|
|
373
|
-
*
|
|
374
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
375
|
-
*/
|
|
376
|
-
export function encode<T>(input: T): Uint8Array;
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* @internal
|
|
380
|
-
*/
|
|
381
|
-
export function encode(): never {
|
|
382
|
-
halt("encode");
|
|
383
|
-
}
|
|
384
|
-
Object.assign(encode, Namespace.protobuf.encode("encode"));
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Protocol Buffer Encoder with type assertion.
|
|
388
|
-
*
|
|
389
|
-
* `typia.protobuf.assertEncode()` is a combination function of {@link assert} and
|
|
390
|
-
* {@link encode}.
|
|
391
|
-
*
|
|
392
|
-
* Therefore, it converts an `input` value to a binary data of
|
|
393
|
-
* Protocol Buffer, with type assertion. If `input` value is not valid, it throws
|
|
394
|
-
* {@link TypeGuardError}. Otherwise, there's no problem on the `input` value,
|
|
395
|
-
* Protocol Buffer binary data would be returned.
|
|
396
|
-
*
|
|
397
|
-
* If you can trust `input` value, or want to perform other type of validation, use
|
|
398
|
-
* below functions intead.
|
|
399
|
-
*
|
|
400
|
-
* - {@link encode}
|
|
401
|
-
* - {@link isEncode}
|
|
402
|
-
* - {@link validateEncode}
|
|
403
|
-
*
|
|
404
|
-
* By the way, you know what? Expression power of Protocol Buffer is not enough strong
|
|
405
|
-
* to fully meet the TypeScript type specs. In such reason, if you put a TypeScript
|
|
406
|
-
* type that is not compatible with Protocol Buffer, this function would throw
|
|
407
|
-
* compilation errors.
|
|
408
|
-
*
|
|
409
|
-
* - [Restrictions of Protocol Buffer](https://typia.io/docs/protobuf/message/#restrictions)
|
|
410
|
-
*
|
|
411
|
-
* @template T Type of the value input
|
|
412
|
-
* @param input A value to encode
|
|
413
|
-
* @returns Encoded binary data
|
|
414
|
-
*
|
|
415
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
416
|
-
*/
|
|
417
|
-
export function assertEncode<T>(input: T): Uint8Array;
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* Protocol Buffer Encoder with type assertion.
|
|
421
|
-
*
|
|
422
|
-
* `typia.protobuf.assertEncode()` is a combination function of {@link assert} and
|
|
423
|
-
* {@link encode}.
|
|
424
|
-
*
|
|
425
|
-
* Therefore, it converts an `input` value to a binary data of
|
|
426
|
-
* Protocol Buffer, with type assertion. If `input` value is not valid, it throws
|
|
427
|
-
* {@link TypeGuardError}. Otherwise, there's no problem on the `input` value,
|
|
428
|
-
* Protocol Buffer binary data would be returned.
|
|
429
|
-
*
|
|
430
|
-
* If you can trust `input` value, or want to perform other type of validation, use
|
|
431
|
-
* below functions intead.
|
|
432
|
-
*
|
|
433
|
-
* - {@link encode}
|
|
434
|
-
* - {@link isEncode}
|
|
435
|
-
* - {@link validateEncode}
|
|
436
|
-
*
|
|
437
|
-
* By the way, you know what? Expression power of Protocol Buffer is not enough strong
|
|
438
|
-
* to fully meet the TypeScript type specs. In such reason, if you put a TypeScript
|
|
439
|
-
* type that is not compatible with Protocol Buffer, this function would throw
|
|
440
|
-
* compilation errors.
|
|
441
|
-
*
|
|
442
|
-
* - [Restrictions of Protocol Buffer](https://typia.io/docs/protobuf/message/#restrictions)
|
|
443
|
-
*
|
|
444
|
-
* @template T Type of the value input
|
|
445
|
-
* @param input A value to encode
|
|
446
|
-
* @returns Encoded binary data
|
|
447
|
-
*
|
|
448
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
449
|
-
*/
|
|
450
|
-
export function assertEncode<T>(input: unknown): Uint8Array;
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* @internal
|
|
454
|
-
*/
|
|
455
|
-
export function assertEncode(): never {
|
|
456
|
-
halt("assertEncode");
|
|
457
|
-
}
|
|
458
|
-
Object.assign(assertEncode, Namespace.assert("protobuf.assertEncode"));
|
|
459
|
-
Object.assign(assertEncode, Namespace.protobuf.encode("assertEncode"));
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* Protocol Buffer Encoder with type checking.
|
|
463
|
-
*
|
|
464
|
-
* `typia.protobuf.isEncode()` is a combination function of {@link is} and
|
|
465
|
-
* {@link encode}.
|
|
466
|
-
*
|
|
467
|
-
* Therefore, it converts an `input` value to a binary data of
|
|
468
|
-
* Protocol Buffer, with type checking. If `input` value is not valid, it returns
|
|
469
|
-
* `null` value. Otherwise, there's no problem on the `input` value, Protocol
|
|
470
|
-
* Buffer binary data would be returned.
|
|
471
|
-
*
|
|
472
|
-
* If you can trust `input` value, or want to perform other type of validation, use
|
|
473
|
-
* below functions intead.
|
|
474
|
-
*
|
|
475
|
-
* - {@link encode}
|
|
476
|
-
* - {@link assertEncode}
|
|
477
|
-
* - {@link validateEncode}
|
|
478
|
-
*
|
|
479
|
-
* By the way, you know what? Expression power of Protocol Buffer is not enough strong
|
|
480
|
-
* to fully meet the TypeScript type specs. In such reason, if you put a TypeScript
|
|
481
|
-
* type that is not compatible with Protocol Buffer, this function would throw
|
|
482
|
-
* compilation errors.
|
|
483
|
-
*
|
|
484
|
-
* - [Restrictions of Protocol Buffer](https://typia.io/docs/protobuf/message/#restrictions)
|
|
485
|
-
*
|
|
486
|
-
* @template T Type of the value input
|
|
487
|
-
* @param input A value to encode
|
|
488
|
-
* @returns Encoded binary data
|
|
489
|
-
*
|
|
490
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
491
|
-
*/
|
|
492
|
-
export function isEncode<T>(input: T): Uint8Array | null;
|
|
493
|
-
|
|
494
|
-
/**
|
|
495
|
-
* Protocol Buffer Encoder with type checking.
|
|
496
|
-
*
|
|
497
|
-
* `typia.protobuf.isEncode()` is a combination function of {@link is} and
|
|
498
|
-
* {@link encode}.
|
|
499
|
-
*
|
|
500
|
-
* Therefore, it converts an `input` value to a binary data of
|
|
501
|
-
* Protocol Buffer, with type checking. If `input` value is not valid, it returns
|
|
502
|
-
* `null` value. Otherwise, there's no problem on the `input` value, Protocol
|
|
503
|
-
* Buffer binary data would be returned.
|
|
504
|
-
*
|
|
505
|
-
* If you can trust `input` value, or want to perform other type of validation, use
|
|
506
|
-
* below functions intead.
|
|
507
|
-
*
|
|
508
|
-
* - {@link encode}
|
|
509
|
-
* - {@link assertEncode}
|
|
510
|
-
* - {@link validateEncode}
|
|
511
|
-
*
|
|
512
|
-
* By the way, you know what? Expression power of Protocol Buffer is not enough strong
|
|
513
|
-
* to fully meet the TypeScript type specs. In such reason, if you put a TypeScript
|
|
514
|
-
* type that is not compatible with Protocol Buffer, this function would throw
|
|
515
|
-
* compilation errors.
|
|
516
|
-
*
|
|
517
|
-
* - [Restrictions of Protocol Buffer](https://typia.io/docs/protobuf/message/#restrictions)
|
|
518
|
-
*
|
|
519
|
-
* @template T Type of the value input
|
|
520
|
-
* @param input A value to encode
|
|
521
|
-
* @returns Encoded binary data
|
|
522
|
-
*
|
|
523
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
524
|
-
*/
|
|
525
|
-
export function isEncode<T>(input: unknown): Uint8Array | null;
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* @internal
|
|
529
|
-
*/
|
|
530
|
-
export function isEncode(): never {
|
|
531
|
-
halt("isEncode");
|
|
532
|
-
}
|
|
533
|
-
Object.assign(isEncode, Namespace.is());
|
|
534
|
-
Object.assign(isEncode, Namespace.protobuf.encode("isEncode"));
|
|
535
|
-
|
|
536
|
-
/**
|
|
537
|
-
* Protocol Buffer Encoder with type validation.
|
|
538
|
-
*
|
|
539
|
-
* `typia.protobuf.validateEncode()` is a combination function of
|
|
540
|
-
* {@link validation} and {@link encode}.
|
|
541
|
-
*
|
|
542
|
-
* Therefore, it converts an `input` value to a binary data of
|
|
543
|
-
* Protocol Buffer, with type validation. If `input` value is not valid, it returns
|
|
544
|
-
* {@link IValidation.IFailure} value with detailed error reasons. Otherwise, there's
|
|
545
|
-
* no problem on the `input` value, Protocol Buffer binary data would be stored in
|
|
546
|
-
* `data` property of the output {@link IValidation.ISuccess} instance.
|
|
547
|
-
*
|
|
548
|
-
* If you can trust `input` value, or want to perform other type of validation, use
|
|
549
|
-
* below functions intead.
|
|
550
|
-
*
|
|
551
|
-
* - {@link encode}
|
|
552
|
-
* - {@link assertEncode}
|
|
553
|
-
* - {@link isEncode}
|
|
554
|
-
*
|
|
555
|
-
* By the way, you know what? Expression power of Protocol Buffer is not enough strong
|
|
556
|
-
* to fully meet the TypeScript type specs. In such reason, if you put a TypeScript
|
|
557
|
-
* type that is not compatible with Protocol Buffer, this function would throw
|
|
558
|
-
* compilation errors.
|
|
559
|
-
*
|
|
560
|
-
* - [Restrictions of Protocol Buffer](https://typia.io/docs/protobuf/message/#restrictions)
|
|
561
|
-
*
|
|
562
|
-
* @template T Type of the value input
|
|
563
|
-
* @param input A value to encode
|
|
564
|
-
* @returns Encoded binary data
|
|
565
|
-
*
|
|
566
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
567
|
-
*/
|
|
568
|
-
export function validateEncode<T>(input: T): IValidation<Uint8Array>;
|
|
569
|
-
|
|
570
|
-
/**
|
|
571
|
-
* Protocol Buffer Encoder with type validation.
|
|
572
|
-
*
|
|
573
|
-
* `typia.protobuf.validateEncode()` is a combination function of
|
|
574
|
-
* {@link validation} and {@link encode}.
|
|
575
|
-
*
|
|
576
|
-
* Therefore, it converts an `input` value to a binary data of
|
|
577
|
-
* Protocol Buffer, with type validation. If `input` value is not valid, it returns
|
|
578
|
-
* {@link IValidation.IFailure} value with detailed error reasons. Otherwise, there's
|
|
579
|
-
* no problem on the `input` value, Protocol Buffer binary data would be stored in
|
|
580
|
-
* `data` property of the output {@link IValidation.ISuccess} instance.
|
|
581
|
-
*
|
|
582
|
-
* If you can trust `input` value, or want to perform other type of validation, use
|
|
583
|
-
* below functions intead.
|
|
584
|
-
*
|
|
585
|
-
* - {@link encode}
|
|
586
|
-
* - {@link assertEncode}
|
|
587
|
-
* - {@link isEncode}
|
|
588
|
-
*
|
|
589
|
-
* By the way, you know what? Expression power of Protocol Buffer is not enough strong
|
|
590
|
-
* to fully meet the TypeScript type specs. In such reason, if you put a TypeScript
|
|
591
|
-
* type that is not compatible with Protocol Buffer, this function would throw
|
|
592
|
-
* compilation errors.
|
|
593
|
-
*
|
|
594
|
-
* - [Restrictions of Protocol Buffer](https://typia.io/docs/protobuf/message/#restrictions)
|
|
595
|
-
*
|
|
596
|
-
* @template T Type of the value input
|
|
597
|
-
* @param input A value to encode
|
|
598
|
-
* @returns Encoded binary data
|
|
599
|
-
*
|
|
600
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
601
|
-
*/
|
|
602
|
-
export function validateEncode<T>(input: unknown): IValidation<Uint8Array>;
|
|
603
|
-
|
|
604
|
-
/**
|
|
605
|
-
* @internal
|
|
606
|
-
*/
|
|
607
|
-
export function validateEncode(): never {
|
|
608
|
-
halt("validateEncode");
|
|
609
|
-
}
|
|
610
|
-
Object.assign(validateEncode, Namespace.validate());
|
|
611
|
-
Object.assign(validateEncode, Namespace.protobuf.encode("validateEncode"));
|
|
612
|
-
|
|
613
|
-
/* -----------------------------------------------------------
|
|
614
|
-
FACTORY FUNCTIONS
|
|
615
|
-
----------------------------------------------------------- */
|
|
616
|
-
/**
|
|
617
|
-
* Creates a reusable {@link decode} function.
|
|
618
|
-
*
|
|
619
|
-
* @danger You must configure the generic argument `T`
|
|
620
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
621
|
-
* @throws compile error
|
|
622
|
-
*
|
|
623
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
624
|
-
*/
|
|
625
|
-
export function createDecode(): never;
|
|
626
|
-
|
|
627
|
-
/**
|
|
628
|
-
* Creates a reusable {@link decode} function.
|
|
629
|
-
*
|
|
630
|
-
* @template T Target type
|
|
631
|
-
* @returns A reusable `decode` function
|
|
632
|
-
*
|
|
633
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
634
|
-
*/
|
|
635
|
-
export function createDecode<T>(): (input: Uint8Array) => Resolved<T>;
|
|
636
|
-
|
|
637
|
-
/**
|
|
638
|
-
* @internal
|
|
639
|
-
*/
|
|
640
|
-
export function createDecode<T>(): (input: Uint8Array) => Resolved<T> {
|
|
641
|
-
halt("createDecode");
|
|
642
|
-
}
|
|
643
|
-
Object.assign(createDecode, Namespace.protobuf.decode("createDecode"));
|
|
644
|
-
|
|
645
|
-
/**
|
|
646
|
-
* Creates a reusable {@link isDecode} function.
|
|
647
|
-
*
|
|
648
|
-
* @danger You must configure the generic argument `T`
|
|
649
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
650
|
-
* @throws compile error
|
|
651
|
-
*
|
|
652
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
653
|
-
*/
|
|
654
|
-
export function createIsDecode(): never;
|
|
655
|
-
|
|
656
|
-
/**
|
|
657
|
-
* Creates a reusable {@link isDecode} function.
|
|
658
|
-
*
|
|
659
|
-
* @template T Target type
|
|
660
|
-
* @returns A reusable `isDecode` function
|
|
661
|
-
*
|
|
662
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
663
|
-
*/
|
|
664
|
-
export function createIsDecode<T>(): (input: Uint8Array) => Resolved<T> | null;
|
|
665
|
-
|
|
666
|
-
/**
|
|
667
|
-
* @internal
|
|
668
|
-
*/
|
|
669
|
-
export function createIsDecode<T>(): (input: Uint8Array) => Resolved<T> | null {
|
|
670
|
-
halt("createIsDecode");
|
|
671
|
-
}
|
|
672
|
-
Object.assign(createIsDecode, Namespace.is());
|
|
673
|
-
Object.assign(createIsDecode, Namespace.protobuf.decode("createIsDecode"));
|
|
674
|
-
|
|
675
|
-
/**
|
|
676
|
-
* Creates a reusable {@link assertDecode} function.
|
|
677
|
-
*
|
|
678
|
-
* @danger You must configure the generic argument `T`
|
|
679
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
680
|
-
* @throws compile error
|
|
681
|
-
*
|
|
682
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
683
|
-
*/
|
|
684
|
-
export function createAssertDecode(): never;
|
|
685
|
-
|
|
686
|
-
/**
|
|
687
|
-
* Creates a reusable {@link assertDecode} function.
|
|
688
|
-
*
|
|
689
|
-
* @template T Target type
|
|
690
|
-
* @returns A reusable `assertDecode` function
|
|
691
|
-
*
|
|
692
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
693
|
-
*/
|
|
694
|
-
export function createAssertDecode<T>(): (input: Uint8Array) => Resolved<T>;
|
|
695
|
-
|
|
696
|
-
/**
|
|
697
|
-
* @internal
|
|
698
|
-
*/
|
|
699
|
-
export function createAssertDecode<T>(): (input: Uint8Array) => Resolved<T> {
|
|
700
|
-
halt("createAssertDecode");
|
|
701
|
-
}
|
|
702
|
-
Object.assign(
|
|
703
|
-
createAssertDecode,
|
|
704
|
-
Namespace.assert("protobuf.createAssertDecode"),
|
|
705
|
-
);
|
|
706
|
-
Object.assign(
|
|
707
|
-
createAssertDecode,
|
|
708
|
-
Namespace.protobuf.decode("createAssertDecode"),
|
|
709
|
-
);
|
|
710
|
-
|
|
711
|
-
/**
|
|
712
|
-
* Creates a reusable {@link validateDecode} function.
|
|
713
|
-
*
|
|
714
|
-
* @danger You must configure the generic argument `T`
|
|
715
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
716
|
-
* @throws compile error
|
|
717
|
-
*
|
|
718
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
719
|
-
*/
|
|
720
|
-
export function createValidateDecode(): never;
|
|
721
|
-
|
|
722
|
-
/**
|
|
723
|
-
* Creates a reusable {@link validateDecode} function.
|
|
724
|
-
*
|
|
725
|
-
* @template T Target type
|
|
726
|
-
* @returns A reusable `validateDecode` function
|
|
727
|
-
*
|
|
728
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
729
|
-
*/
|
|
730
|
-
export function createValidateDecode<T>(): (
|
|
731
|
-
input: Uint8Array,
|
|
732
|
-
) => IValidation<Resolved<T>>;
|
|
733
|
-
|
|
734
|
-
/**
|
|
735
|
-
* @internal
|
|
736
|
-
*/
|
|
737
|
-
export function createValidateDecode<T>(): (
|
|
738
|
-
input: Uint8Array,
|
|
739
|
-
) => IValidation<Resolved<T>> {
|
|
740
|
-
halt("createValidateDecode");
|
|
741
|
-
}
|
|
742
|
-
Object.assign(createValidateDecode, Namespace.validate());
|
|
743
|
-
Object.assign(
|
|
744
|
-
createValidateDecode,
|
|
745
|
-
Namespace.protobuf.decode("createValidateDecode"),
|
|
746
|
-
);
|
|
747
|
-
|
|
748
|
-
/**
|
|
749
|
-
* Creates a reusable {@link encode} function.
|
|
750
|
-
*
|
|
751
|
-
* @danger You must configure the generic argument `T`
|
|
752
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
753
|
-
* @throws compile error
|
|
754
|
-
*
|
|
755
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
756
|
-
*/
|
|
757
|
-
export function createEncode(): never;
|
|
758
|
-
|
|
759
|
-
/**
|
|
760
|
-
* Creates a reusable {@link encode} function.
|
|
761
|
-
*
|
|
762
|
-
* @template T Target type
|
|
763
|
-
* @returns A reusable `encode` function
|
|
764
|
-
*
|
|
765
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
766
|
-
*/
|
|
767
|
-
export function createEncode<T>(): (input: T) => Uint8Array;
|
|
768
|
-
|
|
769
|
-
/**
|
|
770
|
-
* @internal
|
|
771
|
-
*/
|
|
772
|
-
export function createEncode<T>(): (input: T) => Uint8Array {
|
|
773
|
-
halt("createEncode");
|
|
774
|
-
}
|
|
775
|
-
Object.assign(createEncode, Namespace.protobuf.encode("createEncode"));
|
|
776
|
-
|
|
777
|
-
/**
|
|
778
|
-
* Creates a reusable {@link isEncode} function.
|
|
779
|
-
*
|
|
780
|
-
* @danger You must configure the generic argument `T`
|
|
781
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
782
|
-
* @throws compile error
|
|
783
|
-
*
|
|
784
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
785
|
-
*/
|
|
786
|
-
export function createIsEncode(): never;
|
|
787
|
-
|
|
788
|
-
/**
|
|
789
|
-
* Creates a reusable {@link isEncode} function.
|
|
790
|
-
*
|
|
791
|
-
* @template T Target type
|
|
792
|
-
* @returns A reusable `isEncode` function
|
|
793
|
-
*
|
|
794
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
795
|
-
*/
|
|
796
|
-
export function createIsEncode<T>(): (input: T) => Uint8Array | null;
|
|
797
|
-
|
|
798
|
-
/**
|
|
799
|
-
* @internal
|
|
800
|
-
*/
|
|
801
|
-
export function createIsEncode<T>(): (input: T) => Uint8Array | null {
|
|
802
|
-
halt("createIsEncode");
|
|
803
|
-
}
|
|
804
|
-
Object.assign(createIsEncode, Namespace.is());
|
|
805
|
-
Object.assign(createIsEncode, Namespace.protobuf.encode("createIsEncode"));
|
|
806
|
-
|
|
807
|
-
/**
|
|
808
|
-
* Creates a reusable {@link assertEncode} function.
|
|
809
|
-
*
|
|
810
|
-
* @danger You must configure the generic argument `T`
|
|
811
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
812
|
-
* @throws compile error
|
|
813
|
-
*
|
|
814
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
815
|
-
*/
|
|
816
|
-
export function createAssertEncode(): never;
|
|
817
|
-
|
|
818
|
-
/**
|
|
819
|
-
* Creates a reusable {@link assertEncode} function.
|
|
820
|
-
*
|
|
821
|
-
* @template T Target type
|
|
822
|
-
* @returns A reusable `assertEncode` function
|
|
823
|
-
*
|
|
824
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
825
|
-
*/
|
|
826
|
-
export function createAssertEncode<T>(): (input: T) => Uint8Array;
|
|
827
|
-
|
|
828
|
-
/**
|
|
829
|
-
* @internal
|
|
830
|
-
*/
|
|
831
|
-
export function createAssertEncode<T>(): (input: T) => Uint8Array {
|
|
832
|
-
halt("createAssertEncode");
|
|
833
|
-
}
|
|
834
|
-
Object.assign(
|
|
835
|
-
createAssertEncode,
|
|
836
|
-
Namespace.assert("protobuf.createAssertEncode"),
|
|
837
|
-
);
|
|
838
|
-
Object.assign(
|
|
839
|
-
createAssertEncode,
|
|
840
|
-
Namespace.protobuf.encode("createAssertEncode"),
|
|
841
|
-
);
|
|
842
|
-
|
|
843
|
-
/**
|
|
844
|
-
* Creates a reusable {@link validateEncode} function.
|
|
845
|
-
*
|
|
846
|
-
* @danger You must configure the generic argument `T`
|
|
847
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
848
|
-
* @throws compile error
|
|
849
|
-
*
|
|
850
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
851
|
-
*/
|
|
852
|
-
export function createValidateEncode(): never;
|
|
853
|
-
|
|
854
|
-
/**
|
|
855
|
-
* Creates a reusable {@link validateEncode} function.
|
|
856
|
-
*
|
|
857
|
-
* @template T Target type
|
|
858
|
-
* @returns A reusable `validateEncode` function
|
|
859
|
-
*
|
|
860
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
861
|
-
*/
|
|
862
|
-
export function createValidateEncode<T>(): (
|
|
863
|
-
input: T,
|
|
864
|
-
) => IValidation<Uint8Array>;
|
|
865
|
-
|
|
866
|
-
/**
|
|
867
|
-
* @internal
|
|
868
|
-
*/
|
|
869
|
-
export function createValidateEncode<T>(): (
|
|
870
|
-
input: T,
|
|
871
|
-
) => IValidation<Uint8Array> {
|
|
872
|
-
halt("createValidateEncode");
|
|
873
|
-
}
|
|
874
|
-
Object.assign(createValidateEncode, Namespace.validate());
|
|
875
|
-
Object.assign(
|
|
876
|
-
createValidateEncode,
|
|
877
|
-
Namespace.protobuf.encode("createValidateEncode"),
|
|
878
|
-
);
|
|
879
|
-
|
|
880
|
-
/**
|
|
881
|
-
* @internal
|
|
882
|
-
*/
|
|
883
|
-
function halt(name: string): never {
|
|
884
|
-
throw new Error(
|
|
885
|
-
`Error on typia.protobuf.${name}(): no transform has been configured. Read and follow https://typia.io/docs/setup please.`,
|
|
886
|
-
);
|
|
887
|
-
}
|
|
1
|
+
import { Namespace } from "./functional/Namespace";
|
|
2
|
+
|
|
3
|
+
import { IValidation } from "./IValidation";
|
|
4
|
+
import { Resolved } from "./Resolved";
|
|
5
|
+
|
|
6
|
+
/* ===========================================================
|
|
7
|
+
PROTOCOL BUFFER
|
|
8
|
+
- MESSAGE
|
|
9
|
+
- DECODE
|
|
10
|
+
- ENCODE
|
|
11
|
+
- FACTORY FUNCTIONS
|
|
12
|
+
==============================================================
|
|
13
|
+
SCHEMA
|
|
14
|
+
----------------------------------------------------------- */
|
|
15
|
+
/**
|
|
16
|
+
* > You must configure the generic argument `T`.
|
|
17
|
+
*
|
|
18
|
+
* Protocol Buffer Message Schema.
|
|
19
|
+
*
|
|
20
|
+
* Creates a Protocol Buffer Message Schema from a TypeScript type. The message
|
|
21
|
+
* schema would be returned as a string value, and it can be used to share with
|
|
22
|
+
* other developers/languages/frameworks.
|
|
23
|
+
*
|
|
24
|
+
* For reference, Protocol Buffer has lots of restrictions, so that expression power
|
|
25
|
+
* of Protocol Buffer is not enough strong to fully meet the TypeScript type specs.
|
|
26
|
+
* In such reason, if you put a TypeScript type that is not compatible with Protocol
|
|
27
|
+
* Buffer, this function would throw compilation errors.
|
|
28
|
+
*
|
|
29
|
+
* - [Restrictions of Protocol Buffer](https://typia.io/docs/protobuf/message/#restrictions)
|
|
30
|
+
*
|
|
31
|
+
* @template T Target type
|
|
32
|
+
* @returns Protocol Buffer Message Schema.
|
|
33
|
+
*
|
|
34
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
35
|
+
*/
|
|
36
|
+
export function message(): never;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Protocol Buffer Message Schema.
|
|
40
|
+
*
|
|
41
|
+
* Creates a Protocol Buffer Message Schema from a TypeScript type. The message
|
|
42
|
+
* schema would be returned as a string value, and it can be used to share with
|
|
43
|
+
* other developers/languages/frameworks.
|
|
44
|
+
*
|
|
45
|
+
* For reference, Protocol Buffer has lots of restrictions, so that expression power
|
|
46
|
+
* of Protocol Buffer is not enough strong to fully meet the TypeScript type specs.
|
|
47
|
+
* In such reason, if you put a TypeScript type that is not compatible with Protocol
|
|
48
|
+
* Buffer, this function would throw compilation errors.
|
|
49
|
+
*
|
|
50
|
+
* @template T Target type
|
|
51
|
+
* @returns Protocol Buffer Message Schema.
|
|
52
|
+
*
|
|
53
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
54
|
+
*/
|
|
55
|
+
export function message<T>(): string;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
export function message(): never {
|
|
61
|
+
halt("message");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* -----------------------------------------------------------
|
|
65
|
+
DECODE
|
|
66
|
+
----------------------------------------------------------- */
|
|
67
|
+
/**
|
|
68
|
+
* > You must configure the generic argument `T`.
|
|
69
|
+
*
|
|
70
|
+
* Protocol Buffer Decoder.
|
|
71
|
+
*
|
|
72
|
+
* `typia.protobuf.decode()` is a function decoding a binary data of Protocol Buffer
|
|
73
|
+
* format to a TypeScript instance.
|
|
74
|
+
*
|
|
75
|
+
* For reference, as Protocol Buffer handles binary data directly, there's no way
|
|
76
|
+
* when `input` binary data was not encoded from the `T` typed value. In that case,
|
|
77
|
+
* unexpected behavior or internal error would be occured. Therefore, I recommend you
|
|
78
|
+
* to encode binary data of Protocol Buffer from type safe encode functions like below.
|
|
79
|
+
* Use {@link encode} function only when you can ensure it.
|
|
80
|
+
*
|
|
81
|
+
* - {@link assertEncode}
|
|
82
|
+
* - {@link isEncode}
|
|
83
|
+
* - {@link validateEncode}
|
|
84
|
+
*
|
|
85
|
+
* Also, `typia` is providing type safe decoders like {@link assertDecode}, but it
|
|
86
|
+
* is just for additional type validation like `number & Minimum<7>` or
|
|
87
|
+
* `string & Format<"uuid">` cases, that are represented by
|
|
88
|
+
* [custom tags](https://typia.io/docs/validators/tags). Thus, I repeat that,
|
|
89
|
+
* you've to ensure the type safety when using decoder functions.
|
|
90
|
+
*
|
|
91
|
+
* @template T Expected type of decoded value
|
|
92
|
+
* @param input Protobuf Buffer binary data
|
|
93
|
+
* @returns Decoded value
|
|
94
|
+
*
|
|
95
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
96
|
+
*/
|
|
97
|
+
export function decode(input: Uint8Array): never;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Protocol Buffer Decoder.
|
|
101
|
+
*
|
|
102
|
+
* `typia.protobuf.decode()` is a function decoding a binary data of Protocol Buffer
|
|
103
|
+
* format to a TypeScript instance.
|
|
104
|
+
*
|
|
105
|
+
* For reference, as Protocol Buffer handles binary data directly, there's no way
|
|
106
|
+
* when `input` binary data was not encoded from the `T` typed value. In that case,
|
|
107
|
+
* unexpected behavior or internal error would be occured. Therefore, I recommend you
|
|
108
|
+
* to encode binary data of Protocol Buffer from type safe encode functions like below.
|
|
109
|
+
* Use {@link encode} function only when you can ensure it.
|
|
110
|
+
*
|
|
111
|
+
* - {@link assertEncode}
|
|
112
|
+
* - {@link isEncode}
|
|
113
|
+
* - {@link validateEncode}
|
|
114
|
+
*
|
|
115
|
+
* Also, `typia` is providing type safe decoders like {@link assertDecode}, but it
|
|
116
|
+
* is just for additional type validation like `number & Minimum<7>` or
|
|
117
|
+
* `string & Format<"uuid">` cases, that are represented by
|
|
118
|
+
* [custom tags](https://typia.io/docs/validators/tags). Thus, I repeat that,
|
|
119
|
+
* you've to ensure the type safety when using decoder functions.
|
|
120
|
+
*
|
|
121
|
+
* @template T Expected type of decoded value
|
|
122
|
+
* @param input Protobuf Buffer binary data
|
|
123
|
+
* @returns Decoded value
|
|
124
|
+
*
|
|
125
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
126
|
+
*/
|
|
127
|
+
export function decode<T>(input: Uint8Array): Resolved<T>;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @internal
|
|
131
|
+
*/
|
|
132
|
+
export function decode(): never {
|
|
133
|
+
halt("decode");
|
|
134
|
+
}
|
|
135
|
+
Object.assign(decode, Namespace.protobuf.decode("decode"));
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* > You must configure the generic argument `T`.
|
|
139
|
+
*
|
|
140
|
+
* Protocol Buffer Decoder wity type assertion, but not safe.
|
|
141
|
+
*
|
|
142
|
+
* `typia.protobuf.assertDecode()` is a combination function of {@link decode} and
|
|
143
|
+
* {@link assert} function. Therefore, it decodes a binary data of Protocol Buffer to
|
|
144
|
+
* a TypeScript instance, and performs type assertion process. If decoded value is
|
|
145
|
+
* following the type `T`, it returns the decoded value. Otherwise, it throws
|
|
146
|
+
* {@link TypeGuardError} instead.
|
|
147
|
+
*
|
|
148
|
+
* However, note that, this validation is not always safe. It just performs additional
|
|
149
|
+
* type assertion like `number & Minimum<7>` or `string & Format<"uuid">` cases,
|
|
150
|
+
* that are represented by [custom tags](https://typia.io/docs/validators/tags).
|
|
151
|
+
* Therefore, when using `typia.protobuf.assertDecode<T>()` function, you have to
|
|
152
|
+
* ensure the type safety by yourself.
|
|
153
|
+
*
|
|
154
|
+
* In such type safety reason, I recommend you to use type safe encode functions.
|
|
155
|
+
*
|
|
156
|
+
* - {@link assertEncode}
|
|
157
|
+
* - {@link isEncode}
|
|
158
|
+
* - {@link validateEncode}
|
|
159
|
+
*
|
|
160
|
+
* @template T Expected type of decoded value
|
|
161
|
+
* @param input Protobuf Buffer binary data
|
|
162
|
+
* @returns Decoded value
|
|
163
|
+
*
|
|
164
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
165
|
+
*/
|
|
166
|
+
export function assertDecode(input: Uint8Array): never;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Protocol Buffer Decoder wity type assertion, but not safe.
|
|
170
|
+
*
|
|
171
|
+
* `typia.protobuf.assertDecode()` is a combination function of {@link decode} and
|
|
172
|
+
* {@link assert} function. Therefore, it decodes a binary data of Protocol Buffer to
|
|
173
|
+
* a TypeScript instance, and performs type assertion process. If decoded value is
|
|
174
|
+
* following the type `T`, it returns the decoded value. Otherwise, it throws
|
|
175
|
+
* {@link TypeGuardError} instead.
|
|
176
|
+
*
|
|
177
|
+
* However, note that, this validation is not always safe. It just performs additional
|
|
178
|
+
* type assertion like `number & Minimum<7>` or `string & Format<"uuid">` cases,
|
|
179
|
+
* that are represented by [custom tags](https://typia.io/docs/validators/tags).
|
|
180
|
+
* Therefore, when using `typia.protobuf.assertDecode<T>()` function, you have to
|
|
181
|
+
* ensure the type safety by yourself.
|
|
182
|
+
*
|
|
183
|
+
* In such type safety reason, I recommend you to use type safe encode functions.
|
|
184
|
+
*
|
|
185
|
+
* - {@link assertEncode}
|
|
186
|
+
* - {@link isEncode}
|
|
187
|
+
* - {@link validateEncode}
|
|
188
|
+
*
|
|
189
|
+
* @template T Expected type of decoded value
|
|
190
|
+
* @param input Protobuf Buffer binary data
|
|
191
|
+
* @returns Decoded value
|
|
192
|
+
*
|
|
193
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
194
|
+
*/
|
|
195
|
+
export function assertDecode<T>(input: Uint8Array): Resolved<T>;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* @internal
|
|
199
|
+
*/
|
|
200
|
+
export function assertDecode(): never {
|
|
201
|
+
halt("assertDecode");
|
|
202
|
+
}
|
|
203
|
+
Object.assign(assertDecode, Namespace.assert("protobuf.assertDecode"));
|
|
204
|
+
Object.assign(assertDecode, Namespace.protobuf.decode("assertDecode"));
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* > You must configure the generic argument `T`.
|
|
208
|
+
*
|
|
209
|
+
* Protocol Buffer Decoder wity type checking, but not safe.
|
|
210
|
+
*
|
|
211
|
+
* `typia.protobuf.isDecode()` is a combination function of {@link decode} and
|
|
212
|
+
* {@link is} function. Therefore, it decodes a binary data of Protocol Buffer to
|
|
213
|
+
* a TypeScript instance, and performs type checking process. If decoded value is
|
|
214
|
+
* following the type `T`, it returns the decoded value. Otherwise, it returns
|
|
215
|
+
* `null` value instead.
|
|
216
|
+
*
|
|
217
|
+
* However, note that, this validation is not always safe. It just performs additional
|
|
218
|
+
* type checking like `number & Minimum<7>` or `string & Format<"uuid">` cases,
|
|
219
|
+
* that are represented by [custom tags](https://typia.io/docs/validators/tags).
|
|
220
|
+
* Therefore, when using `typia.protobuf.isDecode<T>()` function, you have to
|
|
221
|
+
* ensure the type safety by yourself.
|
|
222
|
+
*
|
|
223
|
+
* In such type safety reason, I recommend you to use type safe encode functions.
|
|
224
|
+
*
|
|
225
|
+
* - {@link assertEncode}
|
|
226
|
+
* - {@link isEncode}
|
|
227
|
+
* - {@link validateEncode}
|
|
228
|
+
*
|
|
229
|
+
* @template T Expected type of decoded value
|
|
230
|
+
* @param input Protobuf Buffer binary data
|
|
231
|
+
* @returns Decoded value
|
|
232
|
+
*
|
|
233
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
234
|
+
*/
|
|
235
|
+
export function isDecode(input: Uint8Array): never;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Protocol Buffer Decoder wity type checking, but not safe.
|
|
239
|
+
*
|
|
240
|
+
* `typia.protobuf.isDecode()` is a combination function of {@link decode} and
|
|
241
|
+
* {@link is} function. Therefore, it decodes a binary data of Protocol Buffer to
|
|
242
|
+
* a TypeScript instance, and performs type checking process. If decoded value is
|
|
243
|
+
* following the type `T`, it returns the decoded value. Otherwise, it returns
|
|
244
|
+
* `null` value instead.
|
|
245
|
+
*
|
|
246
|
+
* However, note that, this validation is not always safe. It just performs additional
|
|
247
|
+
* type checking like `number & Minimum<7>` or `string & Format<"uuid">` cases,
|
|
248
|
+
* that are represented by [custom tags](https://typia.io/docs/validators/tags).
|
|
249
|
+
* Therefore, when using `typia.protobuf.isDecode<T>()` function, you have to
|
|
250
|
+
* ensure the type safety by yourself.
|
|
251
|
+
*
|
|
252
|
+
* In such type safety reason, I recommend you to use type safe encode functions.
|
|
253
|
+
*
|
|
254
|
+
* - {@link assertEncode}
|
|
255
|
+
* - {@link isEncode}
|
|
256
|
+
* - {@link validateEncode}
|
|
257
|
+
*
|
|
258
|
+
* @template T Expected type of decoded value
|
|
259
|
+
* @param input Protobuf Buffer binary data
|
|
260
|
+
* @returns Decoded value
|
|
261
|
+
*
|
|
262
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
263
|
+
*/
|
|
264
|
+
export function isDecode<T>(input: Uint8Array): Resolved<T> | null;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* @internal
|
|
268
|
+
*/
|
|
269
|
+
export function isDecode(): never {
|
|
270
|
+
halt("isDecode");
|
|
271
|
+
}
|
|
272
|
+
Object.assign(isDecode, Namespace.is());
|
|
273
|
+
Object.assign(isDecode, Namespace.protobuf.decode("isDecode"));
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* > You must configure the generic argument `T`.
|
|
277
|
+
*
|
|
278
|
+
* Protocol Buffer Decoder wity type validation, but not safe.
|
|
279
|
+
*
|
|
280
|
+
* `typia.protobuf.validateDecode()` is a combination function of {@link decode} and
|
|
281
|
+
* {@link validate} function. Therefore, it decodes a binary data of Protocol Buffer to
|
|
282
|
+
* a TypeScript instance, and performs type validation process. If decoded value is
|
|
283
|
+
* following the type `T`, it returns the decoded value with
|
|
284
|
+
* {@link IValidation.ISuccess} typed instance. Otherwise, it returns
|
|
285
|
+
* {@link IValidation.IFailure} value instead with detailed error reasons.
|
|
286
|
+
*
|
|
287
|
+
* However, note that, this validation is not always safe. It just performs additional
|
|
288
|
+
* type validation like `number & Minimum<7>` or `string & Format<"uuid">` cases,
|
|
289
|
+
* that are represented by [custom tags](https://typia.io/docs/validators/tags).
|
|
290
|
+
* Therefore, when using `typia.protobuf.validateDecode<T>()` function, you have to
|
|
291
|
+
* ensure the type safety by yourself.
|
|
292
|
+
*
|
|
293
|
+
* In such type safety reason, I recommend you to use type safe encode functions.
|
|
294
|
+
*
|
|
295
|
+
* - {@link assertEncode}
|
|
296
|
+
* - {@link isEncode}
|
|
297
|
+
* - {@link validateEncode}
|
|
298
|
+
*
|
|
299
|
+
* @template T Expected type of decoded value
|
|
300
|
+
* @param input Protobuf Buffer binary data
|
|
301
|
+
* @returns Decoded value
|
|
302
|
+
*
|
|
303
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
304
|
+
*/
|
|
305
|
+
export function validateDecode(input: Uint8Array): never;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Protocol Buffer Decoder wity type validation, but not safe.
|
|
309
|
+
*
|
|
310
|
+
* `typia.protobuf.validateDecode()` is a combination function of {@link decode} and
|
|
311
|
+
* {@link validate} function. Therefore, it decodes a binary data of Protocol Buffer to
|
|
312
|
+
* a TypeScript instance, and performs type validation process. If decoded value is
|
|
313
|
+
* following the type `T`, it returns the decoded value with
|
|
314
|
+
* {@link IValidation.ISuccess} typed instance. Otherwise, it returns
|
|
315
|
+
* {@link IValidation.IFailure} value instead with detailed error reasons.
|
|
316
|
+
*
|
|
317
|
+
* However, note that, this validation is not always safe. It just performs additional
|
|
318
|
+
* type validation like `number & Minimum<7>` or `string & Format<"uuid">` cases,
|
|
319
|
+
* that are represented by [custom tags](https://typia.io/docs/validators/tags).
|
|
320
|
+
* Therefore, when using `typia.protobuf.validateDecode<T>()` function, you have to
|
|
321
|
+
* ensure the type safety by yourself.
|
|
322
|
+
*
|
|
323
|
+
* In such type safety reason, I recommend you to use type safe encode functions.
|
|
324
|
+
*
|
|
325
|
+
* - {@link assertEncode}
|
|
326
|
+
* - {@link isEncode}
|
|
327
|
+
* - {@link validateEncode}
|
|
328
|
+
*
|
|
329
|
+
* @template T Expected type of decoded value
|
|
330
|
+
* @param input Protobuf Buffer binary data
|
|
331
|
+
* @returns Decoded value
|
|
332
|
+
*
|
|
333
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
334
|
+
*/
|
|
335
|
+
export function validateDecode<T>(input: Uint8Array): IValidation<Resolved<T>>;
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* @internal
|
|
339
|
+
*/
|
|
340
|
+
export function validateDecode(): never {
|
|
341
|
+
halt("validateDecode");
|
|
342
|
+
}
|
|
343
|
+
Object.assign(validateDecode, Namespace.validate());
|
|
344
|
+
Object.assign(validateDecode, Namespace.protobuf.decode("validateDecode"));
|
|
345
|
+
|
|
346
|
+
/* -----------------------------------------------------------
|
|
347
|
+
ENCODE
|
|
348
|
+
----------------------------------------------------------- */
|
|
349
|
+
/**
|
|
350
|
+
* Protocol Buffer Encoder.
|
|
351
|
+
*
|
|
352
|
+
* Converts an input value to a binary data of Protocol Buffer format.
|
|
353
|
+
*
|
|
354
|
+
* For reference, this `typia.protobuf.encode()` does not validate the `input` value.
|
|
355
|
+
* It just believes that the `input` value is valid and converts it to a binary data
|
|
356
|
+
* directly. Therefore, if you can't ensure the `input` value type, it would better to
|
|
357
|
+
* call one of below functions intead.
|
|
358
|
+
*
|
|
359
|
+
* - {@link assertEncode}
|
|
360
|
+
* - {@link isEncode}
|
|
361
|
+
* - {@link validateEncode}
|
|
362
|
+
*
|
|
363
|
+
* By the way, you know what? Expression power of Protocol Buffer is not enough strong
|
|
364
|
+
* to fully meet the TypeScript type specs. In such reason, if you put a TypeScript
|
|
365
|
+
* type that is not compatible with Protocol Buffer, this function would throw
|
|
366
|
+
* compilation errors.
|
|
367
|
+
*
|
|
368
|
+
* - [Restrictions of Protocol Buffer](https://typia.io/docs/protobuf/message/#restrictions)
|
|
369
|
+
*
|
|
370
|
+
* @template T Type of the value input
|
|
371
|
+
* @param input A value to encode
|
|
372
|
+
* @returns Encoded binary data
|
|
373
|
+
*
|
|
374
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
375
|
+
*/
|
|
376
|
+
export function encode<T>(input: T): Uint8Array;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* @internal
|
|
380
|
+
*/
|
|
381
|
+
export function encode(): never {
|
|
382
|
+
halt("encode");
|
|
383
|
+
}
|
|
384
|
+
Object.assign(encode, Namespace.protobuf.encode("encode"));
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Protocol Buffer Encoder with type assertion.
|
|
388
|
+
*
|
|
389
|
+
* `typia.protobuf.assertEncode()` is a combination function of {@link assert} and
|
|
390
|
+
* {@link encode}.
|
|
391
|
+
*
|
|
392
|
+
* Therefore, it converts an `input` value to a binary data of
|
|
393
|
+
* Protocol Buffer, with type assertion. If `input` value is not valid, it throws
|
|
394
|
+
* {@link TypeGuardError}. Otherwise, there's no problem on the `input` value,
|
|
395
|
+
* Protocol Buffer binary data would be returned.
|
|
396
|
+
*
|
|
397
|
+
* If you can trust `input` value, or want to perform other type of validation, use
|
|
398
|
+
* below functions intead.
|
|
399
|
+
*
|
|
400
|
+
* - {@link encode}
|
|
401
|
+
* - {@link isEncode}
|
|
402
|
+
* - {@link validateEncode}
|
|
403
|
+
*
|
|
404
|
+
* By the way, you know what? Expression power of Protocol Buffer is not enough strong
|
|
405
|
+
* to fully meet the TypeScript type specs. In such reason, if you put a TypeScript
|
|
406
|
+
* type that is not compatible with Protocol Buffer, this function would throw
|
|
407
|
+
* compilation errors.
|
|
408
|
+
*
|
|
409
|
+
* - [Restrictions of Protocol Buffer](https://typia.io/docs/protobuf/message/#restrictions)
|
|
410
|
+
*
|
|
411
|
+
* @template T Type of the value input
|
|
412
|
+
* @param input A value to encode
|
|
413
|
+
* @returns Encoded binary data
|
|
414
|
+
*
|
|
415
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
416
|
+
*/
|
|
417
|
+
export function assertEncode<T>(input: T): Uint8Array;
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Protocol Buffer Encoder with type assertion.
|
|
421
|
+
*
|
|
422
|
+
* `typia.protobuf.assertEncode()` is a combination function of {@link assert} and
|
|
423
|
+
* {@link encode}.
|
|
424
|
+
*
|
|
425
|
+
* Therefore, it converts an `input` value to a binary data of
|
|
426
|
+
* Protocol Buffer, with type assertion. If `input` value is not valid, it throws
|
|
427
|
+
* {@link TypeGuardError}. Otherwise, there's no problem on the `input` value,
|
|
428
|
+
* Protocol Buffer binary data would be returned.
|
|
429
|
+
*
|
|
430
|
+
* If you can trust `input` value, or want to perform other type of validation, use
|
|
431
|
+
* below functions intead.
|
|
432
|
+
*
|
|
433
|
+
* - {@link encode}
|
|
434
|
+
* - {@link isEncode}
|
|
435
|
+
* - {@link validateEncode}
|
|
436
|
+
*
|
|
437
|
+
* By the way, you know what? Expression power of Protocol Buffer is not enough strong
|
|
438
|
+
* to fully meet the TypeScript type specs. In such reason, if you put a TypeScript
|
|
439
|
+
* type that is not compatible with Protocol Buffer, this function would throw
|
|
440
|
+
* compilation errors.
|
|
441
|
+
*
|
|
442
|
+
* - [Restrictions of Protocol Buffer](https://typia.io/docs/protobuf/message/#restrictions)
|
|
443
|
+
*
|
|
444
|
+
* @template T Type of the value input
|
|
445
|
+
* @param input A value to encode
|
|
446
|
+
* @returns Encoded binary data
|
|
447
|
+
*
|
|
448
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
449
|
+
*/
|
|
450
|
+
export function assertEncode<T>(input: unknown): Uint8Array;
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* @internal
|
|
454
|
+
*/
|
|
455
|
+
export function assertEncode(): never {
|
|
456
|
+
halt("assertEncode");
|
|
457
|
+
}
|
|
458
|
+
Object.assign(assertEncode, Namespace.assert("protobuf.assertEncode"));
|
|
459
|
+
Object.assign(assertEncode, Namespace.protobuf.encode("assertEncode"));
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Protocol Buffer Encoder with type checking.
|
|
463
|
+
*
|
|
464
|
+
* `typia.protobuf.isEncode()` is a combination function of {@link is} and
|
|
465
|
+
* {@link encode}.
|
|
466
|
+
*
|
|
467
|
+
* Therefore, it converts an `input` value to a binary data of
|
|
468
|
+
* Protocol Buffer, with type checking. If `input` value is not valid, it returns
|
|
469
|
+
* `null` value. Otherwise, there's no problem on the `input` value, Protocol
|
|
470
|
+
* Buffer binary data would be returned.
|
|
471
|
+
*
|
|
472
|
+
* If you can trust `input` value, or want to perform other type of validation, use
|
|
473
|
+
* below functions intead.
|
|
474
|
+
*
|
|
475
|
+
* - {@link encode}
|
|
476
|
+
* - {@link assertEncode}
|
|
477
|
+
* - {@link validateEncode}
|
|
478
|
+
*
|
|
479
|
+
* By the way, you know what? Expression power of Protocol Buffer is not enough strong
|
|
480
|
+
* to fully meet the TypeScript type specs. In such reason, if you put a TypeScript
|
|
481
|
+
* type that is not compatible with Protocol Buffer, this function would throw
|
|
482
|
+
* compilation errors.
|
|
483
|
+
*
|
|
484
|
+
* - [Restrictions of Protocol Buffer](https://typia.io/docs/protobuf/message/#restrictions)
|
|
485
|
+
*
|
|
486
|
+
* @template T Type of the value input
|
|
487
|
+
* @param input A value to encode
|
|
488
|
+
* @returns Encoded binary data
|
|
489
|
+
*
|
|
490
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
491
|
+
*/
|
|
492
|
+
export function isEncode<T>(input: T): Uint8Array | null;
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Protocol Buffer Encoder with type checking.
|
|
496
|
+
*
|
|
497
|
+
* `typia.protobuf.isEncode()` is a combination function of {@link is} and
|
|
498
|
+
* {@link encode}.
|
|
499
|
+
*
|
|
500
|
+
* Therefore, it converts an `input` value to a binary data of
|
|
501
|
+
* Protocol Buffer, with type checking. If `input` value is not valid, it returns
|
|
502
|
+
* `null` value. Otherwise, there's no problem on the `input` value, Protocol
|
|
503
|
+
* Buffer binary data would be returned.
|
|
504
|
+
*
|
|
505
|
+
* If you can trust `input` value, or want to perform other type of validation, use
|
|
506
|
+
* below functions intead.
|
|
507
|
+
*
|
|
508
|
+
* - {@link encode}
|
|
509
|
+
* - {@link assertEncode}
|
|
510
|
+
* - {@link validateEncode}
|
|
511
|
+
*
|
|
512
|
+
* By the way, you know what? Expression power of Protocol Buffer is not enough strong
|
|
513
|
+
* to fully meet the TypeScript type specs. In such reason, if you put a TypeScript
|
|
514
|
+
* type that is not compatible with Protocol Buffer, this function would throw
|
|
515
|
+
* compilation errors.
|
|
516
|
+
*
|
|
517
|
+
* - [Restrictions of Protocol Buffer](https://typia.io/docs/protobuf/message/#restrictions)
|
|
518
|
+
*
|
|
519
|
+
* @template T Type of the value input
|
|
520
|
+
* @param input A value to encode
|
|
521
|
+
* @returns Encoded binary data
|
|
522
|
+
*
|
|
523
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
524
|
+
*/
|
|
525
|
+
export function isEncode<T>(input: unknown): Uint8Array | null;
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* @internal
|
|
529
|
+
*/
|
|
530
|
+
export function isEncode(): never {
|
|
531
|
+
halt("isEncode");
|
|
532
|
+
}
|
|
533
|
+
Object.assign(isEncode, Namespace.is());
|
|
534
|
+
Object.assign(isEncode, Namespace.protobuf.encode("isEncode"));
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Protocol Buffer Encoder with type validation.
|
|
538
|
+
*
|
|
539
|
+
* `typia.protobuf.validateEncode()` is a combination function of
|
|
540
|
+
* {@link validation} and {@link encode}.
|
|
541
|
+
*
|
|
542
|
+
* Therefore, it converts an `input` value to a binary data of
|
|
543
|
+
* Protocol Buffer, with type validation. If `input` value is not valid, it returns
|
|
544
|
+
* {@link IValidation.IFailure} value with detailed error reasons. Otherwise, there's
|
|
545
|
+
* no problem on the `input` value, Protocol Buffer binary data would be stored in
|
|
546
|
+
* `data` property of the output {@link IValidation.ISuccess} instance.
|
|
547
|
+
*
|
|
548
|
+
* If you can trust `input` value, or want to perform other type of validation, use
|
|
549
|
+
* below functions intead.
|
|
550
|
+
*
|
|
551
|
+
* - {@link encode}
|
|
552
|
+
* - {@link assertEncode}
|
|
553
|
+
* - {@link isEncode}
|
|
554
|
+
*
|
|
555
|
+
* By the way, you know what? Expression power of Protocol Buffer is not enough strong
|
|
556
|
+
* to fully meet the TypeScript type specs. In such reason, if you put a TypeScript
|
|
557
|
+
* type that is not compatible with Protocol Buffer, this function would throw
|
|
558
|
+
* compilation errors.
|
|
559
|
+
*
|
|
560
|
+
* - [Restrictions of Protocol Buffer](https://typia.io/docs/protobuf/message/#restrictions)
|
|
561
|
+
*
|
|
562
|
+
* @template T Type of the value input
|
|
563
|
+
* @param input A value to encode
|
|
564
|
+
* @returns Encoded binary data
|
|
565
|
+
*
|
|
566
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
567
|
+
*/
|
|
568
|
+
export function validateEncode<T>(input: T): IValidation<Uint8Array>;
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Protocol Buffer Encoder with type validation.
|
|
572
|
+
*
|
|
573
|
+
* `typia.protobuf.validateEncode()` is a combination function of
|
|
574
|
+
* {@link validation} and {@link encode}.
|
|
575
|
+
*
|
|
576
|
+
* Therefore, it converts an `input` value to a binary data of
|
|
577
|
+
* Protocol Buffer, with type validation. If `input` value is not valid, it returns
|
|
578
|
+
* {@link IValidation.IFailure} value with detailed error reasons. Otherwise, there's
|
|
579
|
+
* no problem on the `input` value, Protocol Buffer binary data would be stored in
|
|
580
|
+
* `data` property of the output {@link IValidation.ISuccess} instance.
|
|
581
|
+
*
|
|
582
|
+
* If you can trust `input` value, or want to perform other type of validation, use
|
|
583
|
+
* below functions intead.
|
|
584
|
+
*
|
|
585
|
+
* - {@link encode}
|
|
586
|
+
* - {@link assertEncode}
|
|
587
|
+
* - {@link isEncode}
|
|
588
|
+
*
|
|
589
|
+
* By the way, you know what? Expression power of Protocol Buffer is not enough strong
|
|
590
|
+
* to fully meet the TypeScript type specs. In such reason, if you put a TypeScript
|
|
591
|
+
* type that is not compatible with Protocol Buffer, this function would throw
|
|
592
|
+
* compilation errors.
|
|
593
|
+
*
|
|
594
|
+
* - [Restrictions of Protocol Buffer](https://typia.io/docs/protobuf/message/#restrictions)
|
|
595
|
+
*
|
|
596
|
+
* @template T Type of the value input
|
|
597
|
+
* @param input A value to encode
|
|
598
|
+
* @returns Encoded binary data
|
|
599
|
+
*
|
|
600
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
601
|
+
*/
|
|
602
|
+
export function validateEncode<T>(input: unknown): IValidation<Uint8Array>;
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* @internal
|
|
606
|
+
*/
|
|
607
|
+
export function validateEncode(): never {
|
|
608
|
+
halt("validateEncode");
|
|
609
|
+
}
|
|
610
|
+
Object.assign(validateEncode, Namespace.validate());
|
|
611
|
+
Object.assign(validateEncode, Namespace.protobuf.encode("validateEncode"));
|
|
612
|
+
|
|
613
|
+
/* -----------------------------------------------------------
|
|
614
|
+
FACTORY FUNCTIONS
|
|
615
|
+
----------------------------------------------------------- */
|
|
616
|
+
/**
|
|
617
|
+
* Creates a reusable {@link decode} function.
|
|
618
|
+
*
|
|
619
|
+
* @danger You must configure the generic argument `T`
|
|
620
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
621
|
+
* @throws compile error
|
|
622
|
+
*
|
|
623
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
624
|
+
*/
|
|
625
|
+
export function createDecode(): never;
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Creates a reusable {@link decode} function.
|
|
629
|
+
*
|
|
630
|
+
* @template T Target type
|
|
631
|
+
* @returns A reusable `decode` function
|
|
632
|
+
*
|
|
633
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
634
|
+
*/
|
|
635
|
+
export function createDecode<T>(): (input: Uint8Array) => Resolved<T>;
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* @internal
|
|
639
|
+
*/
|
|
640
|
+
export function createDecode<T>(): (input: Uint8Array) => Resolved<T> {
|
|
641
|
+
halt("createDecode");
|
|
642
|
+
}
|
|
643
|
+
Object.assign(createDecode, Namespace.protobuf.decode("createDecode"));
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Creates a reusable {@link isDecode} function.
|
|
647
|
+
*
|
|
648
|
+
* @danger You must configure the generic argument `T`
|
|
649
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
650
|
+
* @throws compile error
|
|
651
|
+
*
|
|
652
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
653
|
+
*/
|
|
654
|
+
export function createIsDecode(): never;
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Creates a reusable {@link isDecode} function.
|
|
658
|
+
*
|
|
659
|
+
* @template T Target type
|
|
660
|
+
* @returns A reusable `isDecode` function
|
|
661
|
+
*
|
|
662
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
663
|
+
*/
|
|
664
|
+
export function createIsDecode<T>(): (input: Uint8Array) => Resolved<T> | null;
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* @internal
|
|
668
|
+
*/
|
|
669
|
+
export function createIsDecode<T>(): (input: Uint8Array) => Resolved<T> | null {
|
|
670
|
+
halt("createIsDecode");
|
|
671
|
+
}
|
|
672
|
+
Object.assign(createIsDecode, Namespace.is());
|
|
673
|
+
Object.assign(createIsDecode, Namespace.protobuf.decode("createIsDecode"));
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Creates a reusable {@link assertDecode} function.
|
|
677
|
+
*
|
|
678
|
+
* @danger You must configure the generic argument `T`
|
|
679
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
680
|
+
* @throws compile error
|
|
681
|
+
*
|
|
682
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
683
|
+
*/
|
|
684
|
+
export function createAssertDecode(): never;
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Creates a reusable {@link assertDecode} function.
|
|
688
|
+
*
|
|
689
|
+
* @template T Target type
|
|
690
|
+
* @returns A reusable `assertDecode` function
|
|
691
|
+
*
|
|
692
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
693
|
+
*/
|
|
694
|
+
export function createAssertDecode<T>(): (input: Uint8Array) => Resolved<T>;
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* @internal
|
|
698
|
+
*/
|
|
699
|
+
export function createAssertDecode<T>(): (input: Uint8Array) => Resolved<T> {
|
|
700
|
+
halt("createAssertDecode");
|
|
701
|
+
}
|
|
702
|
+
Object.assign(
|
|
703
|
+
createAssertDecode,
|
|
704
|
+
Namespace.assert("protobuf.createAssertDecode"),
|
|
705
|
+
);
|
|
706
|
+
Object.assign(
|
|
707
|
+
createAssertDecode,
|
|
708
|
+
Namespace.protobuf.decode("createAssertDecode"),
|
|
709
|
+
);
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* Creates a reusable {@link validateDecode} function.
|
|
713
|
+
*
|
|
714
|
+
* @danger You must configure the generic argument `T`
|
|
715
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
716
|
+
* @throws compile error
|
|
717
|
+
*
|
|
718
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
719
|
+
*/
|
|
720
|
+
export function createValidateDecode(): never;
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Creates a reusable {@link validateDecode} function.
|
|
724
|
+
*
|
|
725
|
+
* @template T Target type
|
|
726
|
+
* @returns A reusable `validateDecode` function
|
|
727
|
+
*
|
|
728
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
729
|
+
*/
|
|
730
|
+
export function createValidateDecode<T>(): (
|
|
731
|
+
input: Uint8Array,
|
|
732
|
+
) => IValidation<Resolved<T>>;
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* @internal
|
|
736
|
+
*/
|
|
737
|
+
export function createValidateDecode<T>(): (
|
|
738
|
+
input: Uint8Array,
|
|
739
|
+
) => IValidation<Resolved<T>> {
|
|
740
|
+
halt("createValidateDecode");
|
|
741
|
+
}
|
|
742
|
+
Object.assign(createValidateDecode, Namespace.validate());
|
|
743
|
+
Object.assign(
|
|
744
|
+
createValidateDecode,
|
|
745
|
+
Namespace.protobuf.decode("createValidateDecode"),
|
|
746
|
+
);
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* Creates a reusable {@link encode} function.
|
|
750
|
+
*
|
|
751
|
+
* @danger You must configure the generic argument `T`
|
|
752
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
753
|
+
* @throws compile error
|
|
754
|
+
*
|
|
755
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
756
|
+
*/
|
|
757
|
+
export function createEncode(): never;
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Creates a reusable {@link encode} function.
|
|
761
|
+
*
|
|
762
|
+
* @template T Target type
|
|
763
|
+
* @returns A reusable `encode` function
|
|
764
|
+
*
|
|
765
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
766
|
+
*/
|
|
767
|
+
export function createEncode<T>(): (input: T) => Uint8Array;
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* @internal
|
|
771
|
+
*/
|
|
772
|
+
export function createEncode<T>(): (input: T) => Uint8Array {
|
|
773
|
+
halt("createEncode");
|
|
774
|
+
}
|
|
775
|
+
Object.assign(createEncode, Namespace.protobuf.encode("createEncode"));
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* Creates a reusable {@link isEncode} function.
|
|
779
|
+
*
|
|
780
|
+
* @danger You must configure the generic argument `T`
|
|
781
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
782
|
+
* @throws compile error
|
|
783
|
+
*
|
|
784
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
785
|
+
*/
|
|
786
|
+
export function createIsEncode(): never;
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* Creates a reusable {@link isEncode} function.
|
|
790
|
+
*
|
|
791
|
+
* @template T Target type
|
|
792
|
+
* @returns A reusable `isEncode` function
|
|
793
|
+
*
|
|
794
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
795
|
+
*/
|
|
796
|
+
export function createIsEncode<T>(): (input: T) => Uint8Array | null;
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* @internal
|
|
800
|
+
*/
|
|
801
|
+
export function createIsEncode<T>(): (input: T) => Uint8Array | null {
|
|
802
|
+
halt("createIsEncode");
|
|
803
|
+
}
|
|
804
|
+
Object.assign(createIsEncode, Namespace.is());
|
|
805
|
+
Object.assign(createIsEncode, Namespace.protobuf.encode("createIsEncode"));
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* Creates a reusable {@link assertEncode} function.
|
|
809
|
+
*
|
|
810
|
+
* @danger You must configure the generic argument `T`
|
|
811
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
812
|
+
* @throws compile error
|
|
813
|
+
*
|
|
814
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
815
|
+
*/
|
|
816
|
+
export function createAssertEncode(): never;
|
|
817
|
+
|
|
818
|
+
/**
|
|
819
|
+
* Creates a reusable {@link assertEncode} function.
|
|
820
|
+
*
|
|
821
|
+
* @template T Target type
|
|
822
|
+
* @returns A reusable `assertEncode` function
|
|
823
|
+
*
|
|
824
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
825
|
+
*/
|
|
826
|
+
export function createAssertEncode<T>(): (input: T) => Uint8Array;
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* @internal
|
|
830
|
+
*/
|
|
831
|
+
export function createAssertEncode<T>(): (input: T) => Uint8Array {
|
|
832
|
+
halt("createAssertEncode");
|
|
833
|
+
}
|
|
834
|
+
Object.assign(
|
|
835
|
+
createAssertEncode,
|
|
836
|
+
Namespace.assert("protobuf.createAssertEncode"),
|
|
837
|
+
);
|
|
838
|
+
Object.assign(
|
|
839
|
+
createAssertEncode,
|
|
840
|
+
Namespace.protobuf.encode("createAssertEncode"),
|
|
841
|
+
);
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* Creates a reusable {@link validateEncode} function.
|
|
845
|
+
*
|
|
846
|
+
* @danger You must configure the generic argument `T`
|
|
847
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
848
|
+
* @throws compile error
|
|
849
|
+
*
|
|
850
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
851
|
+
*/
|
|
852
|
+
export function createValidateEncode(): never;
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* Creates a reusable {@link validateEncode} function.
|
|
856
|
+
*
|
|
857
|
+
* @template T Target type
|
|
858
|
+
* @returns A reusable `validateEncode` function
|
|
859
|
+
*
|
|
860
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
861
|
+
*/
|
|
862
|
+
export function createValidateEncode<T>(): (
|
|
863
|
+
input: T,
|
|
864
|
+
) => IValidation<Uint8Array>;
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* @internal
|
|
868
|
+
*/
|
|
869
|
+
export function createValidateEncode<T>(): (
|
|
870
|
+
input: T,
|
|
871
|
+
) => IValidation<Uint8Array> {
|
|
872
|
+
halt("createValidateEncode");
|
|
873
|
+
}
|
|
874
|
+
Object.assign(createValidateEncode, Namespace.validate());
|
|
875
|
+
Object.assign(
|
|
876
|
+
createValidateEncode,
|
|
877
|
+
Namespace.protobuf.encode("createValidateEncode"),
|
|
878
|
+
);
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
* @internal
|
|
882
|
+
*/
|
|
883
|
+
function halt(name: string): never {
|
|
884
|
+
throw new Error(
|
|
885
|
+
`Error on typia.protobuf.${name}(): no transform has been configured. Read and follow https://typia.io/docs/setup please.`,
|
|
886
|
+
);
|
|
887
|
+
}
|