-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathindex.ts
228 lines (184 loc) · 3.94 KB
/
index.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import type { Codec } from './codec.js'
export interface FieldDef {
name: string
codec: Codec<any>
optional?: true
repeats?: true
packed?: true
}
export {
decodeMessage
} from './decode.js'
export {
encodeMessage
} from './encode.js'
export { enumeration } from './codecs/enum.js'
export { message } from './codecs/message.js'
export { createReader as reader } from './utils/reader.js'
export { createWriter as writer } from './utils/writer.js'
export type { Codec, EncodeOptions } from './codec.js'
export interface Writer {
/**
* Current length
*/
len: number
/**
* Writes an unsigned 32 bit value as a varint
*/
uint32(value: number): this
/**
* Writes a signed 32 bit value as a varint`
*/
int32(value: number): this
/**
* Writes a 32 bit value as a varint, zig-zag encoded
*/
sint32(value: number): this
/**
* Writes an unsigned 64 bit value as a varint
*/
uint64(value: bigint): this
/**
* Writes a signed 64 bit value as a varint
*/
int64(value: bigint): this
/**
* Writes a signed 64 bit value as a varint, zig-zag encoded
*/
sint64(value: bigint): this
/**
* Writes a boolish value as a varint
*/
bool(value: boolean): this
/**
* Writes an unsigned 32 bit value as fixed 32 bits
*/
fixed32(value: number): this
/**
* Writes a signed 32 bit value as fixed 32 bits
*/
sfixed32(value: number): this
/**
* Writes an unsigned 64 bit value as fixed 64 bits
*/
fixed64(value: bigint): this
/**
* Writes a signed 64 bit value as fixed 64 bits
*/
sfixed64(value: bigint): this
/**
* Writes a float (32 bit)
*/
float(value: number): this
/**
* Writes a double (64 bit float)
*/
double(value: number): this
/**
* Writes a sequence of bytes
*/
bytes(value: Uint8Array): this
/**
* Writes a string
*/
string(value: string): this
/**
* Forks this writer's state by pushing it to a stack.
* Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
*/
fork(): this
/**
* Resets this instance to the last state.
*/
reset(): this
/**
* Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
*/
ldelim(): this
/**
* Finishes the write operation
*/
finish(): Uint8Array
}
export interface Reader {
/**
* Read buffer
*/
buf: Uint8Array
/**
* Read buffer position
*/
pos: number
/**
* Read buffer length
*/
len: number
/**
* Reads a varint as an unsigned 32 bit value
*/
uint32(): number
/**
* Reads a varint as a signed 32 bit value
*/
int32(): number
/**
* Reads a zig-zag encoded varint as a signed 32 bit value
*/
sint32(): number
/**
* Reads a varint as a boolean
*/
bool(): boolean
/**
* Reads fixed 32 bits as an unsigned 32 bit integer
*/
fixed32(): number
/**
* Reads fixed 32 bits as a signed 32 bit integer
*/
sfixed32(): number
/**
* Reads a float (32 bit) as a number
*/
float(): number
/**
* Reads a double (64 bit float) as a number
*/
double(): number
/**
* Reads a sequence of bytes preceded by its length as a varint
*/
bytes(): Uint8Array
/**
* Reads a string preceded by its byte length as a varint
*/
string(): string
/**
* Skips the specified number of bytes if specified, otherwise skips a varints`
*/
skip(length?: number): void
/**
* Skips the next element of the specified wire type
*/
skipType(wireType: number): void
/**
* Reads a varint as a signed 64 bit value
*/
int64(): bigint
/**
* Reads a varint as an unsigned 64 bit value
*/
uint64(): bigint
/**
* Reads a zig-zag encoded varint as a signed 64 bit value
*/
sint64(): bigint
/**
* Reads fixed 64 bits
*/
fixed64(): bigint
/**
* Reads zig-zag encoded fixed 64 bits
*/
sfixed64(): bigint
}