-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnbsdecoder.d.ts
190 lines (162 loc) · 5.6 KB
/
nbsdecoder.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/// <reference types="node" />
/**
* Represents `uint64_t` nanosecond timestamps in JS as an object with separate `seconds` and `nanoseconds` components
*/
export interface NbsTimestamp {
/** The seconds component of this timestamp */
seconds: number;
/** The nanoseconds component of this timestamp */
nanos: number;
}
/**
* An NBS packet
*/
export interface NbsPacket {
/** The NBS packet timestamp */
timestamp: NbsTimestamp;
/** The XX64 hash of the packet type */
type: Buffer;
/** The packet subtype */
subtype: number;
/** The packet data, undefined for empty packets */
payload?: Buffer;
}
/**
* An NBS packet to write to an NBS file
*/
export interface NbsWritePacket {
/** The NBS packet timestamp */
timestamp: NbsTimestamp;
/** The XX64 hash of the packet type */
type: Buffer;
/** The packet subtype */
subtype?: number;
/** The packet data */
payload: Buffer;
}
/**
* A (type, subtype) pair that uniquely identifies a specific type of message
*/
export interface NbsTypeSubtype {
type: Buffer | string;
subtype: number;
}
/**
* A (type, subtype) pair that uniquely identifies a specific type of message,
* where the type is always a Buffer
*/
export interface NbsTypeSubtypeBuffer extends NbsTypeSubtype {
type: Buffer;
}
/** The timestamps for a type subtype */
export interface TypeIndex {
typeSubType: NbsTypeSubtype;
timestamps: NbsTimestamp[];
}
/**
* A decoder that can be used to read packets from NBS files
*/
export declare class NbsDecoder {
/**
* Create a new NbsDecoder instance
*
* @param paths A list of absolute paths of nbs files to decode
* @throws For an empty list of paths, and for paths that don't exist
*/
public constructor(paths: string[]);
/**
* Get all the timestamps of a specified message type subtype.
*
* @param typeSubtype A type subtype object to get the timestamps for
*/
public getTypeIndex(typeSubtype: NbsTypeSubtype): NbsTimestamp[];
/** Get a list of all the types present in the loaded nbs files */
public getAvailableTypes(): NbsTypeSubtypeBuffer[];
/** Get the timestamp range (start, end) across all packets in the loaded nbs files */
public getTimestampRange(): [NbsTimestamp, NbsTimestamp];
/**
* Get the timestamp range (start, end) for all packets of the given type in the loaded nbs files
*
* @param typeSubtype A type subtype object to get the timestamp range for
*/
public getTimestampRange(typeSubtype: NbsTypeSubtype): [NbsTimestamp, NbsTimestamp];
/**
* Get the packets at or before the given timestamp for all types in the loaded nbs files
*
* Returns a list with one packet for each available type in the loaded nbs files.
* Empty packets (where `.payload` is undefined) will be returned for types that don't exist
* for the given timestamp in the loaded nbs files. Empty packets will have their `timestamp`,
* `type`, and `subtype` set to the corresponding arguments passed to this function.
*
* @param timestamp The timestamp to get packets at
*/
public getPackets(timestamp: number | BigInt | NbsTimestamp): NbsPacket[];
/**
* Get the packets at or before the given timestamp for the given types in the loaded nbs files
*
* Returns a list of length N for the given list of N types, one packet for each requested type.
* Empty packets (where `.payload` is undefined) will be returned for types that don't exist
* for the given timestamp in the loaded nbs files. Empty packets will have their `timestamp`,
* `type`, and `subtype` set to the corresponding arguments passed to this function.
*
* @param timestamp The timestamp to get packets at
* @param types A list of type subtype objects to get packets for
*/
public getPackets(
timestamp: number | BigInt | NbsTimestamp,
types: NbsTypeSubtype[]
): NbsPacket[];
/**
* Get the packet of the given type at the given index in the loaded nbs file.
*
* Returns either the packet at the index with the given type, or `undefined` if the given
* index is outside the range of packets for the type.
*
* @param index The index of the requested packet
* @param typeSubtype The type of the requested packet
*/
public getPacketByIndex(index: number, typeSubtype: NbsTypeSubtype): NbsPacket | undefined;
/**
* Get the timestamp to seek to such that all messages of the given types are stepped by (n) steps
*
* @param timestamp The current timestamp to step from
* @param type The type or array of types to step. If unspecified, all types will be stepped.
* @param steps Number of steps to move forwards (positive number) or backwards (negative number).
* If 0 or unspecified, returns min or max timestamp matching the given types.
*/
public nextTimestamp(
timestamp: number | BigInt | NbsTimestamp,
type?: NbsTypeSubtype | NbsTypeSubtype[],
steps?: number
): NbsTimestamp;
/**
* Close the readers for the NBS files.
*/
public close(): void;
}
export declare class NbsEncoder {
/**
* Create a new NbsEncoder instance
*
* @param path Absolute path of the nbs file to write to.
*/
public constructor(path: string);
/**
* Write a packet to the nbs file.
*
* @param packet Packet to write to the file
*/
public write(packet: NbsWritePacket): number;
/**
* Get the total number of bytes written to the nbs file.
*/
public getBytesWritten(): BigInt;
/**
* Close the writers for both the nbs file and its index file.
*/
public close(): void;
/**
* Returns true if the file writer to the nbs file is open.
*/
public isOpen(): boolean;
}