forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protobufjs.d.ts
389 lines (335 loc) · 12.9 KB
/
protobufjs.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
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
// Type definitions for ProtoBuf.js
// Project: https://github.com/dcodeIO/ProtoBuf.js
// Definitions by: Panu Horsmalahti <https://github.com/panuhorsmalahti>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare module ProtoBuf {
// ==========
// protobufjs/src/ProtoBuf.js
var Builder: Builder;
var ByteBuffer: Buffer;
var Long: LongStatic;
var DotProto: DotProto;
var Reflect: Reflect;
// var Lang: Lang; TODO: implement interface Lang
// var Util: Util; TODO: implement interface Util
export function loadJson(json: string, builder?: ProtoBuilder,
filename?: string): ProtoBuilder;
export function loadJsonFile(filename: string,
callback?: (error: any, builder: ProtoBuilder) => void,
builder?: ProtoBuilder): ProtoBuilder;
export function loadProto(proto: string, builder?: ProtoBuilder,
filename?: string): ProtoBuilder;
export function loadProtoFile(filePath: string,
callback?: (error: any, builder: ProtoBuilder) => void,
builder?: ProtoBuilder): ProtoBuilder;
export function newBuilder(options?: {[key: string]: any}): ProtoBuilder;
export interface LongStatic {
new(low?: number, high?: number, unsigned?:boolean): Long;
MAX_UNSIGNED_VALUE: Long;
MAX_VALUE: Long;
MIN_VALUE: Long;
NEG_ONE: Long;
ONE: Long;
UONE: Long;
UZERO: Long;
ZERO: Long;
fromBits(lowBits: number, highBits: number, unsigned?: boolean): Long;
fromInt(value: number, unsigned?: boolean): Long;
fromNumber(value: number, unsigned?: boolean): Long;
fromString(str: string, unsigned?: boolean | number, radix?: number): Long;
fromValue(val: Long | number | string): Long;
isLong(obj: any): boolean;
}
// Based on https://github.com/dcodeIO/Long.js and https://github.com/borisyankov/DefinitelyTyped/blob/master/long/long.d.ts
export interface Long {
high: number;
low: number;
unsigned :boolean;
add(other: Long | number | string): Long;
and(other: Long | number | string): Long;
compare(other: Long | number | string): number;
div(divisor: Long | number | string): Long;
equals(other: Long | number | string): boolean;
getHighBits(): number;
getHighBitsUnsigned(): number;
getLowBits(): number;
getLowBitsUnsigned(): number;
getNumBitsAbs(): number;
greaterThan(other: Long | number | string): boolean;
greaterThanOrEqual(other: Long | number | string): boolean;
isEven(): boolean;
isNegative(): boolean;
isOdd(): boolean;
isPositive(): boolean;
isZero(): boolean;
lessThan(other: Long | number | string): boolean;
lessThanOrEqual(other: Long | number | string): boolean;
modulo(divisor: Long | number | string): Long;
multiply(multiplier: Long | number | string): Long;
negate(): Long;
not(): Long;
notEquals(other: Long | number | string): boolean;
or(other: Long | number | string): Long;
shiftLeft(numBits: number | Long): Long;
shiftRight(numBits: number | Long): Long;
shiftRightUnsigned(numBits: number | Long): Long;
subtract(other: Long | number | string): Long;
toInt(): number;
toNumber(): number;
toSigned(): Long;
toString(radix?: number): string;
toUnsigned(): Long;
xor(other: Long | number | string): Long;
}
// ==========
// protobufjs/src/ProtoBuf/Builder.js
export interface Builder {
new(options?: {[key: string]: any}): ProtoBuilder;
Message: Message;
Service: Service;
isValidMessage(def: {[key: string]: any}): boolean;
isValidMessageField(def: {[key: string]: any}): boolean;
isValidEnum(def: {[key: string]: any}): boolean;
isValidService(def: {[key: string]: any}): boolean;
isValidExtend(def: {[key: string]: any}): boolean;
}
/**
* TODO: Confirm that message needs no further implementation
*/
export interface Message {
new(values?: {[key: string]: any}, var_args?: string[]): Message;
[field: string]: any;
}
/**
* TODO: Implement service interface
*/
export interface Service {
new(rpcImpl?: Function): Service;
}
// ==========
// meta objects for constructing protobufs
export interface ProtoBuilder {
ns: ReflectNamespace;
ptr: ReflectNamespace;
resolved: boolean;
result: ProtoBuf;
files: string[];
importRoot: string;
options: {[key: string]: any};
syntax: string;
reset(): void;
define(pkg: string, options?: {[key: string]: any}): ProtoBuilder;
create(defs?: {[key: string]: any}[]): ProtoBuilder;
resolveAll(): void;
build(path?: string): ProtoBuf;
lookup(path?: string): ReflectT;
}
export interface ProtoBuf {
[package: string]: {[key: string]: MetaMessage | any};
}
export interface MetaMessage {
new(values?: {[key: string]: any}, var_args?: string[]): Message;
decode(buffer?: Buffer, enc?: string): Message;
decodeDelimited(buffer?: Buffer, enc?: string): Message;
decode64(str: string): Message;
decodeHex(str: string): Message;
}
// ==========
// protobufjs/src/ProtoBuf/DotProto.js
export interface DotProto {
Parser: Parser;
Tokenizer: Tokenizer;
}
export interface Parser {
new(proto: string): Parser;
tn: Tokenizer;
parse(): MetaProto;
toString(): string;
}
export interface Tokenizer {
new(proto: string): Tokenizer;
source: string;
index: number;
line: number;
stack: string[];
readingString: boolean;
stringEndsWith: string;
next(): string;
peek(): string;
toString(): string;
}
// ==========
// proto meta information returned by the Parser
export interface MetaProto {
package: string;
messages: ProtoMessage[];
enums: ProtoEnum[];
imports: string[];
options: {[key: string]: any};
services: ProtoService[];
}
export interface ProtoEnum {
name: string;
values: ProtoEnumValue;
options: {[key: string]: any};
}
export interface ProtoEnumValue {
name: string;
id: string;
}
export interface ProtoField {
rule: string;
options: {[key: string]: any};
type: string;
name: string;
id: number;
oneof?: string;
}
export interface ProtoMessage {
name: string;
isGroup?: boolean;
fields: ProtoField[];
enums: ProtoEnum[];
messages: ProtoMessage[];
options: {[key: string]: any};
oneofs: {[key: string]:number[]};
}
export interface ProtoRpcService {
request: string;
response: string;
options: {[key: string]: any};
}
export interface ProtoService {
name: string;
rpc: {[key: string]:ProtoRpcService};
options: {[key: string]: any};
}
// ==========
// protobufjs/src/ProtoBuf/Reflect.js
export interface Reflect {
T: ReflectT;
Namespace: ReflectNamespace;
Message: ReflectMessage;
Enum: ReflectEnum;
Extension: ReflectExtension;
Service: ReflectService;
}
export interface ReflectT {
new(builder?: ProtoBuilder, parent?: ReflectT, name?: string): ReflectT;
builder: ProtoBuilder;
parent: ReflectT;
name: string;
fqn(): string;
toString(includeClass?: boolean): string;
}
export interface ReflectNamespace extends ReflectT {
new(builder?: ProtoBuilder, parent?: ReflectNamespace, name?: string,
options?: {[key: string]: any}): ReflectNamespace;
className: string;
children: ReflectT[];
options: {[key: string]: any};
syntax: string;
getChildren(type?: ReflectT): ReflectT[];
addChild(child: ReflectT): void;
getChild(nameOrId?: string | number): ReflectT;
resolve(qn: string, excludeFields?: boolean): ReflectNamespace;
build(): ProtoBuf;
buildOpt(): {[key: string]: any};
getOption(name?: string): any;
}
export interface ReflectMessage extends ReflectNamespace {
new(builder?: ProtoBuilder, parent?: ReflectNamespace, name?: string,
options?: {[key: string]: any}, isGroup?: boolean): ReflectMessage;
Field: ReflectField; // NOTE: only for new ProtoBuf.Reflect.Message.Field();
ExtensionField: ReflectExtensionField; // NOTE: only for
// new ProtoBuf.Reflect.Message.ExtensionField();
OneOf: ReflectOneOf; // NOTE: only for new ProtoBuf.Reflect.Message.OneOf();
extensions: number[];
clazz(): MetaMessage;
isGroup: boolean;
build(rebuild?: boolean): MetaMessage|any;
encode(message: Message, buffer: Buffer, noVerify?: boolean): Buffer;
calculate(message: Message): number;
decode(buffer: Buffer, length?: number, expectedGroupEndId?: number): Message;
}
export interface ReflectEnum extends ReflectNamespace {
new(builder?: ProtoBuilder, parent?: ReflectT, name?: string,
options?: {[key: string]: any}): ReflectEnum;
Value: ReflectValue; // NOTE: only for new ProtoBuf.Reflect.Enum.Value();
object: {[key: string]:number};
build(): {[key: string]: any};
}
export interface ReflectExtension extends ReflectT {
new(builder?: ProtoBuilder, parent?: ReflectT, name?: string,
field?: ReflectField): ReflectExtension;
field: ReflectField;
}
export interface ReflectService extends ReflectNamespace {
new(): ReflectService;
Method: ReflectMethod; // NOTE: only for new ProtoBuf.Reflect.Service.Method();
RPCMethod: ReflectRPCMethod; // NOTE: only for new ProtoBuf.Reflect.Service.RPCMethod();
clazz(): Function;
build(rebuild?: boolean): Function|any;
}
// TODO: check that the runtime instance of this type reflects this definition
export interface ReflectField extends ReflectT {
new(builder: ProtoBuilder, message: ReflectMessage, rule: string, type: string,
name: string, id: number, options: {[key: string]: any}, oneof: ReflectOneOf): ReflectField;
className: string;
required: boolean;
repeated: boolean;
type: string | WireTuple;
resolvedType: ReflectT;
id: number;
options: {[key: string]: any};
defaultValue: any;
oneof: ReflectOneOf;
originalName: string;
build(): {[key: string]: any};
mkLong(value: any, unsigned?: boolean): number;
verifyValue(value: any, skipRepeated?: boolean): any;
encode(value: any, buffer: Buffer): Buffer;
encodeValue(value: any, buffer: Buffer): Buffer;
calculate(value: any): number;
calculateValue(value: any): number;
decode(wireType: number, buffer: Buffer, skipRepeated?: boolean): any;
}
export interface WireTuple {
name: string;
wireType: number;
}
// TODO: check that the runtime instance of this type reflects this definition
export interface ReflectExtensionField extends ReflectField {
new(builder: ProtoBuilder, message: ReflectMessage, rule: string, type: string,
name: string, id: number, options: {[key: string]: any}): ReflectExtensionField;
extension: ReflectExtension;
}
export interface ReflectOneOf extends ReflectT {
new(builder?: ProtoBuilder, message?: ReflectMessage, name?: string): ReflectOneOf;
fields: ReflectField[];
}
export interface ReflectValue extends ReflectT {
new(builder?: ProtoBuilder, enm?: ReflectEnum, name?: string, id?: number): ReflectValue;
className: string;
id: number;
}
export interface ReflectMethod extends ReflectT {
new(builder?: ProtoBuilder, svc?: ReflectService, name?: string,
options?: {[key: string]: any}): ReflectMethod;
className: string;
options: {[key: string]: any};
buildOpt(): {[key: string]: any};
}
export interface ReflectRPCMethod extends ReflectMethod {
new(builder?: ProtoBuilder, svc?: ReflectService, name?: string, request?: string,
response?: string, options?: {[key: string]: any}): ReflectRPCMethod;
requestName: string;
responseName: string;
resolvedRequestType: ReflectMessage;
resolvedResponseType: ReflectMessage;
}
}
declare module "protobufjs" {
export = ProtoBuf;
}