typia 3.6.7 → 3.7.0-dev.20230310
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/README.md +44 -15
- package/lib/factories/MetadataCollection.d.ts +1 -9
- package/lib/factories/MetadataCollection.js +2 -75
- package/lib/factories/MetadataCollection.js.map +1 -1
- package/lib/factories/ProtocolFactory.d.ts +8 -0
- package/lib/factories/ProtocolFactory.js +112 -0
- package/lib/factories/ProtocolFactory.js.map +1 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +16 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +156 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +3 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.js +47 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +4 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.js +20 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js +69 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +2 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.js +30 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.js +17 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +4 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.js +75 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +5 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js +190 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +2 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.js +33 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_never.d.ts +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_never.js +6 -0
- package/lib/factories/internal/protocols/iterate_protocol_never.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_object.d.ts +4 -0
- package/lib/factories/internal/protocols/iterate_protocol_object.js +157 -0
- package/lib/factories/internal/protocols/iterate_protocol_object.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +5 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js +25 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js +46 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -0
- package/lib/functional/$proto_bytes.d.ts +2 -0
- package/lib/functional/$proto_bytes.js +37 -0
- package/lib/functional/$proto_bytes.js.map +1 -0
- package/lib/functional/$proto_field.d.ts +10 -0
- package/lib/functional/$proto_field.js +42 -0
- package/lib/functional/$proto_field.js.map +1 -0
- package/lib/functional/$proto_float.d.ts +4 -0
- package/lib/functional/$proto_float.js +28 -0
- package/lib/functional/$proto_float.js.map +1 -0
- package/lib/functional/$proto_i32.d.ts +2 -0
- package/lib/functional/$proto_i32.js +23 -0
- package/lib/functional/$proto_i32.js.map +1 -0
- package/lib/functional/$proto_i64.d.ts +2 -0
- package/lib/functional/$proto_i64.js +31 -0
- package/lib/functional/$proto_i64.js.map +1 -0
- package/lib/functional/$proto_size.d.ts +6 -0
- package/lib/functional/$proto_size.js +76 -0
- package/lib/functional/$proto_size.js.map +1 -0
- package/lib/functional/$proto_string.d.ts +2 -0
- package/lib/functional/$proto_string.js +34 -0
- package/lib/functional/$proto_string.js.map +1 -0
- package/lib/functional/$varint.d.ts +6 -0
- package/lib/functional/$varint.js +99 -0
- package/lib/functional/$varint.js.map +1 -0
- package/lib/functional/$zigzag.d.ts +4 -0
- package/lib/functional/$zigzag.js +34 -0
- package/lib/functional/$zigzag.js.map +1 -0
- package/lib/messages/IProtocolMap.d.ts +5 -0
- package/lib/messages/IProtocolMap.js +3 -0
- package/lib/messages/IProtocolMap.js.map +1 -0
- package/lib/messages/IProtocolMessage.d.ts +5 -0
- package/lib/messages/IProtocolMessage.js +3 -0
- package/lib/messages/IProtocolMessage.js.map +1 -0
- package/lib/messages/IProtocolProperty.d.ts +12 -0
- package/lib/messages/IProtocolProperty.js +3 -0
- package/lib/messages/IProtocolProperty.js.map +1 -0
- package/lib/metadata/IMetadataTag.d.ts +7 -3
- package/lib/metadata/Metadata.js +2 -2
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/module.d.ts +2 -0
- package/lib/module.js +5 -1
- package/lib/module.js.map +1 -1
- package/lib/programmers/MessageProgrammer.d.ts +5 -0
- package/lib/programmers/MessageProgrammer.js +141 -0
- package/lib/programmers/MessageProgrammer.js.map +1 -0
- package/lib/programmers/internal/application_object.js +11 -11
- package/lib/programmers/internal/application_object.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +5 -3
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.js +3 -1
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +1 -3
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/protocols/MessageTransformer.d.ts +5 -0
- package/lib/transformers/features/protocols/MessageTransformer.js +17 -0
- package/lib/transformers/features/protocols/MessageTransformer.js.map +1 -0
- package/lib/utils/NameEncoder.d.ts +4 -0
- package/lib/utils/NameEncoder.js +89 -0
- package/lib/utils/NameEncoder.js.map +1 -0
- package/package.json +2 -1
- package/src/factories/MetadataCollection.ts +2 -41
- package/src/factories/ProtocolFactory.ts +79 -0
- package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +163 -0
- package/src/factories/internal/protocols/emplace_protocol_object.ts +25 -0
- package/src/factories/internal/protocols/emplace_protocol_property.ts +12 -0
- package/src/factories/internal/protocols/iterate_protocol_atomic.ts +34 -0
- package/src/factories/internal/protocols/iterate_protocol_constant.ts +27 -0
- package/src/factories/internal/protocols/iterate_protocol_main.ts +19 -0
- package/src/factories/internal/protocols/iterate_protocol_map.ts +58 -0
- package/src/factories/internal/protocols/iterate_protocol_metadata.ts +96 -0
- package/src/factories/internal/protocols/iterate_protocol_native.ts +34 -0
- package/src/factories/internal/protocols/iterate_protocol_never.ts +1 -0
- package/src/factories/internal/protocols/iterate_protocol_object.ts +110 -0
- package/src/factories/internal/protocols/iterate_protocol_repeated.ts +34 -0
- package/src/factories/internal/protocols/iterate_protocol_tuple.ts +29 -0
- package/src/functional/$proto_bytes.ts +25 -0
- package/src/functional/$proto_field.ts +30 -0
- package/src/functional/$proto_float.ts +37 -0
- package/src/functional/$proto_i32.ts +29 -0
- package/src/functional/$proto_i64.ts +37 -0
- package/src/functional/$proto_size.ts +82 -0
- package/src/functional/$proto_string.ts +24 -0
- package/src/functional/$varint.ts +130 -0
- package/src/functional/$zigzag.ts +39 -0
- package/src/messages/IProtocolMap.ts +5 -0
- package/src/messages/IProtocolMessage.ts +6 -0
- package/src/messages/IProtocolProperty.ts +13 -0
- package/src/metadata/IMetadataTag.ts +20 -4
- package/src/metadata/Metadata.ts +6 -3
- package/src/module.ts +11 -0
- package/src/programmers/MessageProgrammer.ts +126 -0
- package/src/programmers/internal/application_object.ts +5 -5
- package/src/programmers/internal/application_schema.ts +7 -3
- package/src/transformers/CallExpressionTransformer.ts +16 -9
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +1 -3
- package/src/transformers/features/protocols/MessageTransformer.ts +32 -0
- package/src/utils/NameEncoder.ts +32 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IMetadataTag } from "../../../metadata/IMetadataTag";
|
|
2
|
+
|
|
3
|
+
import { Atomic } from "../../../typings/Atomic";
|
|
4
|
+
|
|
5
|
+
export const iterate_protocol_atomic =
|
|
6
|
+
(tags: IMetadataTag[]) => (type: Atomic.Literal) => {
|
|
7
|
+
if (type === "boolean") return "bool";
|
|
8
|
+
else if (type === "number") return number(tags);
|
|
9
|
+
else if (type === "bigint") return bigint(tags);
|
|
10
|
+
else return "string";
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const number = (tagList: IMetadataTag[]) => {
|
|
14
|
+
const filtered: IMetadataTag.INumberType[] = tagList.filter(
|
|
15
|
+
(tag) => tag.kind === "type",
|
|
16
|
+
) as IMetadataTag.INumberType[];
|
|
17
|
+
|
|
18
|
+
for (const { value } of filtered)
|
|
19
|
+
if (value === "int") return "int32";
|
|
20
|
+
else if (value === "uint") return "uint32";
|
|
21
|
+
return "double";
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const bigint = (tagList: IMetadataTag[]) => {
|
|
25
|
+
const filtered: IMetadataTag.IBigintType[] = tagList.filter(
|
|
26
|
+
(tag) =>
|
|
27
|
+
tag.kind === "type" &&
|
|
28
|
+
(tag.value === "int64" || tag.value === "uint64"),
|
|
29
|
+
) as IMetadataTag.IBigintType[];
|
|
30
|
+
|
|
31
|
+
for (const { value } of filtered)
|
|
32
|
+
if (value === "int64" || value === "uint64") return value;
|
|
33
|
+
return "int64";
|
|
34
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MetadataConstant } from "../../../metadata/MetadataConstant";
|
|
2
|
+
|
|
3
|
+
export const iterate_protocol_constant = ({
|
|
4
|
+
type,
|
|
5
|
+
values,
|
|
6
|
+
}: MetadataConstant) => {
|
|
7
|
+
if (type === "boolean") return "bool";
|
|
8
|
+
else if (type === "number") return number(values);
|
|
9
|
+
else if (type === "bigint") return bigint(values);
|
|
10
|
+
else return "string";
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const bigint = (values: bigint[]): string => {
|
|
14
|
+
return values.every((v) => v >= BigInt(0)) ? "uint64" : "int64";
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const number = (values: number[]): string => {
|
|
18
|
+
return values.some((v) => Math.floor(v) !== v)
|
|
19
|
+
? "double"
|
|
20
|
+
: values.every((v) => v >= 0)
|
|
21
|
+
? values.every((v) => v <= 2 ** 64 - 1)
|
|
22
|
+
? "uint32"
|
|
23
|
+
: "uint64"
|
|
24
|
+
: values.every((v) => -(2 ** 31) <= v && v <= 2 ** 31 - 1)
|
|
25
|
+
? "int32"
|
|
26
|
+
: "int64";
|
|
27
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
2
|
+
|
|
3
|
+
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
4
|
+
import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
|
|
5
|
+
import { emplace_protocol_object } from "./emplace_protocol_object";
|
|
6
|
+
|
|
7
|
+
export const iterate_protocol_main =
|
|
8
|
+
(dict: Map<string, IProtocolMessage>) =>
|
|
9
|
+
(meta: Metadata): string => {
|
|
10
|
+
// ONLY ONE OBJECT TYPE
|
|
11
|
+
if (ProtocolMetadataUtil.standalone(meta) && meta.objects.length === 1)
|
|
12
|
+
return meta.getName();
|
|
13
|
+
|
|
14
|
+
const obj = ProtocolMetadataUtil.object("__Main", dict.size);
|
|
15
|
+
obj.properties.push(ProtocolMetadataUtil.property("value", meta, []));
|
|
16
|
+
emplace_protocol_object(dict)(obj);
|
|
17
|
+
|
|
18
|
+
return obj.name;
|
|
19
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
2
|
+
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
3
|
+
|
|
4
|
+
import { IProtocolMap } from "../../../messages/IProtocolMap";
|
|
5
|
+
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
6
|
+
import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
|
|
7
|
+
import { emplace_protocol_object } from "./emplace_protocol_object";
|
|
8
|
+
import { iterate_protocol_atomic } from "./iterate_protocol_atomic";
|
|
9
|
+
import { iterate_protocol_constant } from "./iterate_protocol_constant";
|
|
10
|
+
import { iterate_protocol_metadata } from "./iterate_protocol_metadata";
|
|
11
|
+
|
|
12
|
+
export const iterate_protocol_map =
|
|
13
|
+
(sole: boolean) =>
|
|
14
|
+
(dict: Map<string, IProtocolMessage>) =>
|
|
15
|
+
(prop: Metadata.Entry): string | IProtocolMap => {
|
|
16
|
+
if (sole === true)
|
|
17
|
+
return {
|
|
18
|
+
type: "map",
|
|
19
|
+
key: getKeyName(prop.key),
|
|
20
|
+
value: getValueName(dict)(prop.value),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const obj: MetadataObject = ProtocolMetadataUtil.object(
|
|
24
|
+
`Map.Wrapper<${prop.key.getName()}, ${prop.value.getName()}>`,
|
|
25
|
+
dict.size,
|
|
26
|
+
);
|
|
27
|
+
obj.properties.push(
|
|
28
|
+
ProtocolMetadataUtil.property(
|
|
29
|
+
"value",
|
|
30
|
+
ProtocolMetadataUtil.map(prop),
|
|
31
|
+
[],
|
|
32
|
+
),
|
|
33
|
+
);
|
|
34
|
+
emplace_protocol_object(dict)(obj);
|
|
35
|
+
return obj.name;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const getKeyName = (meta: Metadata) => {
|
|
39
|
+
for (const atomic of meta.atomics)
|
|
40
|
+
return iterate_protocol_atomic([])(atomic);
|
|
41
|
+
for (const constant of meta.constants)
|
|
42
|
+
return iterate_protocol_constant(constant);
|
|
43
|
+
return "string";
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const getValueName =
|
|
47
|
+
(dict: Map<string, IProtocolMessage>) => (meta: Metadata) => {
|
|
48
|
+
if (ProtocolMetadataUtil.standalone(meta))
|
|
49
|
+
return iterate_protocol_metadata(dict)(meta)([]).oneOf[0]!.type;
|
|
50
|
+
|
|
51
|
+
const obj: MetadataObject = ProtocolMetadataUtil.object(
|
|
52
|
+
`Map.Value<${meta.getName()}>`,
|
|
53
|
+
dict.size,
|
|
54
|
+
);
|
|
55
|
+
obj.properties.push(ProtocolMetadataUtil.property("value", meta, []));
|
|
56
|
+
emplace_protocol_object(dict)(obj);
|
|
57
|
+
return obj.name;
|
|
58
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { IMetadataTag } from "../../../metadata/IMetadataTag";
|
|
2
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
3
|
+
|
|
4
|
+
import { IProtocolMap } from "../../../messages/IProtocolMap";
|
|
5
|
+
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
6
|
+
import { IProtocolProperty } from "../../../messages/IProtocolProperty";
|
|
7
|
+
import { iterate_protocol_atomic } from "./iterate_protocol_atomic";
|
|
8
|
+
import { iterate_protocol_constant } from "./iterate_protocol_constant";
|
|
9
|
+
import { iterate_protocol_map } from "./iterate_protocol_map";
|
|
10
|
+
import { iterate_protocol_native } from "./iterate_protocol_native";
|
|
11
|
+
import { iterate_protocol_never } from "./iterate_protocol_never";
|
|
12
|
+
import { iterate_protocol_object } from "./iterate_protocol_object";
|
|
13
|
+
import { iterate_protocol_repeated } from "./iterate_protocol_repeated";
|
|
14
|
+
import { iterate_protocol_tuple } from "./iterate_protocol_tuple";
|
|
15
|
+
|
|
16
|
+
export const iterate_protocol_metadata =
|
|
17
|
+
(dict: Map<string, IProtocolMessage>) =>
|
|
18
|
+
(meta: Metadata) =>
|
|
19
|
+
(tags: IMetadataTag[]): Omit<IProtocolProperty, "key"> => {
|
|
20
|
+
// PREPARE ASSETS
|
|
21
|
+
const sole: boolean = meta.size() === 1;
|
|
22
|
+
const bucket: boolean = sole && meta.bucket() === 1;
|
|
23
|
+
const required: boolean =
|
|
24
|
+
(meta.required && !meta.nullable) ||
|
|
25
|
+
(sole &&
|
|
26
|
+
(meta.arrays.length === 1 ||
|
|
27
|
+
meta.sets.length === 1 ||
|
|
28
|
+
meta.maps.length === 1 ||
|
|
29
|
+
(meta.objects.length === 1 &&
|
|
30
|
+
meta.objects[0]!.properties.length === 1 &&
|
|
31
|
+
!meta.objects[0]!.properties[0]?.key.isSoleLiteral())));
|
|
32
|
+
|
|
33
|
+
const oneOf: IProtocolProperty.IOneOf[] = [];
|
|
34
|
+
const add = (type: string | IProtocolMap) => {
|
|
35
|
+
if (oneOf.some((one) => one.type === type)) return;
|
|
36
|
+
oneOf.push({
|
|
37
|
+
type,
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// WHEN SINGULAR ARRAY TYPE
|
|
42
|
+
if (sole && meta.arrays.length + meta.sets.length === 1) {
|
|
43
|
+
const [container, child] =
|
|
44
|
+
meta.arrays.length === 1
|
|
45
|
+
? (["Array", meta.arrays[0]!] as const)
|
|
46
|
+
: (["Set", meta.sets[0]!] as const);
|
|
47
|
+
add(
|
|
48
|
+
iterate_protocol_repeated(container)(true, true)(dict)(child)(
|
|
49
|
+
tags,
|
|
50
|
+
),
|
|
51
|
+
);
|
|
52
|
+
return {
|
|
53
|
+
required,
|
|
54
|
+
oneOf,
|
|
55
|
+
repeated: true,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ATOMIC TYPES
|
|
60
|
+
for (const type of meta.atomics)
|
|
61
|
+
add(iterate_protocol_atomic(tags)(type));
|
|
62
|
+
for (const constant of meta.constants)
|
|
63
|
+
add(iterate_protocol_constant(constant));
|
|
64
|
+
if (meta.templates.length) add("string");
|
|
65
|
+
if (meta.size() === 0) add(iterate_protocol_never());
|
|
66
|
+
|
|
67
|
+
// OBJECT TYPES
|
|
68
|
+
for (const obj of meta.objects)
|
|
69
|
+
add(iterate_protocol_object(sole)(dict)(obj));
|
|
70
|
+
for (const map of meta.maps) add(iterate_protocol_map(sole)(dict)(map));
|
|
71
|
+
for (const native of meta.natives)
|
|
72
|
+
add(iterate_protocol_native(dict)(native));
|
|
73
|
+
|
|
74
|
+
// ARRAY TYPES
|
|
75
|
+
for (const tuple of meta.tuples)
|
|
76
|
+
add(iterate_protocol_tuple(dict)(tuple));
|
|
77
|
+
for (const array of meta.arrays)
|
|
78
|
+
add(
|
|
79
|
+
iterate_protocol_repeated("Array")(false, bucket)(dict)(array)(
|
|
80
|
+
tags,
|
|
81
|
+
),
|
|
82
|
+
);
|
|
83
|
+
for (const set of meta.sets)
|
|
84
|
+
add(
|
|
85
|
+
iterate_protocol_repeated("Set")(false, bucket)(dict)(set)(
|
|
86
|
+
tags,
|
|
87
|
+
),
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
// RETURNS
|
|
91
|
+
return {
|
|
92
|
+
required,
|
|
93
|
+
oneOf,
|
|
94
|
+
repeated: false,
|
|
95
|
+
};
|
|
96
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
2
|
+
|
|
3
|
+
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
4
|
+
import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
|
|
5
|
+
import { emplace_protocol_object } from "./emplace_protocol_object";
|
|
6
|
+
|
|
7
|
+
export const iterate_protocol_native =
|
|
8
|
+
(dict: Map<string, IProtocolMessage>) => (native: string) => {
|
|
9
|
+
if (native === "Date") {
|
|
10
|
+
const obj = ProtocolMetadataUtil.object("__Timestamp", dict.size);
|
|
11
|
+
obj.properties.push(
|
|
12
|
+
ProtocolMetadataUtil.property("seconds", integer("bigint"), [
|
|
13
|
+
{
|
|
14
|
+
kind: "type",
|
|
15
|
+
value: "int64",
|
|
16
|
+
},
|
|
17
|
+
]),
|
|
18
|
+
ProtocolMetadataUtil.property("nanos", integer("number"), [
|
|
19
|
+
{
|
|
20
|
+
kind: "type",
|
|
21
|
+
value: "int",
|
|
22
|
+
},
|
|
23
|
+
]),
|
|
24
|
+
);
|
|
25
|
+
emplace_protocol_object(dict)(obj);
|
|
26
|
+
return "__Timestamp";
|
|
27
|
+
} else return "bytes";
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const integer = (type: "number" | "bigint") => {
|
|
31
|
+
const meta = Metadata.initialize();
|
|
32
|
+
meta.atomics.push(type);
|
|
33
|
+
return meta;
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const iterate_protocol_never = () => "uint32";
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
2
|
+
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
3
|
+
import { MetadataProperty } from "../../../metadata/MetadataProperty";
|
|
4
|
+
|
|
5
|
+
import { Atomic } from "../../../typings/Atomic";
|
|
6
|
+
|
|
7
|
+
import { MapUtil } from "../../../utils/MapUtil";
|
|
8
|
+
|
|
9
|
+
import { IProtocolMap } from "../../../messages/IProtocolMap";
|
|
10
|
+
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
11
|
+
import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
|
|
12
|
+
import { emplace_protocol_object } from "./emplace_protocol_object";
|
|
13
|
+
import { iterate_protocol_metadata } from "./iterate_protocol_metadata";
|
|
14
|
+
|
|
15
|
+
export const iterate_protocol_object =
|
|
16
|
+
(sole: boolean) =>
|
|
17
|
+
(dict: Map<string, IProtocolMessage>) =>
|
|
18
|
+
(obj: MetadataObject): string | IProtocolMap => {
|
|
19
|
+
// ONLY REGULAR PROPERTIES
|
|
20
|
+
const statics: MetadataProperty[] = obj.properties.filter(filter(true));
|
|
21
|
+
const dynamics: Metadata.Entry[] = aggregate(
|
|
22
|
+
obj.properties.filter(filter(false)),
|
|
23
|
+
);
|
|
24
|
+
if (dynamics.length === 0) return obj.name;
|
|
25
|
+
|
|
26
|
+
const regular: MetadataObject | undefined = statics.length
|
|
27
|
+
? (() => {
|
|
28
|
+
const r: MetadataObject = ProtocolMetadataUtil.object(
|
|
29
|
+
`${obj.name}.__Regular`,
|
|
30
|
+
dict.size,
|
|
31
|
+
);
|
|
32
|
+
r.properties.push(...statics);
|
|
33
|
+
emplace_protocol_object(dict)(r);
|
|
34
|
+
return r;
|
|
35
|
+
})()
|
|
36
|
+
: undefined;
|
|
37
|
+
|
|
38
|
+
// ONLY ONE TYPED DYNAMIC PROPERTY EXISTS
|
|
39
|
+
if (regular === undefined && dynamics.length === 1 && sole === true) {
|
|
40
|
+
const { key, value } = dynamics[0]!;
|
|
41
|
+
return {
|
|
42
|
+
type: "map",
|
|
43
|
+
key: key.getName(),
|
|
44
|
+
value: ProtocolMetadataUtil.standalone(value)
|
|
45
|
+
? iterate_protocol_metadata(dict)(value)([]).oneOf[0]!.type
|
|
46
|
+
: (() => {
|
|
47
|
+
const wrapper = ProtocolMetadataUtil.object(
|
|
48
|
+
`${obj.name}.__Wrapper`,
|
|
49
|
+
dict.size,
|
|
50
|
+
);
|
|
51
|
+
wrapper.properties.push(
|
|
52
|
+
ProtocolMetadataUtil.property("value", value, []),
|
|
53
|
+
);
|
|
54
|
+
emplace_protocol_object(dict)(wrapper);
|
|
55
|
+
return wrapper.name;
|
|
56
|
+
})(),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// DO WRAP
|
|
61
|
+
const wrapper: MetadataObject = ProtocolMetadataUtil.object(
|
|
62
|
+
`${obj.name}.__Wrapper`,
|
|
63
|
+
dict.size,
|
|
64
|
+
);
|
|
65
|
+
if (regular !== undefined)
|
|
66
|
+
wrapper.properties.push(
|
|
67
|
+
ProtocolMetadataUtil.property(
|
|
68
|
+
"regular",
|
|
69
|
+
ProtocolMetadataUtil.reference(regular),
|
|
70
|
+
[],
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
wrapper.properties.push(
|
|
74
|
+
...dynamics.map((map, i) =>
|
|
75
|
+
ProtocolMetadataUtil.property(
|
|
76
|
+
`__map_${i}`,
|
|
77
|
+
ProtocolMetadataUtil.map(map),
|
|
78
|
+
[],
|
|
79
|
+
),
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
emplace_protocol_object(dict)(wrapper);
|
|
83
|
+
return wrapper.name;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const filter = (regular: boolean) => (prop: MetadataProperty) =>
|
|
87
|
+
regular === prop.key.isSoleLiteral();
|
|
88
|
+
|
|
89
|
+
const aggregate = (properties: MetadataProperty[]): Metadata.Entry[] => {
|
|
90
|
+
const unique: Map<Atomic.Literal, MetadataProperty[]> = new Map();
|
|
91
|
+
for (const prop of properties) {
|
|
92
|
+
if (prop.key.templates)
|
|
93
|
+
MapUtil.take(unique, "string", () => []).push(prop);
|
|
94
|
+
for (const type of prop.key.atomics)
|
|
95
|
+
MapUtil.take(unique, type, () => []).push(prop);
|
|
96
|
+
for (const { type } of prop.key.constants)
|
|
97
|
+
MapUtil.take(unique, type, () => []).push(prop);
|
|
98
|
+
}
|
|
99
|
+
const output: Metadata.Entry[] = [];
|
|
100
|
+
for (const [key, properties] of unique) {
|
|
101
|
+
const value: Metadata = properties
|
|
102
|
+
.map((x) => x.value)
|
|
103
|
+
.reduce((x, y) => Metadata.merge(x, y));
|
|
104
|
+
output.push({
|
|
105
|
+
key: ProtocolMetadataUtil.atomic(key),
|
|
106
|
+
value,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return output;
|
|
110
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IMetadataTag } from "../../../metadata/IMetadataTag";
|
|
2
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
3
|
+
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
4
|
+
|
|
5
|
+
import { IProtocolMap } from "../../../messages/IProtocolMap";
|
|
6
|
+
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
7
|
+
import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
|
|
8
|
+
import { emplace_protocol_object } from "./emplace_protocol_object";
|
|
9
|
+
import { iterate_protocol_metadata } from "./iterate_protocol_metadata";
|
|
10
|
+
|
|
11
|
+
export const iterate_protocol_repeated =
|
|
12
|
+
(container: "Array" | "Set") =>
|
|
13
|
+
(sole: boolean, bucket: boolean) =>
|
|
14
|
+
(dict: Map<string, IProtocolMessage>) =>
|
|
15
|
+
(meta: Metadata) =>
|
|
16
|
+
(tags: IMetadataTag[]): string | IProtocolMap => {
|
|
17
|
+
sole &&= ProtocolMetadataUtil.standalone(meta);
|
|
18
|
+
if (sole === true)
|
|
19
|
+
return iterate_protocol_metadata(dict)(meta)(tags).oneOf[0]!.type;
|
|
20
|
+
|
|
21
|
+
const obj: MetadataObject = ProtocolMetadataUtil.object(
|
|
22
|
+
`${container}.${bucket ? "Element" : "Wrapper"}<${meta.getName()}>`,
|
|
23
|
+
dict.size,
|
|
24
|
+
);
|
|
25
|
+
obj.properties.push(
|
|
26
|
+
ProtocolMetadataUtil.property(
|
|
27
|
+
"value",
|
|
28
|
+
bucket ? meta : ProtocolMetadataUtil.array(meta),
|
|
29
|
+
tags,
|
|
30
|
+
),
|
|
31
|
+
);
|
|
32
|
+
emplace_protocol_object(dict)(obj);
|
|
33
|
+
return obj.name;
|
|
34
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
2
|
+
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
3
|
+
|
|
4
|
+
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
5
|
+
import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
|
|
6
|
+
import { emplace_protocol_object } from "./emplace_protocol_object";
|
|
7
|
+
|
|
8
|
+
export const iterate_protocol_tuple =
|
|
9
|
+
(dict: Map<string, IProtocolMessage>) =>
|
|
10
|
+
(tuple: Metadata[]): string => {
|
|
11
|
+
const name: string = `[${tuple.map((m) => m.getName()).join(", ")}]`;
|
|
12
|
+
if (dict.has(name)) return name;
|
|
13
|
+
|
|
14
|
+
const obj: MetadataObject = ProtocolMetadataUtil.object(
|
|
15
|
+
name,
|
|
16
|
+
dict.size,
|
|
17
|
+
);
|
|
18
|
+
obj.properties.push(
|
|
19
|
+
...tuple.map((value, i) =>
|
|
20
|
+
ProtocolMetadataUtil.property(
|
|
21
|
+
`v${i}`,
|
|
22
|
+
value.rest ? ProtocolMetadataUtil.array(value.rest) : value,
|
|
23
|
+
[],
|
|
24
|
+
),
|
|
25
|
+
),
|
|
26
|
+
);
|
|
27
|
+
emplace_protocol_object(dict)(obj);
|
|
28
|
+
return obj.name;
|
|
29
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { $varint_decode_i32, $varint_encode } from "./$varint";
|
|
2
|
+
|
|
3
|
+
export function $proto_bytes_encode(
|
|
4
|
+
dst: Uint8Array,
|
|
5
|
+
offset: number,
|
|
6
|
+
value: Uint8Array,
|
|
7
|
+
): number {
|
|
8
|
+
offset = $varint_encode(dst, offset, value.length);
|
|
9
|
+
dst.set(value, offset);
|
|
10
|
+
offset += value.length;
|
|
11
|
+
return offset;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function $proto_bytes_decode(
|
|
15
|
+
src: Uint8Array,
|
|
16
|
+
offset: number,
|
|
17
|
+
): [value: Uint8Array, offset: number] {
|
|
18
|
+
let length = 0;
|
|
19
|
+
|
|
20
|
+
[length, offset] = $varint_decode_i32(src, offset); // Max Length: ~2GB
|
|
21
|
+
const value = src.subarray(offset, offset + length);
|
|
22
|
+
offset += length;
|
|
23
|
+
|
|
24
|
+
return [value, offset];
|
|
25
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { $varint_decode_i32, $varint_encode } from "./$varint";
|
|
2
|
+
|
|
3
|
+
export enum $proto_field_wiretype {
|
|
4
|
+
VARINT = 0,
|
|
5
|
+
I64 = 1,
|
|
6
|
+
LEN = 2,
|
|
7
|
+
SGROUP = 3, // deprecated
|
|
8
|
+
EGROUP = 4, // deprecated
|
|
9
|
+
I32 = 5,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function $proto_field_encode(
|
|
13
|
+
dst: Uint8Array,
|
|
14
|
+
offset: number,
|
|
15
|
+
fieldNumber: number,
|
|
16
|
+
wireType: $proto_field_wiretype,
|
|
17
|
+
): number {
|
|
18
|
+
const tag = (fieldNumber << 3) | Number(wireType);
|
|
19
|
+
return $varint_encode(dst, offset, tag);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function $proto_field_decode(
|
|
23
|
+
buf: Uint8Array,
|
|
24
|
+
offset: number,
|
|
25
|
+
): [fieldNumber: number, wireType: $proto_field_wiretype, offset: number] {
|
|
26
|
+
const [tag, o] = $varint_decode_i32(buf, offset);
|
|
27
|
+
const fieldNumber = tag >>> 3;
|
|
28
|
+
const wireType = tag & 0b111;
|
|
29
|
+
return [fieldNumber, wireType, o];
|
|
30
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function $proto_float32_encode(
|
|
2
|
+
dst: Uint8Array,
|
|
3
|
+
offset: number,
|
|
4
|
+
value: number,
|
|
5
|
+
): number {
|
|
6
|
+
new DataView(dst).setFloat32(offset, value, true);
|
|
7
|
+
offset += 4;
|
|
8
|
+
return offset;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function $proto_float32_decode(
|
|
12
|
+
src: Uint8Array,
|
|
13
|
+
offset: number,
|
|
14
|
+
): [value: number, offset: number] {
|
|
15
|
+
const value = new DataView(src).getFloat32(offset, true);
|
|
16
|
+
offset += 4;
|
|
17
|
+
return [value, offset];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function $proto_float64_encode(
|
|
21
|
+
dst: Uint8Array,
|
|
22
|
+
offset: number,
|
|
23
|
+
value: number,
|
|
24
|
+
): number {
|
|
25
|
+
new DataView(dst).setFloat64(offset, value, true);
|
|
26
|
+
offset += 8;
|
|
27
|
+
return offset;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function $proto_float64_decode(
|
|
31
|
+
src: Uint8Array,
|
|
32
|
+
offset: number,
|
|
33
|
+
): [value: number, offset: number] {
|
|
34
|
+
const value = new DataView(src).getFloat64(offset, true);
|
|
35
|
+
offset += 8;
|
|
36
|
+
return [value, offset];
|
|
37
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function $proto_i32_encode(
|
|
2
|
+
dst: Uint8Array,
|
|
3
|
+
offset: number,
|
|
4
|
+
value: number,
|
|
5
|
+
): number {
|
|
6
|
+
value = (value | 0) >>> 0;
|
|
7
|
+
|
|
8
|
+
dst[offset] = value & 0xff;
|
|
9
|
+
dst[offset + 1] = (value >>> 8) & 0xff;
|
|
10
|
+
dst[offset + 2] = (value >>> 16) & 0xff;
|
|
11
|
+
dst[offset + 3] = (value >>> 24) & 0xff;
|
|
12
|
+
offset += 4;
|
|
13
|
+
|
|
14
|
+
return offset;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function $proto_i32_decode(
|
|
18
|
+
buf: Uint8Array,
|
|
19
|
+
offset: number,
|
|
20
|
+
): [value: number, offset: number] {
|
|
21
|
+
const value =
|
|
22
|
+
(buf[offset]! << 0) |
|
|
23
|
+
(buf[offset + 1]! << 8) |
|
|
24
|
+
(buf[offset + 2]! << 16) |
|
|
25
|
+
(buf[offset + 3]! << 24);
|
|
26
|
+
offset += 4;
|
|
27
|
+
|
|
28
|
+
return [value, offset];
|
|
29
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function $proto_i64_encode(
|
|
2
|
+
dst: Uint8Array,
|
|
3
|
+
offset: number,
|
|
4
|
+
value: bigint,
|
|
5
|
+
): number {
|
|
6
|
+
value = BigInt.asUintN(64, value);
|
|
7
|
+
|
|
8
|
+
dst[offset] = Number(value & BigInt(0xff));
|
|
9
|
+
dst[offset + 1] = Number((value >> BigInt(8)) & BigInt(0xff));
|
|
10
|
+
dst[offset + 2] = Number((value >> BigInt(16)) & BigInt(0xff));
|
|
11
|
+
dst[offset + 3] = Number((value >> BigInt(24)) & BigInt(0xff));
|
|
12
|
+
dst[offset + 4] = Number((value >> BigInt(32)) & BigInt(0xff));
|
|
13
|
+
dst[offset + 5] = Number((value >> BigInt(40)) & BigInt(0xff));
|
|
14
|
+
dst[offset + 6] = Number((value >> BigInt(48)) & BigInt(0xff));
|
|
15
|
+
dst[offset + 7] = Number((value >> BigInt(56)) & BigInt(0xff));
|
|
16
|
+
offset += 8;
|
|
17
|
+
|
|
18
|
+
return offset;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function $proto_i64_decode(
|
|
22
|
+
buf: Uint8Array,
|
|
23
|
+
offset: number,
|
|
24
|
+
): [value: bigint, offset: number] {
|
|
25
|
+
const value =
|
|
26
|
+
(BigInt(buf[offset]!) << BigInt(0)) |
|
|
27
|
+
(BigInt(buf[offset + 1]!) << BigInt(8)) |
|
|
28
|
+
(BigInt(buf[offset + 2]!) << BigInt(16)) |
|
|
29
|
+
(BigInt(buf[offset + 3]!) << BigInt(24)) |
|
|
30
|
+
(BigInt(buf[offset + 4]!) << BigInt(32)) |
|
|
31
|
+
(BigInt(buf[offset + 5]!) << BigInt(40)) |
|
|
32
|
+
(BigInt(buf[offset + 6]!) << BigInt(48)) |
|
|
33
|
+
(BigInt(buf[offset + 7]!) << BigInt(56));
|
|
34
|
+
offset += 8;
|
|
35
|
+
|
|
36
|
+
return [BigInt.asIntN(64, value), offset];
|
|
37
|
+
}
|