@2702rebels/wpidata 1.0.0 → 1.0.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/dist/abstractions.d.cts +140 -140
- package/dist/abstractions.d.cts.map +1 -1
- package/dist/abstractions.d.mts +140 -140
- package/dist/abstractions.d.mts.map +1 -1
- package/dist/formats/json.d.cts.map +1 -1
- package/dist/formats/json.d.mts.map +1 -1
- package/dist/formats/msgpack.d.cts.map +1 -1
- package/dist/formats/msgpack.d.mts.map +1 -1
- package/dist/formats/protobuf.d.cts +21 -22
- package/dist/formats/protobuf.d.cts.map +1 -1
- package/dist/formats/protobuf.d.mts +21 -22
- package/dist/formats/protobuf.d.mts.map +1 -1
- package/dist/formats/protobuf.mjs.map +1 -1
- package/dist/formats/struct.cjs +17 -4
- package/dist/formats/struct.d.cts +52 -65
- package/dist/formats/struct.d.cts.map +1 -1
- package/dist/formats/struct.d.mts +52 -65
- package/dist/formats/struct.d.mts.map +1 -1
- package/dist/formats/struct.mjs +17 -4
- package/dist/formats/struct.mjs.map +1 -1
- package/dist/sink.d.cts +35 -43
- package/dist/sink.d.cts.map +1 -1
- package/dist/sink.d.mts +35 -43
- package/dist/sink.d.mts.map +1 -1
- package/dist/types/protobuf.d.cts.map +1 -1
- package/dist/types/protobuf.d.mts.map +1 -1
- package/dist/types/sendable.d.cts.map +1 -1
- package/dist/types/sendable.d.mts.map +1 -1
- package/dist/types/struct.d.cts.map +1 -1
- package/dist/types/struct.d.mts.map +1 -1
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts.map +1 -1
- package/package.json +4 -4
- package/src/formats/protobuf.ts +1 -0
- package/src/formats/struct.test.ts +49 -0
- package/src/formats/struct.ts +34 -4
package/dist/abstractions.d.mts
CHANGED
|
@@ -3,134 +3,134 @@ type DataType = "boolean" | "string" | "number" | "booleanArray" | "stringArray"
|
|
|
3
3
|
type DataTypeImpl = boolean | string | number | Array<boolean> | Array<string> | Array<number> | Record<string, unknown> | Array<Record<string, unknown>> | Uint8Array;
|
|
4
4
|
interface StructuredTypeDescriptor {
|
|
5
5
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
* **Type name**
|
|
7
|
+
*
|
|
8
|
+
* Typically the name represents the original type name without any adorners.
|
|
9
|
+
* For example, `struct:Pose3d`, `struct:Pose3d[]` would be represented
|
|
10
|
+
* as `Pose3d`, and `proto:wpi.proto.ProtobufPose3d` as `wpi.proto.ProtobufPose3d`.
|
|
11
|
+
*
|
|
12
|
+
* To determine if the parsed value is an array, consult `array` indicator and
|
|
13
|
+
* use `Array.isArray` method.
|
|
14
|
+
*/
|
|
15
15
|
readonly name: string;
|
|
16
16
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
* **Type format**
|
|
18
|
+
*
|
|
19
|
+
* Represents the origin (protocol) of the deserialized data.
|
|
20
|
+
*
|
|
21
|
+
* Due to WPILIB idiosyncrasies deserialized JSON representation of the same
|
|
22
|
+
* structured type may differ across various serialization protocols.
|
|
23
|
+
*/
|
|
24
24
|
readonly format: "protobuf" | "struct" | "composite";
|
|
25
25
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
* **Array indicator**
|
|
27
|
+
*
|
|
28
|
+
* Indicates that the value contains a top-level array of type.
|
|
29
|
+
*/
|
|
30
30
|
readonly isArray?: boolean;
|
|
31
31
|
}
|
|
32
32
|
interface DataChannelRecord<T extends DataTypeImpl = DataTypeImpl> {
|
|
33
33
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
* **Timestamp (microseconds)**
|
|
35
|
+
*
|
|
36
|
+
* Timestamp of the record in microseconds. Typically represents robot time.
|
|
37
|
+
*/
|
|
38
38
|
readonly timestamp: number;
|
|
39
39
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
* **Value**
|
|
41
|
+
*
|
|
42
|
+
* Record value. Depends on the {@link DataChannel.dataType}.
|
|
43
|
+
*/
|
|
44
44
|
value: T;
|
|
45
45
|
}
|
|
46
46
|
interface DataChannelBase<T extends DataTypeImpl = DataTypeImpl> {
|
|
47
47
|
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
* **Channel source**
|
|
49
|
+
*
|
|
50
|
+
* For example, `nt` or `wpilog`. This field is considered opaque.
|
|
51
|
+
*/
|
|
52
52
|
readonly source: string;
|
|
53
53
|
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
* **Channel identifier**
|
|
55
|
+
*
|
|
56
|
+
* Must be unique within the data source.
|
|
57
|
+
* NT4 — topic name
|
|
58
|
+
* WPILOG — data channel identifier
|
|
59
|
+
*/
|
|
60
60
|
readonly id: string;
|
|
61
61
|
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
62
|
+
* **Data representation type**
|
|
63
|
+
*
|
|
64
|
+
* This type indicates the processed data representation in the Javascript world.
|
|
65
|
+
* For example, NT4 source may differentiate between numeric types, such as
|
|
66
|
+
* 32-bit integer and 64-bit float, yet both are stored as `number`.
|
|
67
|
+
*
|
|
68
|
+
* Complex types are typically serialized using JSON, msgpack, struct or protobuf
|
|
69
|
+
* protocols and require a corresponding data transformer to be registered in
|
|
70
|
+
* the pipeline to unpack them. If no transformer is present the raw `binary`
|
|
71
|
+
* representation is used where data is stored in a byte array buffer.
|
|
72
|
+
*/
|
|
73
73
|
readonly dataType: DataType;
|
|
74
74
|
/**
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
* **Raw data type**
|
|
76
|
+
*
|
|
77
|
+
* Raw data type string to be used for publishing. Retains original type specifics
|
|
78
|
+
* that cannot be represented in the JavaScript world, such as differences between
|
|
79
|
+
* various numeric types.
|
|
80
|
+
*/
|
|
81
81
|
readonly publishedDataType: string;
|
|
82
82
|
/**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
* **Protocol transformer**
|
|
84
|
+
*
|
|
85
|
+
* Unpacks raw binary data into JSON object according to the serialization protocol.
|
|
86
|
+
*/
|
|
87
87
|
readonly transformer?: DataTransformer;
|
|
88
88
|
/**
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
* **Structured type descriptor**
|
|
90
|
+
*
|
|
91
|
+
* Applicable to complex types, serialized as struct or protobuf. Must be set
|
|
92
|
+
* by the corresponding transformer.
|
|
93
|
+
*/
|
|
94
94
|
structuredType?: StructuredTypeDescriptor;
|
|
95
95
|
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
96
|
+
* **Channel metadata**
|
|
97
|
+
*
|
|
98
|
+
* For NT4 metadata is extracted from topic properties beyond the default set.
|
|
99
|
+
* For WPILOG metadata is read and attempted to be parsed as JSON object first
|
|
100
|
+
* and stored as string otherwise.
|
|
101
|
+
*
|
|
102
|
+
* This field represents the most recently seen values as published by the source.
|
|
103
|
+
*/
|
|
104
104
|
metadata?: Record<string, unknown> | string;
|
|
105
105
|
/**
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
* **Timestamped records**
|
|
107
|
+
*
|
|
108
|
+
* Timestamps are provided by the data source. The array is sorted by the timestamp
|
|
109
|
+
* in ascending order, earlier records have smaller indices.
|
|
110
|
+
*/
|
|
111
111
|
records?: Array<DataChannelRecord<T>>;
|
|
112
112
|
/**
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
113
|
+
* **Timestamped dead-letter queue**
|
|
114
|
+
*
|
|
115
|
+
* Records that cannot be yet unpacked due to missing type descriptors.
|
|
116
|
+
*
|
|
117
|
+
* Timestamps are provided by the data source. The array is sorted by the timestamp
|
|
118
|
+
* in ascending order, earlier records have smaller indices.
|
|
119
|
+
*/
|
|
120
120
|
dlq?: Array<DataChannelRecord<Uint8Array>>;
|
|
121
121
|
/**
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
* **Composite channel container**
|
|
123
|
+
*
|
|
124
|
+
* Returns the container composite channel for sub-channels that are part of it.
|
|
125
|
+
*/
|
|
126
126
|
composite?: CompositeDataChannel;
|
|
127
127
|
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
128
|
+
* **Publishes value to the channel**
|
|
129
|
+
*
|
|
130
|
+
* @param value value to publish
|
|
131
|
+
* @param path optional path to the sub-channel
|
|
132
|
+
* @param options additional publisher options
|
|
133
|
+
*/
|
|
134
134
|
publish?: (value: unknown, path?: ReadonlyArray<string>, options?: DataChannelPublisherOptions) => void;
|
|
135
135
|
}
|
|
136
136
|
interface BooleanDataChannel extends DataChannelBase<boolean> {
|
|
@@ -160,11 +160,11 @@ interface BinaryDataChannel extends DataChannelBase<Uint8Array> {
|
|
|
160
160
|
interface CompositeDataChannel extends DataChannelBase<Record<string, unknown>> {
|
|
161
161
|
readonly dataType: "composite";
|
|
162
162
|
/**
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
163
|
+
* **Sub-channel identifiers and record paths**
|
|
164
|
+
*
|
|
165
|
+
* Identifiers of individual data channels that comprise this composite channel
|
|
166
|
+
* and their respective paths for the data to be written in the JSON record.
|
|
167
|
+
*/
|
|
168
168
|
channels: Map<string, Array<string>>;
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
@@ -186,55 +186,55 @@ type DataChannel = BooleanDataChannel | StringDataChannel | NumberDataChannel |
|
|
|
186
186
|
*/
|
|
187
187
|
interface DataTransformer {
|
|
188
188
|
/**
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
189
|
+
* Inspects a channel to determine whether it represents a schema or a data channel
|
|
190
|
+
* that must run through this transformer.
|
|
191
|
+
*
|
|
192
|
+
* This method must return either a {@link DataChannel} instance indicating a data
|
|
193
|
+
* channel, which must have {@link DataChannel.transformer} field set, or a string
|
|
194
|
+
* containing the schema type name indicating a schema channel. Otherwise,
|
|
195
|
+
* a value of `undefined` must be returned.
|
|
196
|
+
*
|
|
197
|
+
* @param source source
|
|
198
|
+
* @param name channel name
|
|
199
|
+
* @param type channel type
|
|
200
|
+
* @param metadata channel metadata
|
|
201
|
+
* @returns data channel, schema type name or `undefined`
|
|
202
|
+
*/
|
|
203
203
|
inspect(source: string, name: string, type: string, metadata?: Record<string, unknown> | string): DataChannel | string | undefined;
|
|
204
204
|
/**
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
205
|
+
* Ingests raw schema data for the specified type name. This method will be invoked
|
|
206
|
+
* when the data arrives on a schema channel previously identified by {@link inspect}.
|
|
207
|
+
*
|
|
208
|
+
* @param typeName schema type name previously returned by {@link inspect}
|
|
209
|
+
* @param value raw schema data
|
|
210
|
+
*/
|
|
211
211
|
schema(typeName: string, value: unknown): void;
|
|
212
212
|
/**
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
213
|
+
* Deserializes raw data. If the data cannot be transformed yet due to missing
|
|
214
|
+
* schema dependencies, this method must return `undefined` and the data will
|
|
215
|
+
* stored in the dead-letter queue to retry automatically at a later time.
|
|
216
|
+
*
|
|
217
|
+
* @param value raw value to deserialize
|
|
218
|
+
* @param type an optional {@link DataChannel.structuredType} descriptor
|
|
219
|
+
* @returns a deserialized value on success or `undefined` otherwise
|
|
220
|
+
*/
|
|
221
221
|
deserialize(value: unknown, type?: StructuredTypeDescriptor): DataTypeImpl | undefined;
|
|
222
222
|
/**
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
223
|
+
* Serializes data into a raw format for publishing.
|
|
224
|
+
*
|
|
225
|
+
* @param value value to serialize
|
|
226
|
+
* @param type an optional {@link DataChannel.structuredType} descriptor
|
|
227
|
+
* @returns a serialized representation of the value
|
|
228
|
+
*/
|
|
229
229
|
serialize(value: unknown, type?: StructuredTypeDescriptor): string | Uint8Array;
|
|
230
230
|
/**
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
231
|
+
* Determines whether data with the specified `type` can be transformed.
|
|
232
|
+
*
|
|
233
|
+
* The transformer may not be able to transform certain types if it is missing
|
|
234
|
+
* corresponding type descriptors yet to arrive via schema channel.
|
|
235
|
+
*
|
|
236
|
+
* @param type type name
|
|
237
|
+
*/
|
|
238
238
|
canTransform(type: string): boolean;
|
|
239
239
|
}
|
|
240
240
|
interface DataChannelPublisherOptions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstractions.d.mts","names":[],"sources":["../src/abstractions.ts"],"
|
|
1
|
+
{"version":3,"file":"abstractions.d.mts","names":[],"sources":["../src/abstractions.ts"],"mappings":";KAAY,QAAA;AAA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,sBAAA,SAA+B,eAAA,CAAgB,KAAA;EAAA,SAAA,QAAA;AAAA;AAAA,UAI/C,sBAAA,SAA+B,eAAA,CAAgB,KAAA;EAAA,SAAA,QAAA;AAAA;AAAA,UAI/C,eAAA,SAAwB,eAAA,CAAgB,MAAA;EAAA,SAAA,QAAA;AAAA;AAAA,UAIxC,iBAAA,SAA0B,eAAA,CAAgB,UAAA;EAAA,SAAA,QAAA;AAAA;AAAA,UAI1C,oBAAA,SAA6B,eAAA,CAAgB,MAAA;EAAA,SAAA,QAAA;EAAA;;;;;AAkB9D;EAlB8D,QAAA,EASlD,GAAA,SAAY,KAAA;AAAA;AAAA;;;;AASxB;;AATwB,KASZ,WAAA,GACR,kBAAA,GACA,iBAAA,GACA,iBAAA,GACA,uBAAA,GACA,sBAAA,GACA,sBAAA,GACA,eAAA,GACA,iBAAA,GACA,oBAAA;AAAA;;AAYJ;;;;;;;;AAZI,UAYa,eAAA;EAAA;;;;;;;;AA+DjB;;;;;;;EA/DiB,OAAA,CAAA,MAAA,UAAA,IAAA,UAAA,IAAA,UAAA,QAAA,GAoBF,MAAA,6BACV,WAAA;EAAA;;;;;;AA0CL;EA1CK,MAAA,CAAA,QAAA,UAAA,KAAA;EAAA;;;;;;AA0CL;;;EA1CK,WAAA,CAAA,KAAA,WAAA,IAAA,GAoBgC,wBAAA,GAA2B,YAAA;EAAA;;;;AAsBhE;;;EAtBgE,SAAA,CAAA,KAAA,WAAA,IAAA,GAS7B,wBAAA,YAAoC,UAAA;EAAA;;AAavE;;;;;;EAbuE,YAAA,CAAA,IAAA;AAAA;AAAA,UAatD,2BAAA;EAAA;EAAA,cAAA,GAEE,wBAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.d.cts","names":[],"sources":["../../src/formats/json.ts"],"
|
|
1
|
+
{"version":3,"file":"json.d.cts","names":[],"sources":["../../src/formats/json.ts"],"mappings":";;;;cAUa,mBAAA,YAA+B,eAAA;EAAA,QAAA,MAAA,UAAA,IAAA,UAAA,IAAA,UAAA,QAAA,YAKpB,MAAA,oBACnB,WAAA;EAAA,OAAA;EAAA,YAAA,KAAA,YAiBiC,YAAA;EAAA,UAAA,KAAA,qBAQO,UAAA;EAAA,aAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.d.mts","names":[],"sources":["../../src/formats/json.ts"],"
|
|
1
|
+
{"version":3,"file":"json.d.mts","names":[],"sources":["../../src/formats/json.ts"],"mappings":";;;;cAUa,mBAAA,YAA+B,eAAA;EAAA,QAAA,MAAA,UAAA,IAAA,UAAA,IAAA,UAAA,QAAA,YAKpB,MAAA,oBACnB,WAAA;EAAA,OAAA;EAAA,YAAA,KAAA,YAiBiC,YAAA;EAAA,UAAA,KAAA,qBAQO,UAAA;EAAA,aAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"msgpack.d.cts","names":[],"sources":["../../src/formats/msgpack.ts"],"
|
|
1
|
+
{"version":3,"file":"msgpack.d.cts","names":[],"sources":["../../src/formats/msgpack.ts"],"mappings":";;;;cAOa,sBAAA,YAAkC,eAAA;EAAA,QAAA,MAAA,UAAA,IAAA,UAAA,IAAA,UAAA,QAAA,YAKvB,MAAA,oBACnB,WAAA;EAAA,OAAA;EAAA,YAAA,KAAA,YAiBiC,YAAA;EAAA,UAAA,KAAA,YAIF,UAAA;EAAA,aAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"msgpack.d.mts","names":[],"sources":["../../src/formats/msgpack.ts"],"
|
|
1
|
+
{"version":3,"file":"msgpack.d.mts","names":[],"sources":["../../src/formats/msgpack.ts"],"mappings":";;;;cAOa,sBAAA,YAAkC,eAAA;EAAA,QAAA,MAAA,UAAA,IAAA,UAAA,IAAA,UAAA,QAAA,YAKvB,MAAA,oBACnB,WAAA;EAAA,OAAA;EAAA,YAAA,KAAA,YAiBiC,YAAA;EAAA,UAAA,KAAA,YAIF,UAAA;EAAA,aAAA;AAAA"}
|
|
@@ -2,7 +2,6 @@ import { DataChannel, DataTransformer, DataTypeImpl, StructuredTypeDescriptor }
|
|
|
2
2
|
import { Root } from "protobufjs";
|
|
3
3
|
|
|
4
4
|
//#region src/formats/protobuf.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Unpacks protobuf serialized data into JSON object.
|
|
8
7
|
*
|
|
@@ -23,35 +22,35 @@ declare function pack(name: string, value: Record<string, unknown>, repository:
|
|
|
23
22
|
/** Repository of protobuf descriptors. */
|
|
24
23
|
declare class ProtobufRepository {
|
|
25
24
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
* Root namespace.
|
|
26
|
+
*/
|
|
28
27
|
root: Root;
|
|
29
28
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
* Determines whether type can be transformed, indicating that
|
|
30
|
+
* the parsed type descriptor is present.
|
|
31
|
+
*
|
|
32
|
+
* @param name protobuf descriptor name
|
|
33
|
+
*/
|
|
35
34
|
canTransform(name: string): boolean;
|
|
36
35
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
* Unpacks protobuf serialized data into JSON object.
|
|
37
|
+
*
|
|
38
|
+
* @param name protobuf descriptor name
|
|
39
|
+
* @param data serialized binary data
|
|
40
|
+
*/
|
|
42
41
|
unpack(name: string, data: Uint8Array<ArrayBufferLike>): Record<string, unknown>;
|
|
43
42
|
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
* Packs JSON object into serialized protobuf data.
|
|
44
|
+
*
|
|
45
|
+
* @param name protobuf descriptor name
|
|
46
|
+
* @param value JSON object to pack
|
|
47
|
+
*/
|
|
49
48
|
pack(name: string, value: Record<string, unknown>): Uint8Array<ArrayBufferLike>;
|
|
50
49
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
* Parses protobuf file descriptor and adds it to the repository.
|
|
51
|
+
*
|
|
52
|
+
* @param data descriptor binary data
|
|
53
|
+
*/
|
|
55
54
|
add(data: Uint8Array<ArrayBufferLike>): void;
|
|
56
55
|
}
|
|
57
56
|
/** Implements {@link DataTransformer} interface for the `protobuf` serialization protocol. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protobuf.d.cts","names":[],"sources":["../../src/formats/protobuf.ts"],"
|
|
1
|
+
{"version":3,"file":"protobuf.d.cts","names":[],"sources":["../../src/formats/protobuf.ts"],"mappings":";;;;;AAqBA;;;;;;iBAAgB,MAAA,CAAA,IAAA,UAAA,IAAA,EAER,UAAA,CAAW,eAAA,GAAA,UAAA,EACL,kBAAA,GACX,MAAA;AAAA;;AAaH;;;;;AAMA;AAnBG,iBAaa,IAAA,CAAA,IAAA,UAAA,KAAA,EAA0B,MAAA,mBAAA,UAAA,EAAqC,kBAAA,GAAqB,UAAA;AAAA;AAAA,cAMvF,kBAAA;EAAA;;;EAAA,IAAA,EAIA,IAAA;EAAA;;;;;;EAAA,aAAA,IAAA;EAAA;;;;;;EAAA,OAAA,IAAA,UAAA,IAAA,EAsBuB,UAAA,CAAW,eAAA,IAAgB,MAAA;EAAA;;;;;;EAAA,KAAA,IAAA,UAAA,KAAA,EAU5B,MAAA,oBAAuB,UAAA,CAAA,eAAA;EAAA;;;;;EAAA,IAAA,IAAA,EASvC,UAAA,CAAW,eAAA;AAAA;AAAA;AAAA,cAkDjB,uBAAA,YAAmC,eAAA;EAAA,iBAAA,IAAA;EAAA,QAAA,MAAA,UAAA,IAAA,UAAA,IAAA,UAAA,QAAA,YAOxB,MAAA,oBACnB,WAAA;EAAA,OAAA,QAAA,UAAA,KAAA;EAAA,YAAA,KAAA,WAAA,IAAA,GA+BuC,wBAAA,GAA2B,YAAA;EAAA,UAAA,KAAA,WAAA,IAAA,GAc7B,wBAAA,GAA2B,UAAA;EAAA,aAAA,IAAA;AAAA"}
|
|
@@ -2,7 +2,6 @@ import { DataChannel, DataTransformer, DataTypeImpl, StructuredTypeDescriptor }
|
|
|
2
2
|
import { Root } from "protobufjs";
|
|
3
3
|
|
|
4
4
|
//#region src/formats/protobuf.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Unpacks protobuf serialized data into JSON object.
|
|
8
7
|
*
|
|
@@ -23,35 +22,35 @@ declare function pack(name: string, value: Record<string, unknown>, repository:
|
|
|
23
22
|
/** Repository of protobuf descriptors. */
|
|
24
23
|
declare class ProtobufRepository {
|
|
25
24
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
* Root namespace.
|
|
26
|
+
*/
|
|
28
27
|
root: Root;
|
|
29
28
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
* Determines whether type can be transformed, indicating that
|
|
30
|
+
* the parsed type descriptor is present.
|
|
31
|
+
*
|
|
32
|
+
* @param name protobuf descriptor name
|
|
33
|
+
*/
|
|
35
34
|
canTransform(name: string): boolean;
|
|
36
35
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
* Unpacks protobuf serialized data into JSON object.
|
|
37
|
+
*
|
|
38
|
+
* @param name protobuf descriptor name
|
|
39
|
+
* @param data serialized binary data
|
|
40
|
+
*/
|
|
42
41
|
unpack(name: string, data: Uint8Array<ArrayBufferLike>): Record<string, unknown>;
|
|
43
42
|
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
* Packs JSON object into serialized protobuf data.
|
|
44
|
+
*
|
|
45
|
+
* @param name protobuf descriptor name
|
|
46
|
+
* @param value JSON object to pack
|
|
47
|
+
*/
|
|
49
48
|
pack(name: string, value: Record<string, unknown>): Uint8Array<ArrayBufferLike>;
|
|
50
49
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
* Parses protobuf file descriptor and adds it to the repository.
|
|
51
|
+
*
|
|
52
|
+
* @param data descriptor binary data
|
|
53
|
+
*/
|
|
55
54
|
add(data: Uint8Array<ArrayBufferLike>): void;
|
|
56
55
|
}
|
|
57
56
|
/** Implements {@link DataTransformer} interface for the `protobuf` serialization protocol. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protobuf.d.mts","names":[],"sources":["../../src/formats/protobuf.ts"],"
|
|
1
|
+
{"version":3,"file":"protobuf.d.mts","names":[],"sources":["../../src/formats/protobuf.ts"],"mappings":";;;;;AAqBA;;;;;;iBAAgB,MAAA,CAAA,IAAA,UAAA,IAAA,EAER,UAAA,CAAW,eAAA,GAAA,UAAA,EACL,kBAAA,GACX,MAAA;AAAA;;AAaH;;;;;AAMA;AAnBG,iBAaa,IAAA,CAAA,IAAA,UAAA,KAAA,EAA0B,MAAA,mBAAA,UAAA,EAAqC,kBAAA,GAAqB,UAAA;AAAA;AAAA,cAMvF,kBAAA;EAAA;;;EAAA,IAAA,EAIA,IAAA;EAAA;;;;;;EAAA,aAAA,IAAA;EAAA;;;;;;EAAA,OAAA,IAAA,UAAA,IAAA,EAsBuB,UAAA,CAAW,eAAA,IAAgB,MAAA;EAAA;;;;;;EAAA,KAAA,IAAA,UAAA,KAAA,EAU5B,MAAA,oBAAuB,UAAA,CAAA,eAAA;EAAA;;;;;EAAA,IAAA,IAAA,EASvC,UAAA,CAAW,eAAA;AAAA;AAAA;AAAA,cAkDjB,uBAAA,YAAmC,eAAA;EAAA,iBAAA,IAAA;EAAA,QAAA,MAAA,UAAA,IAAA,UAAA,IAAA,UAAA,QAAA,YAOxB,MAAA,oBACnB,WAAA;EAAA,OAAA,QAAA,UAAA,KAAA;EAAA,YAAA,KAAA,WAAA,IAAA,GA+BuC,wBAAA,GAA2B,YAAA;EAAA,UAAA,KAAA,WAAA,IAAA,GAc7B,wBAAA,GAA2B,UAAA;EAAA,aAAA,IAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protobuf.mjs","names":[],"sources":["../../src/formats/protobuf.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\n\nimport { Enum, Field, Root, Service, Type } from \"protobufjs\";\nimport { FileDescriptorProto } from \"protobufjs/ext/descriptor\";\n\nimport { toUint8Array } from \"../utils\";\n\nimport type { IFileDescriptorProto } from \"protobufjs/ext/descriptor\";\nimport type { DataChannel, DataTransformer, DataTypeImpl, StructuredTypeDescriptor } from \"../abstractions\";\n\nconst error = (message: string) => {\n return new Error(message);\n};\n\n/**\n * Unpacks protobuf serialized data into JSON object.\n *\n * @param name protobuf descriptor name\n * @param data serialized binary data\n * @param repository repository of available descriptors\n */\nexport function unpack(\n name: string,\n data: Uint8Array<ArrayBufferLike>,\n repository: ProtobufRepository\n): Record<string, unknown> {\n const type = repository.root.lookupType(name); // throws on error\n return type.decode(data) as unknown as Record<string, unknown>;\n}\n/**\n * Packs JSON object into serialized protobuf data.\n *\n * @param name protobuf descriptor name\n * @param value JSON object to pack\n * @param repository repository of available descriptors\n * @returns ArrayBuffer containing serialized data\n */\nexport function pack(name: string, value: Record<string, unknown>, repository: ProtobufRepository): Uint8Array {\n const type = repository.root.lookupType(name); // throws on error\n return type.encode(value).finish();\n}\n\n/** Repository of protobuf descriptors. */\nexport class ProtobufRepository {\n /**\n * Root namespace.\n */\n public root = new Root();\n\n /**\n * Determines whether type can be transformed, indicating that\n * the parsed type descriptor is present.\n *\n * @param name protobuf descriptor name\n */\n public canTransform(name: string) {\n try {\n return this.root.lookupType(name) != null;\n } catch {\n return false;\n }\n }\n\n /**\n * Unpacks protobuf serialized data into JSON object.\n *\n * @param name protobuf descriptor name\n * @param data serialized binary data\n */\n public unpack(name: string, data: Uint8Array<ArrayBufferLike>) {\n return unpack(name, data, this);\n }\n\n /**\n * Packs JSON object into serialized protobuf data.\n *\n * @param name protobuf descriptor name\n * @param value JSON object to pack\n */\n public pack(name: string, value: Record<string, unknown>) {\n return pack(name, value, this);\n }\n\n /**\n * Parses protobuf file descriptor and adds it to the repository.\n *\n * @param data descriptor binary data\n */\n public add(data: Uint8Array<ArrayBufferLike>): void {\n const fd = FileDescriptorProto.decode(data) as IFileDescriptorProto;\n if (fd.name == null) {\n throw error(`Failed to parse protobuf file descriptor: missing name`);\n }\n\n // ignore duplicates\n if (this.root.files.includes(fd.name)) {\n return;\n // throw error(`Failed to parse protobuf file descriptor: duplicate '${fd.name}' filename`);\n }\n\n const filePackage = fd.package ? this.root.define(fd.package) : this.root;\n\n if (fd.name) {\n filePackage.filename = fd.name;\n this.root.files.push(fd.name);\n }\n\n if (fd.messageType) {\n for (const messageType of fd.messageType) {\n // @ts-expect-error\n filePackage.add(Type.fromDescriptor(messageType, fd.syntax));\n }\n }\n\n if (fd.enumType) {\n for (const enumType of fd.enumType) {\n // @ts-expect-error\n filePackage.add(Enum.fromDescriptor(enumType));\n }\n }\n\n if (fd.extension) {\n for (const extension of fd.extension) {\n // @ts-expect-error\n filePackage.add(Field.fromDescriptor(extension));\n }\n }\n\n if (fd.service) {\n for (const service of fd.service) {\n // @ts-expect-error\n filePackage.add(Service.fromDescriptor(service));\n }\n }\n }\n}\n\n/** Implements {@link DataTransformer} interface for the `protobuf` serialization protocol. */\nexport class ProtobufDataTransformer implements DataTransformer {\n private readonly repo = new ProtobufRepository();\n\n public inspect(\n source: string,\n name: string,\n type: string,\n metadata?: string | Record<string, unknown>\n ): DataChannel | string | undefined {\n if (name.startsWith(\"/.schema/proto:\")) {\n if (type !== \"proto:FileDescriptorProto\") {\n throw new Error(`Unexpected type '${type}' for protobuf schema entry`);\n }\n\n return name.substring(15);\n }\n\n if (type.startsWith(\"proto:\")) {\n return {\n source,\n id: name,\n dataType: \"json\",\n publishedDataType: type,\n transformer: this,\n structuredType: {\n name: type.slice(6),\n format: \"protobuf\",\n },\n metadata,\n };\n }\n\n return undefined;\n }\n\n public schema(typeName: string, value: unknown) {\n this.repo.add(toUint8Array(value));\n }\n\n public deserialize(value: unknown, type?: StructuredTypeDescriptor): DataTypeImpl | undefined {\n if (type == null) {\n throw new Error(\n `Transformation requires type to be specified. This situation should not be possible if the transformer is wired correctly.`\n );\n }\n\n if (this.repo.canTransform(type.name)) {\n return this.repo.unpack(type.name, toUint8Array(value));\n }\n\n return undefined;\n }\n\n public serialize(value: unknown, type?: StructuredTypeDescriptor): Uint8Array {\n if (type == null) {\n throw new Error(\n `Transformation requires type to be specified. This situation should not be possible if the transformer is wired correctly.`\n );\n }\n\n if (value == null || typeof value !== \"object\") {\n throw new Error(\"Only JSON objects can be serialized\");\n }\n\n if (this.repo.canTransform(type.name)) {\n return this.repo.pack(type.name, value as Record<string, unknown>);\n }\n\n throw new Error(`Protobuf serialization is not supported for '${type.name}'`);\n }\n\n public canTransform(type: string): boolean {\n return this.repo.canTransform(type);\n }\n}\n"],"mappings":";;;;;AAUA,MAAM,SAAS,YAAoB;AACjC,QAAO,IAAI,MAAM,QAAQ;;;;;;;;;AAU3B,SAAgB,OACd,MACA,MACA,YACyB;AAEzB,QADa,WAAW,KAAK,WAAW,KAAK,CACjC,OAAO,KAAK;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"protobuf.mjs","names":[],"sources":["../../src/formats/protobuf.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\n\nimport { Enum, Field, Root, Service, Type } from \"protobufjs\";\nimport { FileDescriptorProto } from \"protobufjs/ext/descriptor\";\n\nimport { toUint8Array } from \"../utils\";\n\nimport type { IFileDescriptorProto } from \"protobufjs/ext/descriptor\";\nimport type { DataChannel, DataTransformer, DataTypeImpl, StructuredTypeDescriptor } from \"../abstractions\";\n\nconst error = (message: string) => {\n return new Error(message);\n};\n\n/**\n * Unpacks protobuf serialized data into JSON object.\n *\n * @param name protobuf descriptor name\n * @param data serialized binary data\n * @param repository repository of available descriptors\n */\nexport function unpack(\n name: string,\n data: Uint8Array<ArrayBufferLike>,\n repository: ProtobufRepository\n): Record<string, unknown> {\n const type = repository.root.lookupType(name); // throws on error\n return type.decode(data) as unknown as Record<string, unknown>;\n}\n\n/**\n * Packs JSON object into serialized protobuf data.\n *\n * @param name protobuf descriptor name\n * @param value JSON object to pack\n * @param repository repository of available descriptors\n * @returns ArrayBuffer containing serialized data\n */\nexport function pack(name: string, value: Record<string, unknown>, repository: ProtobufRepository): Uint8Array {\n const type = repository.root.lookupType(name); // throws on error\n return type.encode(value).finish();\n}\n\n/** Repository of protobuf descriptors. */\nexport class ProtobufRepository {\n /**\n * Root namespace.\n */\n public root = new Root();\n\n /**\n * Determines whether type can be transformed, indicating that\n * the parsed type descriptor is present.\n *\n * @param name protobuf descriptor name\n */\n public canTransform(name: string) {\n try {\n return this.root.lookupType(name) != null;\n } catch {\n return false;\n }\n }\n\n /**\n * Unpacks protobuf serialized data into JSON object.\n *\n * @param name protobuf descriptor name\n * @param data serialized binary data\n */\n public unpack(name: string, data: Uint8Array<ArrayBufferLike>) {\n return unpack(name, data, this);\n }\n\n /**\n * Packs JSON object into serialized protobuf data.\n *\n * @param name protobuf descriptor name\n * @param value JSON object to pack\n */\n public pack(name: string, value: Record<string, unknown>) {\n return pack(name, value, this);\n }\n\n /**\n * Parses protobuf file descriptor and adds it to the repository.\n *\n * @param data descriptor binary data\n */\n public add(data: Uint8Array<ArrayBufferLike>): void {\n const fd = FileDescriptorProto.decode(data) as IFileDescriptorProto;\n if (fd.name == null) {\n throw error(`Failed to parse protobuf file descriptor: missing name`);\n }\n\n // ignore duplicates\n if (this.root.files.includes(fd.name)) {\n return;\n // throw error(`Failed to parse protobuf file descriptor: duplicate '${fd.name}' filename`);\n }\n\n const filePackage = fd.package ? this.root.define(fd.package) : this.root;\n\n if (fd.name) {\n filePackage.filename = fd.name;\n this.root.files.push(fd.name);\n }\n\n if (fd.messageType) {\n for (const messageType of fd.messageType) {\n // @ts-expect-error\n filePackage.add(Type.fromDescriptor(messageType, fd.syntax));\n }\n }\n\n if (fd.enumType) {\n for (const enumType of fd.enumType) {\n // @ts-expect-error\n filePackage.add(Enum.fromDescriptor(enumType));\n }\n }\n\n if (fd.extension) {\n for (const extension of fd.extension) {\n // @ts-expect-error\n filePackage.add(Field.fromDescriptor(extension));\n }\n }\n\n if (fd.service) {\n for (const service of fd.service) {\n // @ts-expect-error\n filePackage.add(Service.fromDescriptor(service));\n }\n }\n }\n}\n\n/** Implements {@link DataTransformer} interface for the `protobuf` serialization protocol. */\nexport class ProtobufDataTransformer implements DataTransformer {\n private readonly repo = new ProtobufRepository();\n\n public inspect(\n source: string,\n name: string,\n type: string,\n metadata?: string | Record<string, unknown>\n ): DataChannel | string | undefined {\n if (name.startsWith(\"/.schema/proto:\")) {\n if (type !== \"proto:FileDescriptorProto\") {\n throw new Error(`Unexpected type '${type}' for protobuf schema entry`);\n }\n\n return name.substring(15);\n }\n\n if (type.startsWith(\"proto:\")) {\n return {\n source,\n id: name,\n dataType: \"json\",\n publishedDataType: type,\n transformer: this,\n structuredType: {\n name: type.slice(6),\n format: \"protobuf\",\n },\n metadata,\n };\n }\n\n return undefined;\n }\n\n public schema(typeName: string, value: unknown) {\n this.repo.add(toUint8Array(value));\n }\n\n public deserialize(value: unknown, type?: StructuredTypeDescriptor): DataTypeImpl | undefined {\n if (type == null) {\n throw new Error(\n `Transformation requires type to be specified. This situation should not be possible if the transformer is wired correctly.`\n );\n }\n\n if (this.repo.canTransform(type.name)) {\n return this.repo.unpack(type.name, toUint8Array(value));\n }\n\n return undefined;\n }\n\n public serialize(value: unknown, type?: StructuredTypeDescriptor): Uint8Array {\n if (type == null) {\n throw new Error(\n `Transformation requires type to be specified. This situation should not be possible if the transformer is wired correctly.`\n );\n }\n\n if (value == null || typeof value !== \"object\") {\n throw new Error(\"Only JSON objects can be serialized\");\n }\n\n if (this.repo.canTransform(type.name)) {\n return this.repo.pack(type.name, value as Record<string, unknown>);\n }\n\n throw new Error(`Protobuf serialization is not supported for '${type.name}'`);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 @@ function transformEnums(field, value) {
|
|
|
72
72
|
function unpackStruct(sink, descriptor, view, byteOffset, transformer) {
|
|
73
73
|
for (const field of descriptor.fields) if (field.type === "ref") {
|
|
74
74
|
if (field.typeRef == null || typeof field.typeRef !== "object") throw error(`Failed to unpack struct data: field '${field.identifier}' references unresolved type`);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
if (field.arraySize != null) {
|
|
76
|
+
const result = [];
|
|
77
|
+
for (let i = 0; i < field.arraySize; ++i) {
|
|
78
|
+
const v = {};
|
|
79
|
+
unpackStruct(v, field.typeRef, view, byteOffset + field.offset + i * field.size, transformer);
|
|
80
|
+
result.push(v);
|
|
81
|
+
}
|
|
82
|
+
sink[field.identifier] = result;
|
|
83
|
+
} else {
|
|
84
|
+
const result = {};
|
|
85
|
+
unpackStruct(result, field.typeRef, view, byteOffset + field.offset, transformer);
|
|
86
|
+
sink[field.identifier] = result;
|
|
87
|
+
}
|
|
78
88
|
} else if (field.arraySize != null) if (field.type === "char") sink[field.identifier] = transformer(field, decodeStringValue(view, byteOffset + field.offset, field.arraySize));
|
|
79
89
|
else {
|
|
80
90
|
const result = [];
|
|
@@ -97,7 +107,10 @@ function packStruct(source, descriptor, view, byteOffset, transformer) {
|
|
|
97
107
|
const value = source[field.identifier];
|
|
98
108
|
if (field.type === "ref") {
|
|
99
109
|
if (field.typeRef == null || typeof field.typeRef !== "object") throw error(`Failed to pack struct data: field '${field.identifier}' references unresolved type`);
|
|
100
|
-
|
|
110
|
+
if (field.arraySize != null) {
|
|
111
|
+
if (!Array.isArray(value) || value.length != field.arraySize) throw error(`Failed to pack struct data: field '${field.identifier}' must be an array of length ${field.arraySize}`);
|
|
112
|
+
for (let i = 0; i < field.arraySize; ++i) packStruct(value[i], field.typeRef, view, byteOffset + field.offset + i * field.size, transformer);
|
|
113
|
+
} else packStruct(value ?? {}, field.typeRef, view, byteOffset + field.offset, transformer);
|
|
101
114
|
} else if (field.arraySize != null) if (field.type === "char") encodeStringValue(view, byteOffset + field.offset, field.arraySize, transformer(field, value) ?? "");
|
|
102
115
|
else for (let i = 0; i < field.arraySize; ++i) encodePrimitiveValue(field, view, byteOffset + field.offset + i * field.size, transformer(field, value));
|
|
103
116
|
else if (field.bitWidth != null) encodeBitFieldValue(field, view, byteOffset + field.offset, transformer(field, value));
|