Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / protobufjs / index.d.ts
1 // DO NOT EDIT! This is a generated file. Edit the JSDoc in src/*.js instead and run 'npm run types'.
2
3 export as namespace protobuf;
4
5 /**
6  * Provides common type definitions.
7  * Can also be used to provide additional google types or your own custom types.
8  * @param name Short name as in `google/protobuf/[name].proto` or full file name
9  * @param json JSON definition within `google.protobuf` if a short name, otherwise the file's root definition
10  */
11 export function common(name: string, json: { [k: string]: any }): void;
12
13 export namespace common {
14
15     /** Properties of a google.protobuf.Any message. */
16     interface IAny {
17         typeUrl?: string;
18         bytes?: Uint8Array;
19     }
20
21     /** Properties of a google.protobuf.Duration message. */
22     interface IDuration {
23         seconds?: (number|Long);
24         nanos?: number;
25     }
26
27     /** Properties of a google.protobuf.Timestamp message. */
28     interface ITimestamp {
29         seconds?: (number|Long);
30         nanos?: number;
31     }
32
33     /** Properties of a google.protobuf.Empty message. */
34     interface IEmpty {
35     }
36
37     /** Properties of a google.protobuf.Struct message. */
38     interface IStruct {
39         fields?: { [k: string]: IValue };
40     }
41
42     /** Properties of a google.protobuf.Value message. */
43     interface IValue {
44         kind?: string;
45         nullValue?: 0;
46         numberValue?: number;
47         stringValue?: string;
48         boolValue?: boolean;
49         structValue?: IStruct;
50         listValue?: IListValue;
51     }
52
53     /** Properties of a google.protobuf.ListValue message. */
54     interface IListValue {
55         values?: IValue[];
56     }
57
58     /** Properties of a google.protobuf.DoubleValue message. */
59     interface IDoubleValue {
60         value?: number;
61     }
62
63     /** Properties of a google.protobuf.FloatValue message. */
64     interface IFloatValue {
65         value?: number;
66     }
67
68     /** Properties of a google.protobuf.Int64Value message. */
69     interface IInt64Value {
70         value?: (number|Long);
71     }
72
73     /** Properties of a google.protobuf.UInt64Value message. */
74     interface IUInt64Value {
75         value?: (number|Long);
76     }
77
78     /** Properties of a google.protobuf.Int32Value message. */
79     interface IInt32Value {
80         value?: number;
81     }
82
83     /** Properties of a google.protobuf.UInt32Value message. */
84     interface IUInt32Value {
85         value?: number;
86     }
87
88     /** Properties of a google.protobuf.BoolValue message. */
89     interface IBoolValue {
90         value?: boolean;
91     }
92
93     /** Properties of a google.protobuf.StringValue message. */
94     interface IStringValue {
95         value?: string;
96     }
97
98     /** Properties of a google.protobuf.BytesValue message. */
99     interface IBytesValue {
100         value?: Uint8Array;
101     }
102
103     /**
104      * Gets the root definition of the specified common proto file.
105      *
106      * Bundled definitions are:
107      * - google/protobuf/any.proto
108      * - google/protobuf/duration.proto
109      * - google/protobuf/empty.proto
110      * - google/protobuf/field_mask.proto
111      * - google/protobuf/struct.proto
112      * - google/protobuf/timestamp.proto
113      * - google/protobuf/wrappers.proto
114      *
115      * @param file Proto file name
116      * @returns Root definition or `null` if not defined
117      */
118     function get(file: string): (INamespace|null);
119 }
120
121 /** Runtime message from/to plain object converters. */
122 export namespace converter {
123
124     /**
125      * Generates a plain object to runtime message converter specific to the specified message type.
126      * @param mtype Message type
127      * @returns Codegen instance
128      */
129     function fromObject(mtype: Type): Codegen;
130
131     /**
132      * Generates a runtime message to plain object converter specific to the specified message type.
133      * @param mtype Message type
134      * @returns Codegen instance
135      */
136     function toObject(mtype: Type): Codegen;
137 }
138
139 /**
140  * Generates a decoder specific to the specified message type.
141  * @param mtype Message type
142  * @returns Codegen instance
143  */
144 export function decoder(mtype: Type): Codegen;
145
146 /**
147  * Generates an encoder specific to the specified message type.
148  * @param mtype Message type
149  * @returns Codegen instance
150  */
151 export function encoder(mtype: Type): Codegen;
152
153 /** Reflected enum. */
154 export class Enum extends ReflectionObject {
155
156     /**
157      * Constructs a new enum instance.
158      * @param name Unique name within its namespace
159      * @param [values] Enum values as an object, by name
160      * @param [options] Declared options
161      * @param [comment] The comment for this enum
162      * @param [comments] The value comments for this enum
163      */
164     constructor(name: string, values?: { [k: string]: number }, options?: { [k: string]: any }, comment?: string, comments?: { [k: string]: string });
165
166     /** Enum values by id. */
167     public valuesById: { [k: number]: string };
168
169     /** Enum values by name. */
170     public values: { [k: string]: number };
171
172     /** Enum comment text. */
173     public comment: (string|null);
174
175     /** Value comment texts, if any. */
176     public comments: { [k: string]: string };
177
178     /** Reserved ranges, if any. */
179     public reserved: (number[]|string)[];
180
181     /**
182      * Constructs an enum from an enum descriptor.
183      * @param name Enum name
184      * @param json Enum descriptor
185      * @returns Created enum
186      * @throws {TypeError} If arguments are invalid
187      */
188     public static fromJSON(name: string, json: IEnum): Enum;
189
190     /**
191      * Converts this enum to an enum descriptor.
192      * @param [toJSONOptions] JSON conversion options
193      * @returns Enum descriptor
194      */
195     public toJSON(toJSONOptions?: IToJSONOptions): IEnum;
196
197     /**
198      * Adds a value to this enum.
199      * @param name Value name
200      * @param id Value id
201      * @param [comment] Comment, if any
202      * @returns `this`
203      * @throws {TypeError} If arguments are invalid
204      * @throws {Error} If there is already a value with this name or id
205      */
206     public add(name: string, id: number, comment?: string): Enum;
207
208     /**
209      * Removes a value from this enum
210      * @param name Value name
211      * @returns `this`
212      * @throws {TypeError} If arguments are invalid
213      * @throws {Error} If `name` is not a name of this enum
214      */
215     public remove(name: string): Enum;
216
217     /**
218      * Tests if the specified id is reserved.
219      * @param id Id to test
220      * @returns `true` if reserved, otherwise `false`
221      */
222     public isReservedId(id: number): boolean;
223
224     /**
225      * Tests if the specified name is reserved.
226      * @param name Name to test
227      * @returns `true` if reserved, otherwise `false`
228      */
229     public isReservedName(name: string): boolean;
230 }
231
232 /** Enum descriptor. */
233 export interface IEnum {
234
235     /** Enum values */
236     values: { [k: string]: number };
237
238     /** Enum options */
239     options?: { [k: string]: any };
240 }
241
242 /** Reflected message field. */
243 export class Field extends FieldBase {
244
245     /**
246      * Constructs a new message field instance. Note that {@link MapField|map fields} have their own class.
247      * @param name Unique name within its namespace
248      * @param id Unique id within its namespace
249      * @param type Value type
250      * @param [rule="optional"] Field rule
251      * @param [extend] Extended type if different from parent
252      * @param [options] Declared options
253      */
254     constructor(name: string, id: number, type: string, rule?: (string|{ [k: string]: any }), extend?: (string|{ [k: string]: any }), options?: { [k: string]: any });
255
256     /**
257      * Constructs a field from a field descriptor.
258      * @param name Field name
259      * @param json Field descriptor
260      * @returns Created field
261      * @throws {TypeError} If arguments are invalid
262      */
263     public static fromJSON(name: string, json: IField): Field;
264
265     /** Determines whether this field is packed. Only relevant when repeated and working with proto2. */
266     public readonly packed: boolean;
267
268     /**
269      * Field decorator (TypeScript).
270      * @param fieldId Field id
271      * @param fieldType Field type
272      * @param [fieldRule="optional"] Field rule
273      * @param [defaultValue] Default value
274      * @returns Decorator function
275      */
276     public static d<T extends number | number[] | Long | Long[] | string | string[] | boolean | boolean[] | Uint8Array | Uint8Array[] | Buffer | Buffer[]>(fieldId: number, fieldType: ("double"|"float"|"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"string"|"bool"|"bytes"|object), fieldRule?: ("optional"|"required"|"repeated"), defaultValue?: T): FieldDecorator;
277
278     /**
279      * Field decorator (TypeScript).
280      * @param fieldId Field id
281      * @param fieldType Field type
282      * @param [fieldRule="optional"] Field rule
283      * @returns Decorator function
284      */
285     public static d<T extends Message<T>>(fieldId: number, fieldType: (Constructor<T>|string), fieldRule?: ("optional"|"required"|"repeated")): FieldDecorator;
286 }
287
288 /** Base class of all reflected message fields. This is not an actual class but here for the sake of having consistent type definitions. */
289 export class FieldBase extends ReflectionObject {
290
291     /**
292      * Not an actual constructor. Use {@link Field} instead.
293      * @param name Unique name within its namespace
294      * @param id Unique id within its namespace
295      * @param type Value type
296      * @param [rule="optional"] Field rule
297      * @param [extend] Extended type if different from parent
298      * @param [options] Declared options
299      * @param [comment] Comment associated with this field
300      */
301     constructor(name: string, id: number, type: string, rule?: (string|{ [k: string]: any }), extend?: (string|{ [k: string]: any }), options?: { [k: string]: any }, comment?: string);
302
303     /** Field rule, if any. */
304     public rule?: string;
305
306     /** Field type. */
307     public type: string;
308
309     /** Unique field id. */
310     public id: number;
311
312     /** Extended type if different from parent. */
313     public extend?: string;
314
315     /** Whether this field is required. */
316     public required: boolean;
317
318     /** Whether this field is optional. */
319     public optional: boolean;
320
321     /** Whether this field is repeated. */
322     public repeated: boolean;
323
324     /** Whether this field is a map or not. */
325     public map: boolean;
326
327     /** Message this field belongs to. */
328     public message: (Type|null);
329
330     /** OneOf this field belongs to, if any, */
331     public partOf: (OneOf|null);
332
333     /** The field type's default value. */
334     public typeDefault: any;
335
336     /** The field's default value on prototypes. */
337     public defaultValue: any;
338
339     /** Whether this field's value should be treated as a long. */
340     public long: boolean;
341
342     /** Whether this field's value is a buffer. */
343     public bytes: boolean;
344
345     /** Resolved type if not a basic type. */
346     public resolvedType: (Type|Enum|null);
347
348     /** Sister-field within the extended type if a declaring extension field. */
349     public extensionField: (Field|null);
350
351     /** Sister-field within the declaring namespace if an extended field. */
352     public declaringField: (Field|null);
353
354     /** Comment for this field. */
355     public comment: (string|null);
356
357     /**
358      * Converts this field to a field descriptor.
359      * @param [toJSONOptions] JSON conversion options
360      * @returns Field descriptor
361      */
362     public toJSON(toJSONOptions?: IToJSONOptions): IField;
363
364     /**
365      * Resolves this field's type references.
366      * @returns `this`
367      * @throws {Error} If any reference cannot be resolved
368      */
369     public resolve(): Field;
370 }
371
372 /** Field descriptor. */
373 export interface IField {
374
375     /** Field rule */
376     rule?: string;
377
378     /** Field type */
379     type: string;
380
381     /** Field id */
382     id: number;
383
384     /** Field options */
385     options?: { [k: string]: any };
386 }
387
388 /** Extension field descriptor. */
389 export interface IExtensionField extends IField {
390
391     /** Extended type */
392     extend: string;
393 }
394
395 /**
396  * Decorator function as returned by {@link Field.d} and {@link MapField.d} (TypeScript).
397  * @param prototype Target prototype
398  * @param fieldName Field name
399  */
400 type FieldDecorator = (prototype: object, fieldName: string) => void;
401
402 /**
403  * A node-style callback as used by {@link load} and {@link Root#load}.
404  * @param error Error, if any, otherwise `null`
405  * @param [root] Root, if there hasn't been an error
406  */
407 type LoadCallback = (error: (Error|null), root?: Root) => void;
408
409 /**
410  * Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
411  * @param filename One or multiple files to load
412  * @param root Root namespace, defaults to create a new one if omitted.
413  * @param callback Callback function
414  * @see {@link Root#load}
415  */
416 export function load(filename: (string|string[]), root: Root, callback: LoadCallback): void;
417
418 /**
419  * Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
420  * @param filename One or multiple files to load
421  * @param callback Callback function
422  * @see {@link Root#load}
423  */
424 export function load(filename: (string|string[]), callback: LoadCallback): void;
425
426 /**
427  * Loads one or multiple .proto or preprocessed .json files into a common root namespace and returns a promise.
428  * @param filename One or multiple files to load
429  * @param [root] Root namespace, defaults to create a new one if omitted.
430  * @returns Promise
431  * @see {@link Root#load}
432  */
433 export function load(filename: (string|string[]), root?: Root): Promise<Root>;
434
435 /**
436  * Synchronously loads one or multiple .proto or preprocessed .json files into a common root namespace (node only).
437  * @param filename One or multiple files to load
438  * @param [root] Root namespace, defaults to create a new one if omitted.
439  * @returns Root namespace
440  * @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid
441  * @see {@link Root#loadSync}
442  */
443 export function loadSync(filename: (string|string[]), root?: Root): Root;
444
445 /** Build type, one of `"full"`, `"light"` or `"minimal"`. */
446 export const build: string;
447
448 /** Reconfigures the library according to the environment. */
449 export function configure(): void;
450
451 /** Reflected map field. */
452 export class MapField extends FieldBase {
453
454     /**
455      * Constructs a new map field instance.
456      * @param name Unique name within its namespace
457      * @param id Unique id within its namespace
458      * @param keyType Key type
459      * @param type Value type
460      * @param [options] Declared options
461      * @param [comment] Comment associated with this field
462      */
463     constructor(name: string, id: number, keyType: string, type: string, options?: { [k: string]: any }, comment?: string);
464
465     /** Key type. */
466     public keyType: string;
467
468     /** Resolved key type if not a basic type. */
469     public resolvedKeyType: (ReflectionObject|null);
470
471     /**
472      * Constructs a map field from a map field descriptor.
473      * @param name Field name
474      * @param json Map field descriptor
475      * @returns Created map field
476      * @throws {TypeError} If arguments are invalid
477      */
478     public static fromJSON(name: string, json: IMapField): MapField;
479
480     /**
481      * Converts this map field to a map field descriptor.
482      * @param [toJSONOptions] JSON conversion options
483      * @returns Map field descriptor
484      */
485     public toJSON(toJSONOptions?: IToJSONOptions): IMapField;
486
487     /**
488      * Map field decorator (TypeScript).
489      * @param fieldId Field id
490      * @param fieldKeyType Field key type
491      * @param fieldValueType Field value type
492      * @returns Decorator function
493      */
494     public static d<T extends { [key: string]: number | Long | string | boolean | Uint8Array | Buffer | number[] | Message<{}> }>(fieldId: number, fieldKeyType: ("int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"bool"|"string"), fieldValueType: ("double"|"float"|"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"bool"|"string"|"bytes"|object|Constructor<{}>)): FieldDecorator;
495 }
496
497 /** Map field descriptor. */
498 export interface IMapField extends IField {
499
500     /** Key type */
501     keyType: string;
502 }
503
504 /** Extension map field descriptor. */
505 export interface IExtensionMapField extends IMapField {
506
507     /** Extended type */
508     extend: string;
509 }
510
511 /** Abstract runtime message. */
512 export class Message<T extends object = object> {
513
514     /**
515      * Constructs a new message instance.
516      * @param [properties] Properties to set
517      */
518     constructor(properties?: Properties<T>);
519
520     /** Reference to the reflected type. */
521     public static readonly $type: Type;
522
523     /** Reference to the reflected type. */
524     public readonly $type: Type;
525
526     /**
527      * Creates a new message of this type using the specified properties.
528      * @param [properties] Properties to set
529      * @returns Message instance
530      */
531     public static create<T extends Message<T>>(this: Constructor<T>, properties?: { [k: string]: any }): Message<T>;
532
533     /**
534      * Encodes a message of this type.
535      * @param message Message to encode
536      * @param [writer] Writer to use
537      * @returns Writer
538      */
539     public static encode<T extends Message<T>>(this: Constructor<T>, message: (T|{ [k: string]: any }), writer?: Writer): Writer;
540
541     /**
542      * Encodes a message of this type preceeded by its length as a varint.
543      * @param message Message to encode
544      * @param [writer] Writer to use
545      * @returns Writer
546      */
547     public static encodeDelimited<T extends Message<T>>(this: Constructor<T>, message: (T|{ [k: string]: any }), writer?: Writer): Writer;
548
549     /**
550      * Decodes a message of this type.
551      * @param reader Reader or buffer to decode
552      * @returns Decoded message
553      */
554     public static decode<T extends Message<T>>(this: Constructor<T>, reader: (Reader|Uint8Array)): T;
555
556     /**
557      * Decodes a message of this type preceeded by its length as a varint.
558      * @param reader Reader or buffer to decode
559      * @returns Decoded message
560      */
561     public static decodeDelimited<T extends Message<T>>(this: Constructor<T>, reader: (Reader|Uint8Array)): T;
562
563     /**
564      * Verifies a message of this type.
565      * @param message Plain object to verify
566      * @returns `null` if valid, otherwise the reason why it is not
567      */
568     public static verify(message: { [k: string]: any }): (string|null);
569
570     /**
571      * Creates a new message of this type from a plain object. Also converts values to their respective internal types.
572      * @param object Plain object
573      * @returns Message instance
574      */
575     public static fromObject<T extends Message<T>>(this: Constructor<T>, object: { [k: string]: any }): T;
576
577     /**
578      * Creates a plain object from a message of this type. Also converts values to other types if specified.
579      * @param message Message instance
580      * @param [options] Conversion options
581      * @returns Plain object
582      */
583     public static toObject<T extends Message<T>>(this: Constructor<T>, message: T, options?: IConversionOptions): { [k: string]: any };
584
585     /**
586      * Converts this message to JSON.
587      * @returns JSON object
588      */
589     public toJSON(): { [k: string]: any };
590 }
591
592 /** Reflected service method. */
593 export class Method extends ReflectionObject {
594
595     /**
596      * Constructs a new service method instance.
597      * @param name Method name
598      * @param type Method type, usually `"rpc"`
599      * @param requestType Request message type
600      * @param responseType Response message type
601      * @param [requestStream] Whether the request is streamed
602      * @param [responseStream] Whether the response is streamed
603      * @param [options] Declared options
604      * @param [comment] The comment for this method
605      */
606     constructor(name: string, type: (string|undefined), requestType: string, responseType: string, requestStream?: (boolean|{ [k: string]: any }), responseStream?: (boolean|{ [k: string]: any }), options?: { [k: string]: any }, comment?: string);
607
608     /** Method type. */
609     public type: string;
610
611     /** Request type. */
612     public requestType: string;
613
614     /** Whether requests are streamed or not. */
615     public requestStream?: boolean;
616
617     /** Response type. */
618     public responseType: string;
619
620     /** Whether responses are streamed or not. */
621     public responseStream?: boolean;
622
623     /** Resolved request type. */
624     public resolvedRequestType: (Type|null);
625
626     /** Resolved response type. */
627     public resolvedResponseType: (Type|null);
628
629     /** Comment for this method */
630     public comment: (string|null);
631
632     /**
633      * Constructs a method from a method descriptor.
634      * @param name Method name
635      * @param json Method descriptor
636      * @returns Created method
637      * @throws {TypeError} If arguments are invalid
638      */
639     public static fromJSON(name: string, json: IMethod): Method;
640
641     /**
642      * Converts this method to a method descriptor.
643      * @param [toJSONOptions] JSON conversion options
644      * @returns Method descriptor
645      */
646     public toJSON(toJSONOptions?: IToJSONOptions): IMethod;
647 }
648
649 /** Method descriptor. */
650 export interface IMethod {
651
652     /** Method type */
653     type?: string;
654
655     /** Request type */
656     requestType: string;
657
658     /** Response type */
659     responseType: string;
660
661     /** Whether requests are streamed */
662     requestStream?: boolean;
663
664     /** Whether responses are streamed */
665     responseStream?: boolean;
666
667     /** Method options */
668     options?: { [k: string]: any };
669 }
670
671 /** Reflected namespace. */
672 export class Namespace extends NamespaceBase {
673
674     /**
675      * Constructs a new namespace instance.
676      * @param name Namespace name
677      * @param [options] Declared options
678      */
679     constructor(name: string, options?: { [k: string]: any });
680
681     /**
682      * Constructs a namespace from JSON.
683      * @param name Namespace name
684      * @param json JSON object
685      * @returns Created namespace
686      * @throws {TypeError} If arguments are invalid
687      */
688     public static fromJSON(name: string, json: { [k: string]: any }): Namespace;
689
690     /**
691      * Converts an array of reflection objects to JSON.
692      * @param array Object array
693      * @param [toJSONOptions] JSON conversion options
694      * @returns JSON object or `undefined` when array is empty
695      */
696     public static arrayToJSON(array: ReflectionObject[], toJSONOptions?: IToJSONOptions): ({ [k: string]: any }|undefined);
697
698     /**
699      * Tests if the specified id is reserved.
700      * @param reserved Array of reserved ranges and names
701      * @param id Id to test
702      * @returns `true` if reserved, otherwise `false`
703      */
704     public static isReservedId(reserved: ((number[]|string)[]|undefined), id: number): boolean;
705
706     /**
707      * Tests if the specified name is reserved.
708      * @param reserved Array of reserved ranges and names
709      * @param name Name to test
710      * @returns `true` if reserved, otherwise `false`
711      */
712     public static isReservedName(reserved: ((number[]|string)[]|undefined), name: string): boolean;
713 }
714
715 /** Base class of all reflection objects containing nested objects. This is not an actual class but here for the sake of having consistent type definitions. */
716 export abstract class NamespaceBase extends ReflectionObject {
717
718     /** Nested objects by name. */
719     public nested?: { [k: string]: ReflectionObject };
720
721     /** Nested objects of this namespace as an array for iteration. */
722     public readonly nestedArray: ReflectionObject[];
723
724     /**
725      * Converts this namespace to a namespace descriptor.
726      * @param [toJSONOptions] JSON conversion options
727      * @returns Namespace descriptor
728      */
729     public toJSON(toJSONOptions?: IToJSONOptions): INamespace;
730
731     /**
732      * Adds nested objects to this namespace from nested object descriptors.
733      * @param nestedJson Any nested object descriptors
734      * @returns `this`
735      */
736     public addJSON(nestedJson: { [k: string]: AnyNestedObject }): Namespace;
737
738     /**
739      * Gets the nested object of the specified name.
740      * @param name Nested object name
741      * @returns The reflection object or `null` if it doesn't exist
742      */
743     public get(name: string): (ReflectionObject|null);
744
745     /**
746      * Gets the values of the nested {@link Enum|enum} of the specified name.
747      * This methods differs from {@link Namespace#get|get} in that it returns an enum's values directly and throws instead of returning `null`.
748      * @param name Nested enum name
749      * @returns Enum values
750      * @throws {Error} If there is no such enum
751      */
752     public getEnum(name: string): { [k: string]: number };
753
754     /**
755      * Adds a nested object to this namespace.
756      * @param object Nested object to add
757      * @returns `this`
758      * @throws {TypeError} If arguments are invalid
759      * @throws {Error} If there is already a nested object with this name
760      */
761     public add(object: ReflectionObject): Namespace;
762
763     /**
764      * Removes a nested object from this namespace.
765      * @param object Nested object to remove
766      * @returns `this`
767      * @throws {TypeError} If arguments are invalid
768      * @throws {Error} If `object` is not a member of this namespace
769      */
770     public remove(object: ReflectionObject): Namespace;
771
772     /**
773      * Defines additial namespaces within this one if not yet existing.
774      * @param path Path to create
775      * @param [json] Nested types to create from JSON
776      * @returns Pointer to the last namespace created or `this` if path is empty
777      */
778     public define(path: (string|string[]), json?: any): Namespace;
779
780     /**
781      * Resolves this namespace's and all its nested objects' type references. Useful to validate a reflection tree, but comes at a cost.
782      * @returns `this`
783      */
784     public resolveAll(): Namespace;
785
786     /**
787      * Recursively looks up the reflection object matching the specified path in the scope of this namespace.
788      * @param path Path to look up
789      * @param filterTypes Filter types, any combination of the constructors of `protobuf.Type`, `protobuf.Enum`, `protobuf.Service` etc.
790      * @param [parentAlreadyChecked=false] If known, whether the parent has already been checked
791      * @returns Looked up object or `null` if none could be found
792      */
793     public lookup(path: (string|string[]), filterTypes: (any|any[]), parentAlreadyChecked?: boolean): (ReflectionObject|null);
794
795     /**
796      * Looks up the reflection object at the specified path, relative to this namespace.
797      * @param path Path to look up
798      * @param [parentAlreadyChecked=false] Whether the parent has already been checked
799      * @returns Looked up object or `null` if none could be found
800      */
801     public lookup(path: (string|string[]), parentAlreadyChecked?: boolean): (ReflectionObject|null);
802
803     /**
804      * Looks up the {@link Type|type} at the specified path, relative to this namespace.
805      * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
806      * @param path Path to look up
807      * @returns Looked up type
808      * @throws {Error} If `path` does not point to a type
809      */
810     public lookupType(path: (string|string[])): Type;
811
812     /**
813      * Looks up the values of the {@link Enum|enum} at the specified path, relative to this namespace.
814      * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
815      * @param path Path to look up
816      * @returns Looked up enum
817      * @throws {Error} If `path` does not point to an enum
818      */
819     public lookupEnum(path: (string|string[])): Enum;
820
821     /**
822      * Looks up the {@link Type|type} or {@link Enum|enum} at the specified path, relative to this namespace.
823      * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
824      * @param path Path to look up
825      * @returns Looked up type or enum
826      * @throws {Error} If `path` does not point to a type or enum
827      */
828     public lookupTypeOrEnum(path: (string|string[])): Type;
829
830     /**
831      * Looks up the {@link Service|service} at the specified path, relative to this namespace.
832      * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
833      * @param path Path to look up
834      * @returns Looked up service
835      * @throws {Error} If `path` does not point to a service
836      */
837     public lookupService(path: (string|string[])): Service;
838 }
839
840 /** Namespace descriptor. */
841 export interface INamespace {
842
843     /** Namespace options */
844     options?: { [k: string]: any };
845
846     /** Nested object descriptors */
847     nested?: { [k: string]: AnyNestedObject };
848 }
849
850 /** Any extension field descriptor. */
851 type AnyExtensionField = (IExtensionField|IExtensionMapField);
852
853 /** Any nested object descriptor. */
854 type AnyNestedObject = (IEnum|IType|IService|AnyExtensionField|INamespace);
855
856 /** Base class of all reflection objects. */
857 export abstract class ReflectionObject {
858
859     /** Options. */
860     public options?: { [k: string]: any };
861
862     /** Parsed Options. */
863     public parsedOptions?: { [k: string]: any[] };
864
865     /** Unique name within its namespace. */
866     public name: string;
867
868     /** Parent namespace. */
869     public parent: (Namespace|null);
870
871     /** Whether already resolved or not. */
872     public resolved: boolean;
873
874     /** Comment text, if any. */
875     public comment: (string|null);
876
877     /** Defining file name. */
878     public filename: (string|null);
879
880     /** Reference to the root namespace. */
881     public readonly root: Root;
882
883     /** Full name including leading dot. */
884     public readonly fullName: string;
885
886     /**
887      * Converts this reflection object to its descriptor representation.
888      * @returns Descriptor
889      */
890     public toJSON(): { [k: string]: any };
891
892     /**
893      * Called when this object is added to a parent.
894      * @param parent Parent added to
895      */
896     public onAdd(parent: ReflectionObject): void;
897
898     /**
899      * Called when this object is removed from a parent.
900      * @param parent Parent removed from
901      */
902     public onRemove(parent: ReflectionObject): void;
903
904     /**
905      * Resolves this objects type references.
906      * @returns `this`
907      */
908     public resolve(): ReflectionObject;
909
910     /**
911      * Gets an option value.
912      * @param name Option name
913      * @returns Option value or `undefined` if not set
914      */
915     public getOption(name: string): any;
916
917     /**
918      * Sets an option.
919      * @param name Option name
920      * @param value Option value
921      * @param [ifNotSet] Sets the option only if it isn't currently set
922      * @returns `this`
923      */
924     public setOption(name: string, value: any, ifNotSet?: boolean): ReflectionObject;
925
926     /**
927      * Sets a parsed option.
928      * @param name parsed Option name
929      * @param value Option value
930      * @param propName dot '.' delimited full path of property within the option to set. if undefined\empty, will add a new option with that value
931      * @returns `this`
932      */
933     public setParsedOption(name: string, value: any, propName: string): ReflectionObject;
934
935     /**
936      * Sets multiple options.
937      * @param options Options to set
938      * @param [ifNotSet] Sets an option only if it isn't currently set
939      * @returns `this`
940      */
941     public setOptions(options: { [k: string]: any }, ifNotSet?: boolean): ReflectionObject;
942
943     /**
944      * Converts this instance to its string representation.
945      * @returns Class name[, space, full name]
946      */
947     public toString(): string;
948 }
949
950 /** Reflected oneof. */
951 export class OneOf extends ReflectionObject {
952
953     /**
954      * Constructs a new oneof instance.
955      * @param name Oneof name
956      * @param [fieldNames] Field names
957      * @param [options] Declared options
958      * @param [comment] Comment associated with this field
959      */
960     constructor(name: string, fieldNames?: (string[]|{ [k: string]: any }), options?: { [k: string]: any }, comment?: string);
961
962     /** Field names that belong to this oneof. */
963     public oneof: string[];
964
965     /** Fields that belong to this oneof as an array for iteration. */
966     public readonly fieldsArray: Field[];
967
968     /** Comment for this field. */
969     public comment: (string|null);
970
971     /**
972      * Constructs a oneof from a oneof descriptor.
973      * @param name Oneof name
974      * @param json Oneof descriptor
975      * @returns Created oneof
976      * @throws {TypeError} If arguments are invalid
977      */
978     public static fromJSON(name: string, json: IOneOf): OneOf;
979
980     /**
981      * Converts this oneof to a oneof descriptor.
982      * @param [toJSONOptions] JSON conversion options
983      * @returns Oneof descriptor
984      */
985     public toJSON(toJSONOptions?: IToJSONOptions): IOneOf;
986
987     /**
988      * Adds a field to this oneof and removes it from its current parent, if any.
989      * @param field Field to add
990      * @returns `this`
991      */
992     public add(field: Field): OneOf;
993
994     /**
995      * Removes a field from this oneof and puts it back to the oneof's parent.
996      * @param field Field to remove
997      * @returns `this`
998      */
999     public remove(field: Field): OneOf;
1000
1001     /**
1002      * OneOf decorator (TypeScript).
1003      * @param fieldNames Field names
1004      * @returns Decorator function
1005      */
1006     public static d<T extends string>(...fieldNames: string[]): OneOfDecorator;
1007 }
1008
1009 /** Oneof descriptor. */
1010 export interface IOneOf {
1011
1012     /** Oneof field names */
1013     oneof: string[];
1014
1015     /** Oneof options */
1016     options?: { [k: string]: any };
1017 }
1018
1019 /**
1020  * Decorator function as returned by {@link OneOf.d} (TypeScript).
1021  * @param prototype Target prototype
1022  * @param oneofName OneOf name
1023  */
1024 type OneOfDecorator = (prototype: object, oneofName: string) => void;
1025
1026 /**
1027  * Parses the given .proto source and returns an object with the parsed contents.
1028  * @param source Source contents
1029  * @param [options] Parse options. Defaults to {@link parse.defaults} when omitted.
1030  * @returns Parser result
1031  */
1032 export function parse(source: string, options?: IParseOptions): IParserResult;
1033
1034 /** Result object returned from {@link parse}. */
1035 export interface IParserResult {
1036
1037     /** Package name, if declared */
1038     package: (string|undefined);
1039
1040     /** Imports, if any */
1041     imports: (string[]|undefined);
1042
1043     /** Weak imports, if any */
1044     weakImports: (string[]|undefined);
1045
1046     /** Syntax, if specified (either `"proto2"` or `"proto3"`) */
1047     syntax: (string|undefined);
1048
1049     /** Populated root instance */
1050     root: Root;
1051 }
1052
1053 /** Options modifying the behavior of {@link parse}. */
1054 export interface IParseOptions {
1055
1056     /** Keeps field casing instead of converting to camel case */
1057     keepCase?: boolean;
1058
1059     /** Recognize double-slash comments in addition to doc-block comments. */
1060     alternateCommentMode?: boolean;
1061
1062     /** Use trailing comment when both leading comment and trailing comment exist. */
1063     preferTrailingComment?: boolean;
1064 }
1065
1066 /** Options modifying the behavior of JSON serialization. */
1067 export interface IToJSONOptions {
1068
1069     /** Serializes comments. */
1070     keepComments?: boolean;
1071 }
1072
1073 /**
1074  * Parses the given .proto source and returns an object with the parsed contents.
1075  * @param source Source contents
1076  * @param root Root to populate
1077  * @param [options] Parse options. Defaults to {@link parse.defaults} when omitted.
1078  * @returns Parser result
1079  */
1080 export function parse(source: string, root: Root, options?: IParseOptions): IParserResult;
1081
1082 /** Wire format reader using `Uint8Array` if available, otherwise `Array`. */
1083 export class Reader {
1084
1085     /**
1086      * Constructs a new reader instance using the specified buffer.
1087      * @param buffer Buffer to read from
1088      */
1089     constructor(buffer: Uint8Array);
1090
1091     /** Read buffer. */
1092     public buf: Uint8Array;
1093
1094     /** Read buffer position. */
1095     public pos: number;
1096
1097     /** Read buffer length. */
1098     public len: number;
1099
1100     /**
1101      * Creates a new reader using the specified buffer.
1102      * @param buffer Buffer to read from
1103      * @returns A {@link BufferReader} if `buffer` is a Buffer, otherwise a {@link Reader}
1104      * @throws {Error} If `buffer` is not a valid buffer
1105      */
1106     public static create(buffer: (Uint8Array|Buffer)): (Reader|BufferReader);
1107
1108     /**
1109      * Reads a varint as an unsigned 32 bit value.
1110      * @returns Value read
1111      */
1112     public uint32(): number;
1113
1114     /**
1115      * Reads a varint as a signed 32 bit value.
1116      * @returns Value read
1117      */
1118     public int32(): number;
1119
1120     /**
1121      * Reads a zig-zag encoded varint as a signed 32 bit value.
1122      * @returns Value read
1123      */
1124     public sint32(): number;
1125
1126     /**
1127      * Reads a varint as a signed 64 bit value.
1128      * @returns Value read
1129      */
1130     public int64(): Long;
1131
1132     /**
1133      * Reads a varint as an unsigned 64 bit value.
1134      * @returns Value read
1135      */
1136     public uint64(): Long;
1137
1138     /**
1139      * Reads a zig-zag encoded varint as a signed 64 bit value.
1140      * @returns Value read
1141      */
1142     public sint64(): Long;
1143
1144     /**
1145      * Reads a varint as a boolean.
1146      * @returns Value read
1147      */
1148     public bool(): boolean;
1149
1150     /**
1151      * Reads fixed 32 bits as an unsigned 32 bit integer.
1152      * @returns Value read
1153      */
1154     public fixed32(): number;
1155
1156     /**
1157      * Reads fixed 32 bits as a signed 32 bit integer.
1158      * @returns Value read
1159      */
1160     public sfixed32(): number;
1161
1162     /**
1163      * Reads fixed 64 bits.
1164      * @returns Value read
1165      */
1166     public fixed64(): Long;
1167
1168     /**
1169      * Reads zig-zag encoded fixed 64 bits.
1170      * @returns Value read
1171      */
1172     public sfixed64(): Long;
1173
1174     /**
1175      * Reads a float (32 bit) as a number.
1176      * @returns Value read
1177      */
1178     public float(): number;
1179
1180     /**
1181      * Reads a double (64 bit float) as a number.
1182      * @returns Value read
1183      */
1184     public double(): number;
1185
1186     /**
1187      * Reads a sequence of bytes preceeded by its length as a varint.
1188      * @returns Value read
1189      */
1190     public bytes(): Uint8Array;
1191
1192     /**
1193      * Reads a string preceeded by its byte length as a varint.
1194      * @returns Value read
1195      */
1196     public string(): string;
1197
1198     /**
1199      * Skips the specified number of bytes if specified, otherwise skips a varint.
1200      * @param [length] Length if known, otherwise a varint is assumed
1201      * @returns `this`
1202      */
1203     public skip(length?: number): Reader;
1204
1205     /**
1206      * Skips the next element of the specified wire type.
1207      * @param wireType Wire type received
1208      * @returns `this`
1209      */
1210     public skipType(wireType: number): Reader;
1211 }
1212
1213 /** Wire format reader using node buffers. */
1214 export class BufferReader extends Reader {
1215
1216     /**
1217      * Constructs a new buffer reader instance.
1218      * @param buffer Buffer to read from
1219      */
1220     constructor(buffer: Buffer);
1221
1222     /**
1223      * Reads a sequence of bytes preceeded by its length as a varint.
1224      * @returns Value read
1225      */
1226     public bytes(): Buffer;
1227 }
1228
1229 /** Root namespace wrapping all types, enums, services, sub-namespaces etc. that belong together. */
1230 export class Root extends NamespaceBase {
1231
1232     /**
1233      * Constructs a new root namespace instance.
1234      * @param [options] Top level options
1235      */
1236     constructor(options?: { [k: string]: any });
1237
1238     /** Deferred extension fields. */
1239     public deferred: Field[];
1240
1241     /** Resolved file names of loaded files. */
1242     public files: string[];
1243
1244     /**
1245      * Loads a namespace descriptor into a root namespace.
1246      * @param json Nameespace descriptor
1247      * @param [root] Root namespace, defaults to create a new one if omitted
1248      * @returns Root namespace
1249      */
1250     public static fromJSON(json: INamespace, root?: Root): Root;
1251
1252     /**
1253      * Resolves the path of an imported file, relative to the importing origin.
1254      * This method exists so you can override it with your own logic in case your imports are scattered over multiple directories.
1255      * @param origin The file name of the importing file
1256      * @param target The file name being imported
1257      * @returns Resolved path to `target` or `null` to skip the file
1258      */
1259     public resolvePath(origin: string, target: string): (string|null);
1260
1261     /**
1262      * Fetch content from file path or url
1263      * This method exists so you can override it with your own logic.
1264      * @param path File path or url
1265      * @param callback Callback function
1266      */
1267     public fetch(path: string, callback: FetchCallback): void;
1268
1269     /**
1270      * Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
1271      * @param filename Names of one or multiple files to load
1272      * @param options Parse options
1273      * @param callback Callback function
1274      */
1275     public load(filename: (string|string[]), options: IParseOptions, callback: LoadCallback): void;
1276
1277     /**
1278      * Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
1279      * @param filename Names of one or multiple files to load
1280      * @param callback Callback function
1281      */
1282     public load(filename: (string|string[]), callback: LoadCallback): void;
1283
1284     /**
1285      * Loads one or multiple .proto or preprocessed .json files into this root namespace and returns a promise.
1286      * @param filename Names of one or multiple files to load
1287      * @param [options] Parse options. Defaults to {@link parse.defaults} when omitted.
1288      * @returns Promise
1289      */
1290     public load(filename: (string|string[]), options?: IParseOptions): Promise<Root>;
1291
1292     /**
1293      * Synchronously loads one or multiple .proto or preprocessed .json files into this root namespace (node only).
1294      * @param filename Names of one or multiple files to load
1295      * @param [options] Parse options. Defaults to {@link parse.defaults} when omitted.
1296      * @returns Root namespace
1297      * @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid
1298      */
1299     public loadSync(filename: (string|string[]), options?: IParseOptions): Root;
1300 }
1301
1302 /**
1303  * Named roots.
1304  * This is where pbjs stores generated structures (the option `-r, --root` specifies a name).
1305  * Can also be used manually to make roots available accross modules.
1306  */
1307 export let roots: { [k: string]: Root };
1308
1309 /** Streaming RPC helpers. */
1310 export namespace rpc {
1311
1312     /**
1313      * A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
1314      *
1315      * Differs from {@link RPCImplCallback} in that it is an actual callback of a service method which may not return `response = null`.
1316      * @param error Error, if any
1317      * @param [response] Response message
1318      */
1319     type ServiceMethodCallback<TRes extends Message<TRes>> = (error: (Error|null), response?: TRes) => void;
1320
1321     /**
1322      * A service method part of a {@link rpc.Service} as created by {@link Service.create}.
1323      * @param request Request message or plain object
1324      * @param [callback] Node-style callback called with the error, if any, and the response message
1325      * @returns Promise if `callback` has been omitted, otherwise `undefined`
1326      */
1327     type ServiceMethod<TReq extends Message<TReq>, TRes extends Message<TRes>> = (request: (TReq|Properties<TReq>), callback?: rpc.ServiceMethodCallback<TRes>) => Promise<Message<TRes>>;
1328
1329     /** An RPC service as returned by {@link Service#create}. */
1330     class Service extends util.EventEmitter {
1331
1332         /**
1333          * Constructs a new RPC service instance.
1334          * @param rpcImpl RPC implementation
1335          * @param [requestDelimited=false] Whether requests are length-delimited
1336          * @param [responseDelimited=false] Whether responses are length-delimited
1337          */
1338         constructor(rpcImpl: RPCImpl, requestDelimited?: boolean, responseDelimited?: boolean);
1339
1340         /** RPC implementation. Becomes `null` once the service is ended. */
1341         public rpcImpl: (RPCImpl|null);
1342
1343         /** Whether requests are length-delimited. */
1344         public requestDelimited: boolean;
1345
1346         /** Whether responses are length-delimited. */
1347         public responseDelimited: boolean;
1348
1349         /**
1350          * Calls a service method through {@link rpc.Service#rpcImpl|rpcImpl}.
1351          * @param method Reflected or static method
1352          * @param requestCtor Request constructor
1353          * @param responseCtor Response constructor
1354          * @param request Request message or plain object
1355          * @param callback Service callback
1356          */
1357         public rpcCall<TReq extends Message<TReq>, TRes extends Message<TRes>>(method: (Method|rpc.ServiceMethod<TReq, TRes>), requestCtor: Constructor<TReq>, responseCtor: Constructor<TRes>, request: (TReq|Properties<TReq>), callback: rpc.ServiceMethodCallback<TRes>): void;
1358
1359         /**
1360          * Ends this service and emits the `end` event.
1361          * @param [endedByRPC=false] Whether the service has been ended by the RPC implementation.
1362          * @returns `this`
1363          */
1364         public end(endedByRPC?: boolean): rpc.Service;
1365     }
1366 }
1367
1368 /**
1369  * RPC implementation passed to {@link Service#create} performing a service request on network level, i.e. by utilizing http requests or websockets.
1370  * @param method Reflected or static method being called
1371  * @param requestData Request data
1372  * @param callback Callback function
1373  */
1374 type RPCImpl = (method: (Method|rpc.ServiceMethod<Message<{}>, Message<{}>>), requestData: Uint8Array, callback: RPCImplCallback) => void;
1375
1376 /**
1377  * Node-style callback as used by {@link RPCImpl}.
1378  * @param error Error, if any, otherwise `null`
1379  * @param [response] Response data or `null` to signal end of stream, if there hasn't been an error
1380  */
1381 type RPCImplCallback = (error: (Error|null), response?: (Uint8Array|null)) => void;
1382
1383 /** Reflected service. */
1384 export class Service extends NamespaceBase {
1385
1386     /**
1387      * Constructs a new service instance.
1388      * @param name Service name
1389      * @param [options] Service options
1390      * @throws {TypeError} If arguments are invalid
1391      */
1392     constructor(name: string, options?: { [k: string]: any });
1393
1394     /** Service methods. */
1395     public methods: { [k: string]: Method };
1396
1397     /**
1398      * Constructs a service from a service descriptor.
1399      * @param name Service name
1400      * @param json Service descriptor
1401      * @returns Created service
1402      * @throws {TypeError} If arguments are invalid
1403      */
1404     public static fromJSON(name: string, json: IService): Service;
1405
1406     /**
1407      * Converts this service to a service descriptor.
1408      * @param [toJSONOptions] JSON conversion options
1409      * @returns Service descriptor
1410      */
1411     public toJSON(toJSONOptions?: IToJSONOptions): IService;
1412
1413     /** Methods of this service as an array for iteration. */
1414     public readonly methodsArray: Method[];
1415
1416     /**
1417      * Creates a runtime service using the specified rpc implementation.
1418      * @param rpcImpl RPC implementation
1419      * @param [requestDelimited=false] Whether requests are length-delimited
1420      * @param [responseDelimited=false] Whether responses are length-delimited
1421      * @returns RPC service. Useful where requests and/or responses are streamed.
1422      */
1423     public create(rpcImpl: RPCImpl, requestDelimited?: boolean, responseDelimited?: boolean): rpc.Service;
1424 }
1425
1426 /** Service descriptor. */
1427 export interface IService extends INamespace {
1428
1429     /** Method descriptors */
1430     methods: { [k: string]: IMethod };
1431 }
1432
1433 /**
1434  * Gets the next token and advances.
1435  * @returns Next token or `null` on eof
1436  */
1437 type TokenizerHandleNext = () => (string|null);
1438
1439 /**
1440  * Peeks for the next token.
1441  * @returns Next token or `null` on eof
1442  */
1443 type TokenizerHandlePeek = () => (string|null);
1444
1445 /**
1446  * Pushes a token back to the stack.
1447  * @param token Token
1448  */
1449 type TokenizerHandlePush = (token: string) => void;
1450
1451 /**
1452  * Skips the next token.
1453  * @param expected Expected token
1454  * @param [optional=false] If optional
1455  * @returns Whether the token matched
1456  * @throws {Error} If the token didn't match and is not optional
1457  */
1458 type TokenizerHandleSkip = (expected: string, optional?: boolean) => boolean;
1459
1460 /**
1461  * Gets the comment on the previous line or, alternatively, the line comment on the specified line.
1462  * @param [line] Line number
1463  * @returns Comment text or `null` if none
1464  */
1465 type TokenizerHandleCmnt = (line?: number) => (string|null);
1466
1467 /** Handle object returned from {@link tokenize}. */
1468 export interface ITokenizerHandle {
1469
1470     /** Gets the next token and advances (`null` on eof) */
1471     next: TokenizerHandleNext;
1472
1473     /** Peeks for the next token (`null` on eof) */
1474     peek: TokenizerHandlePeek;
1475
1476     /** Pushes a token back to the stack */
1477     push: TokenizerHandlePush;
1478
1479     /** Skips a token, returns its presence and advances or, if non-optional and not present, throws */
1480     skip: TokenizerHandleSkip;
1481
1482     /** Gets the comment on the previous line or the line comment on the specified line, if any */
1483     cmnt: TokenizerHandleCmnt;
1484
1485     /** Current line number */
1486     line: number;
1487 }
1488
1489 /**
1490  * Tokenizes the given .proto source and returns an object with useful utility functions.
1491  * @param source Source contents
1492  * @param alternateCommentMode Whether we should activate alternate comment parsing mode.
1493  * @returns Tokenizer handle
1494  */
1495 export function tokenize(source: string, alternateCommentMode: boolean): ITokenizerHandle;
1496
1497 export namespace tokenize {
1498
1499     /**
1500      * Unescapes a string.
1501      * @param str String to unescape
1502      * @returns Unescaped string
1503      */
1504     function unescape(str: string): string;
1505 }
1506
1507 /** Reflected message type. */
1508 export class Type extends NamespaceBase {
1509
1510     /**
1511      * Constructs a new reflected message type instance.
1512      * @param name Message name
1513      * @param [options] Declared options
1514      */
1515     constructor(name: string, options?: { [k: string]: any });
1516
1517     /** Message fields. */
1518     public fields: { [k: string]: Field };
1519
1520     /** Oneofs declared within this namespace, if any. */
1521     public oneofs: { [k: string]: OneOf };
1522
1523     /** Extension ranges, if any. */
1524     public extensions: number[][];
1525
1526     /** Reserved ranges, if any. */
1527     public reserved: (number[]|string)[];
1528
1529     /** Message fields by id. */
1530     public readonly fieldsById: { [k: number]: Field };
1531
1532     /** Fields of this message as an array for iteration. */
1533     public readonly fieldsArray: Field[];
1534
1535     /** Oneofs of this message as an array for iteration. */
1536     public readonly oneofsArray: OneOf[];
1537
1538     /**
1539      * The registered constructor, if any registered, otherwise a generic constructor.
1540      * Assigning a function replaces the internal constructor. If the function does not extend {@link Message} yet, its prototype will be setup accordingly and static methods will be populated. If it already extends {@link Message}, it will just replace the internal constructor.
1541      */
1542     public ctor: Constructor<{}>;
1543
1544     /**
1545      * Generates a constructor function for the specified type.
1546      * @param mtype Message type
1547      * @returns Codegen instance
1548      */
1549     public static generateConstructor(mtype: Type): Codegen;
1550
1551     /**
1552      * Creates a message type from a message type descriptor.
1553      * @param name Message name
1554      * @param json Message type descriptor
1555      * @returns Created message type
1556      */
1557     public static fromJSON(name: string, json: IType): Type;
1558
1559     /**
1560      * Converts this message type to a message type descriptor.
1561      * @param [toJSONOptions] JSON conversion options
1562      * @returns Message type descriptor
1563      */
1564     public toJSON(toJSONOptions?: IToJSONOptions): IType;
1565
1566     /**
1567      * Adds a nested object to this type.
1568      * @param object Nested object to add
1569      * @returns `this`
1570      * @throws {TypeError} If arguments are invalid
1571      * @throws {Error} If there is already a nested object with this name or, if a field, when there is already a field with this id
1572      */
1573     public add(object: ReflectionObject): Type;
1574
1575     /**
1576      * Removes a nested object from this type.
1577      * @param object Nested object to remove
1578      * @returns `this`
1579      * @throws {TypeError} If arguments are invalid
1580      * @throws {Error} If `object` is not a member of this type
1581      */
1582     public remove(object: ReflectionObject): Type;
1583
1584     /**
1585      * Tests if the specified id is reserved.
1586      * @param id Id to test
1587      * @returns `true` if reserved, otherwise `false`
1588      */
1589     public isReservedId(id: number): boolean;
1590
1591     /**
1592      * Tests if the specified name is reserved.
1593      * @param name Name to test
1594      * @returns `true` if reserved, otherwise `false`
1595      */
1596     public isReservedName(name: string): boolean;
1597
1598     /**
1599      * Creates a new message of this type using the specified properties.
1600      * @param [properties] Properties to set
1601      * @returns Message instance
1602      */
1603     public create(properties?: { [k: string]: any }): Message<{}>;
1604
1605     /**
1606      * Sets up {@link Type#encode|encode}, {@link Type#decode|decode} and {@link Type#verify|verify}.
1607      * @returns `this`
1608      */
1609     public setup(): Type;
1610
1611     /**
1612      * Encodes a message of this type. Does not implicitly {@link Type#verify|verify} messages.
1613      * @param message Message instance or plain object
1614      * @param [writer] Writer to encode to
1615      * @returns writer
1616      */
1617     public encode(message: (Message<{}>|{ [k: string]: any }), writer?: Writer): Writer;
1618
1619     /**
1620      * Encodes a message of this type preceeded by its byte length as a varint. Does not implicitly {@link Type#verify|verify} messages.
1621      * @param message Message instance or plain object
1622      * @param [writer] Writer to encode to
1623      * @returns writer
1624      */
1625     public encodeDelimited(message: (Message<{}>|{ [k: string]: any }), writer?: Writer): Writer;
1626
1627     /**
1628      * Decodes a message of this type.
1629      * @param reader Reader or buffer to decode from
1630      * @param [length] Length of the message, if known beforehand
1631      * @returns Decoded message
1632      * @throws {Error} If the payload is not a reader or valid buffer
1633      * @throws {util.ProtocolError<{}>} If required fields are missing
1634      */
1635     public decode(reader: (Reader|Uint8Array), length?: number): Message<{}>;
1636
1637     /**
1638      * Decodes a message of this type preceeded by its byte length as a varint.
1639      * @param reader Reader or buffer to decode from
1640      * @returns Decoded message
1641      * @throws {Error} If the payload is not a reader or valid buffer
1642      * @throws {util.ProtocolError} If required fields are missing
1643      */
1644     public decodeDelimited(reader: (Reader|Uint8Array)): Message<{}>;
1645
1646     /**
1647      * Verifies that field values are valid and that required fields are present.
1648      * @param message Plain object to verify
1649      * @returns `null` if valid, otherwise the reason why it is not
1650      */
1651     public verify(message: { [k: string]: any }): (null|string);
1652
1653     /**
1654      * Creates a new message of this type from a plain object. Also converts values to their respective internal types.
1655      * @param object Plain object to convert
1656      * @returns Message instance
1657      */
1658     public fromObject(object: { [k: string]: any }): Message<{}>;
1659
1660     /**
1661      * Creates a plain object from a message of this type. Also converts values to other types if specified.
1662      * @param message Message instance
1663      * @param [options] Conversion options
1664      * @returns Plain object
1665      */
1666     public toObject(message: Message<{}>, options?: IConversionOptions): { [k: string]: any };
1667
1668     /**
1669      * Type decorator (TypeScript).
1670      * @param [typeName] Type name, defaults to the constructor's name
1671      * @returns Decorator function
1672      */
1673     public static d<T extends Message<T>>(typeName?: string): TypeDecorator<T>;
1674 }
1675
1676 /** Message type descriptor. */
1677 export interface IType extends INamespace {
1678
1679     /** Oneof descriptors */
1680     oneofs?: { [k: string]: IOneOf };
1681
1682     /** Field descriptors */
1683     fields: { [k: string]: IField };
1684
1685     /** Extension ranges */
1686     extensions?: number[][];
1687
1688     /** Reserved ranges */
1689     reserved?: number[][];
1690
1691     /** Whether a legacy group or not */
1692     group?: boolean;
1693 }
1694
1695 /** Conversion options as used by {@link Type#toObject} and {@link Message.toObject}. */
1696 export interface IConversionOptions {
1697
1698     /**
1699      * Long conversion type.
1700      * Valid values are `String` and `Number` (the global types).
1701      * Defaults to copy the present value, which is a possibly unsafe number without and a {@link Long} with a long library.
1702      */
1703     longs?: Function;
1704
1705     /**
1706      * Enum value conversion type.
1707      * Only valid value is `String` (the global type).
1708      * Defaults to copy the present value, which is the numeric id.
1709      */
1710     enums?: Function;
1711
1712     /**
1713      * Bytes value conversion type.
1714      * Valid values are `Array` and (a base64 encoded) `String` (the global types).
1715      * Defaults to copy the present value, which usually is a Buffer under node and an Uint8Array in the browser.
1716      */
1717     bytes?: Function;
1718
1719     /** Also sets default values on the resulting object */
1720     defaults?: boolean;
1721
1722     /** Sets empty arrays for missing repeated fields even if `defaults=false` */
1723     arrays?: boolean;
1724
1725     /** Sets empty objects for missing map fields even if `defaults=false` */
1726     objects?: boolean;
1727
1728     /** Includes virtual oneof properties set to the present field's name, if any */
1729     oneofs?: boolean;
1730
1731     /** Performs additional JSON compatibility conversions, i.e. NaN and Infinity to strings */
1732     json?: boolean;
1733 }
1734
1735 /**
1736  * Decorator function as returned by {@link Type.d} (TypeScript).
1737  * @param target Target constructor
1738  */
1739 type TypeDecorator<T extends Message<T>> = (target: Constructor<T>) => void;
1740
1741 /** Common type constants. */
1742 export namespace types {
1743
1744     /** Basic type wire types. */
1745     const basic: {
1746         "double": number,
1747         "float": number,
1748         "int32": number,
1749         "uint32": number,
1750         "sint32": number,
1751         "fixed32": number,
1752         "sfixed32": number,
1753         "int64": number,
1754         "uint64": number,
1755         "sint64": number,
1756         "fixed64": number,
1757         "sfixed64": number,
1758         "bool": number,
1759         "string": number,
1760         "bytes": number
1761     };
1762
1763     /** Basic type defaults. */
1764     const defaults: {
1765         "double": number,
1766         "float": number,
1767         "int32": number,
1768         "uint32": number,
1769         "sint32": number,
1770         "fixed32": number,
1771         "sfixed32": number,
1772         "int64": number,
1773         "uint64": number,
1774         "sint64": number,
1775         "fixed64": number,
1776         "sfixed64": number,
1777         "bool": boolean,
1778         "string": string,
1779         "bytes": number[],
1780         "message": null
1781     };
1782
1783     /** Basic long type wire types. */
1784     const long: {
1785         "int64": number,
1786         "uint64": number,
1787         "sint64": number,
1788         "fixed64": number,
1789         "sfixed64": number
1790     };
1791
1792     /** Allowed types for map keys with their associated wire type. */
1793     const mapKey: {
1794         "int32": number,
1795         "uint32": number,
1796         "sint32": number,
1797         "fixed32": number,
1798         "sfixed32": number,
1799         "int64": number,
1800         "uint64": number,
1801         "sint64": number,
1802         "fixed64": number,
1803         "sfixed64": number,
1804         "bool": number,
1805         "string": number
1806     };
1807
1808     /** Allowed types for packed repeated fields with their associated wire type. */
1809     const packed: {
1810         "double": number,
1811         "float": number,
1812         "int32": number,
1813         "uint32": number,
1814         "sint32": number,
1815         "fixed32": number,
1816         "sfixed32": number,
1817         "int64": number,
1818         "uint64": number,
1819         "sint64": number,
1820         "fixed64": number,
1821         "sfixed64": number,
1822         "bool": number
1823     };
1824 }
1825
1826 /** Constructor type. */
1827 export interface Constructor<T> extends Function {
1828     new(...params: any[]): T; prototype: T;
1829 }
1830
1831 /** Properties type. */
1832 type Properties<T> = { [P in keyof T]?: T[P] };
1833
1834 /**
1835  * Any compatible Buffer instance.
1836  * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings.
1837  */
1838 export interface Buffer extends Uint8Array {
1839 }
1840
1841 /**
1842  * Any compatible Long instance.
1843  * This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js.
1844  */
1845 export interface Long {
1846
1847     /** Low bits */
1848     low: number;
1849
1850     /** High bits */
1851     high: number;
1852
1853     /** Whether unsigned or not */
1854     unsigned: boolean;
1855 }
1856
1857 /**
1858  * A OneOf getter as returned by {@link util.oneOfGetter}.
1859  * @returns Set field name, if any
1860  */
1861 type OneOfGetter = () => (string|undefined);
1862
1863 /**
1864  * A OneOf setter as returned by {@link util.oneOfSetter}.
1865  * @param value Field name
1866  */
1867 type OneOfSetter = (value: (string|undefined)) => void;
1868
1869 /** Various utility functions. */
1870 export namespace util {
1871
1872     /** Helper class for working with the low and high bits of a 64 bit value. */
1873     class LongBits {
1874
1875         /**
1876          * Constructs new long bits.
1877          * @param lo Low 32 bits, unsigned
1878          * @param hi High 32 bits, unsigned
1879          */
1880         constructor(lo: number, hi: number);
1881
1882         /** Low bits. */
1883         public lo: number;
1884
1885         /** High bits. */
1886         public hi: number;
1887
1888         /** Zero bits. */
1889         public static zero: util.LongBits;
1890
1891         /** Zero hash. */
1892         public static zeroHash: string;
1893
1894         /**
1895          * Constructs new long bits from the specified number.
1896          * @param value Value
1897          * @returns Instance
1898          */
1899         public static fromNumber(value: number): util.LongBits;
1900
1901         /**
1902          * Constructs new long bits from a number, long or string.
1903          * @param value Value
1904          * @returns Instance
1905          */
1906         public static from(value: (Long|number|string)): util.LongBits;
1907
1908         /**
1909          * Converts this long bits to a possibly unsafe JavaScript number.
1910          * @param [unsigned=false] Whether unsigned or not
1911          * @returns Possibly unsafe number
1912          */
1913         public toNumber(unsigned?: boolean): number;
1914
1915         /**
1916          * Converts this long bits to a long.
1917          * @param [unsigned=false] Whether unsigned or not
1918          * @returns Long
1919          */
1920         public toLong(unsigned?: boolean): Long;
1921
1922         /**
1923          * Constructs new long bits from the specified 8 characters long hash.
1924          * @param hash Hash
1925          * @returns Bits
1926          */
1927         public static fromHash(hash: string): util.LongBits;
1928
1929         /**
1930          * Converts this long bits to a 8 characters long hash.
1931          * @returns Hash
1932          */
1933         public toHash(): string;
1934
1935         /**
1936          * Zig-zag encodes this long bits.
1937          * @returns `this`
1938          */
1939         public zzEncode(): util.LongBits;
1940
1941         /**
1942          * Zig-zag decodes this long bits.
1943          * @returns `this`
1944          */
1945         public zzDecode(): util.LongBits;
1946
1947         /**
1948          * Calculates the length of this longbits when encoded as a varint.
1949          * @returns Length
1950          */
1951         public length(): number;
1952     }
1953
1954     /** Whether running within node or not. */
1955     let isNode: boolean;
1956
1957     /** Global object reference. */
1958     let global: object;
1959
1960     /** An immuable empty array. */
1961     const emptyArray: any[];
1962
1963     /** An immutable empty object. */
1964     const emptyObject: object;
1965
1966     /**
1967      * Tests if the specified value is an integer.
1968      * @param value Value to test
1969      * @returns `true` if the value is an integer
1970      */
1971     function isInteger(value: any): boolean;
1972
1973     /**
1974      * Tests if the specified value is a string.
1975      * @param value Value to test
1976      * @returns `true` if the value is a string
1977      */
1978     function isString(value: any): boolean;
1979
1980     /**
1981      * Tests if the specified value is a non-null object.
1982      * @param value Value to test
1983      * @returns `true` if the value is a non-null object
1984      */
1985     function isObject(value: any): boolean;
1986
1987     /**
1988      * Checks if a property on a message is considered to be present.
1989      * This is an alias of {@link util.isSet}.
1990      * @param obj Plain object or message instance
1991      * @param prop Property name
1992      * @returns `true` if considered to be present, otherwise `false`
1993      */
1994     function isset(obj: object, prop: string): boolean;
1995
1996     /**
1997      * Checks if a property on a message is considered to be present.
1998      * @param obj Plain object or message instance
1999      * @param prop Property name
2000      * @returns `true` if considered to be present, otherwise `false`
2001      */
2002     function isSet(obj: object, prop: string): boolean;
2003
2004     /** Node's Buffer class if available. */
2005     let Buffer: Constructor<Buffer>;
2006
2007     /**
2008      * Creates a new buffer of whatever type supported by the environment.
2009      * @param [sizeOrArray=0] Buffer size or number array
2010      * @returns Buffer
2011      */
2012     function newBuffer(sizeOrArray?: (number|number[])): (Uint8Array|Buffer);
2013
2014     /** Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`. */
2015     let Array: Constructor<Uint8Array>;
2016
2017     /** Long.js's Long class if available. */
2018     let Long: Constructor<Long>;
2019
2020     /** Regular expression used to verify 2 bit (`bool`) map keys. */
2021     const key2Re: RegExp;
2022
2023     /** Regular expression used to verify 32 bit (`int32` etc.) map keys. */
2024     const key32Re: RegExp;
2025
2026     /** Regular expression used to verify 64 bit (`int64` etc.) map keys. */
2027     const key64Re: RegExp;
2028
2029     /**
2030      * Converts a number or long to an 8 characters long hash string.
2031      * @param value Value to convert
2032      * @returns Hash
2033      */
2034     function longToHash(value: (Long|number)): string;
2035
2036     /**
2037      * Converts an 8 characters long hash string to a long or number.
2038      * @param hash Hash
2039      * @param [unsigned=false] Whether unsigned or not
2040      * @returns Original value
2041      */
2042     function longFromHash(hash: string, unsigned?: boolean): (Long|number);
2043
2044     /**
2045      * Merges the properties of the source object into the destination object.
2046      * @param dst Destination object
2047      * @param src Source object
2048      * @param [ifNotSet=false] Merges only if the key is not already set
2049      * @returns Destination object
2050      */
2051     function merge(dst: { [k: string]: any }, src: { [k: string]: any }, ifNotSet?: boolean): { [k: string]: any };
2052
2053     /**
2054      * Converts the first character of a string to lower case.
2055      * @param str String to convert
2056      * @returns Converted string
2057      */
2058     function lcFirst(str: string): string;
2059
2060     /**
2061      * Creates a custom error constructor.
2062      * @param name Error name
2063      * @returns Custom error constructor
2064      */
2065     function newError(name: string): Constructor<Error>;
2066
2067     /** Error subclass indicating a protocol specifc error. */
2068     class ProtocolError<T extends Message<T>> extends Error {
2069
2070         /**
2071          * Constructs a new protocol error.
2072          * @param message Error message
2073          * @param [properties] Additional properties
2074          */
2075         constructor(message: string, properties?: { [k: string]: any });
2076
2077         /** So far decoded message instance. */
2078         public instance: Message<T>;
2079     }
2080
2081     /**
2082      * Builds a getter for a oneof's present field name.
2083      * @param fieldNames Field names
2084      * @returns Unbound getter
2085      */
2086     function oneOfGetter(fieldNames: string[]): OneOfGetter;
2087
2088     /**
2089      * Builds a setter for a oneof's present field name.
2090      * @param fieldNames Field names
2091      * @returns Unbound setter
2092      */
2093     function oneOfSetter(fieldNames: string[]): OneOfSetter;
2094
2095     /**
2096      * Default conversion options used for {@link Message#toJSON} implementations.
2097      *
2098      * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:
2099      *
2100      * - Longs become strings
2101      * - Enums become string keys
2102      * - Bytes become base64 encoded strings
2103      * - (Sub-)Messages become plain objects
2104      * - Maps become plain objects with all string keys
2105      * - Repeated fields become arrays
2106      * - NaN and Infinity for float and double fields become strings
2107      *
2108      * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json
2109      */
2110     let toJSONOptions: IConversionOptions;
2111
2112     /** Node's fs module if available. */
2113     let fs: { [k: string]: any };
2114
2115     /**
2116      * Converts an object's values to an array.
2117      * @param object Object to convert
2118      * @returns Converted array
2119      */
2120     function toArray(object: { [k: string]: any }): any[];
2121
2122     /**
2123      * Converts an array of keys immediately followed by their respective value to an object, omitting undefined values.
2124      * @param array Array to convert
2125      * @returns Converted object
2126      */
2127     function toObject(array: any[]): { [k: string]: any };
2128
2129     /**
2130      * Tests whether the specified name is a reserved word in JS.
2131      * @param name Name to test
2132      * @returns `true` if reserved, otherwise `false`
2133      */
2134     function isReserved(name: string): boolean;
2135
2136     /**
2137      * Returns a safe property accessor for the specified property name.
2138      * @param prop Property name
2139      * @returns Safe accessor
2140      */
2141     function safeProp(prop: string): string;
2142
2143     /**
2144      * Converts the first character of a string to upper case.
2145      * @param str String to convert
2146      * @returns Converted string
2147      */
2148     function ucFirst(str: string): string;
2149
2150     /**
2151      * Converts a string to camel case.
2152      * @param str String to convert
2153      * @returns Converted string
2154      */
2155     function camelCase(str: string): string;
2156
2157     /**
2158      * Compares reflected fields by id.
2159      * @param a First field
2160      * @param b Second field
2161      * @returns Comparison value
2162      */
2163     function compareFieldsById(a: Field, b: Field): number;
2164
2165     /**
2166      * Decorator helper for types (TypeScript).
2167      * @param ctor Constructor function
2168      * @param [typeName] Type name, defaults to the constructor's name
2169      * @returns Reflected type
2170      */
2171     function decorateType<T extends Message<T>>(ctor: Constructor<T>, typeName?: string): Type;
2172
2173     /**
2174      * Decorator helper for enums (TypeScript).
2175      * @param object Enum object
2176      * @returns Reflected enum
2177      */
2178     function decorateEnum(object: object): Enum;
2179
2180     /**
2181      * Sets the value of a property by property path. If a value already exists, it is turned to an array
2182      * @param dst Destination object
2183      * @param path dot '.' delimited path of the property to set
2184      * @param value the value to set
2185      * @returns Destination object
2186      */
2187     function setProperty(dst: { [k: string]: any }, path: string, value: object): { [k: string]: any };
2188
2189     /** Decorator root (TypeScript). */
2190     let decorateRoot: Root;
2191
2192     /**
2193      * Returns a promise from a node-style callback function.
2194      * @param fn Function to call
2195      * @param ctx Function context
2196      * @param params Function arguments
2197      * @returns Promisified function
2198      */
2199     function asPromise(fn: asPromiseCallback, ctx: any, ...params: any[]): Promise<any>;
2200
2201     /** A minimal base64 implementation for number arrays. */
2202     namespace base64 {
2203
2204         /**
2205          * Calculates the byte length of a base64 encoded string.
2206          * @param string Base64 encoded string
2207          * @returns Byte length
2208          */
2209         function length(string: string): number;
2210
2211         /**
2212          * Encodes a buffer to a base64 encoded string.
2213          * @param buffer Source buffer
2214          * @param start Source start
2215          * @param end Source end
2216          * @returns Base64 encoded string
2217          */
2218         function encode(buffer: Uint8Array, start: number, end: number): string;
2219
2220         /**
2221          * Decodes a base64 encoded string to a buffer.
2222          * @param string Source string
2223          * @param buffer Destination buffer
2224          * @param offset Destination offset
2225          * @returns Number of bytes written
2226          * @throws {Error} If encoding is invalid
2227          */
2228         function decode(string: string, buffer: Uint8Array, offset: number): number;
2229
2230         /**
2231          * Tests if the specified string appears to be base64 encoded.
2232          * @param string String to test
2233          * @returns `true` if probably base64 encoded, otherwise false
2234          */
2235         function test(string: string): boolean;
2236     }
2237
2238     /**
2239      * Begins generating a function.
2240      * @param functionParams Function parameter names
2241      * @param [functionName] Function name if not anonymous
2242      * @returns Appender that appends code to the function's body
2243      */
2244     function codegen(functionParams: string[], functionName?: string): Codegen;
2245
2246     namespace codegen {
2247
2248         /** When set to `true`, codegen will log generated code to console. Useful for debugging. */
2249         let verbose: boolean;
2250     }
2251
2252     /**
2253      * Begins generating a function.
2254      * @param [functionName] Function name if not anonymous
2255      * @returns Appender that appends code to the function's body
2256      */
2257     function codegen(functionName?: string): Codegen;
2258
2259     /** A minimal event emitter. */
2260     class EventEmitter {
2261
2262         /** Constructs a new event emitter instance. */
2263         constructor();
2264
2265         /**
2266          * Registers an event listener.
2267          * @param evt Event name
2268          * @param fn Listener
2269          * @param [ctx] Listener context
2270          * @returns `this`
2271          */
2272         public on(evt: string, fn: EventEmitterListener, ctx?: any): this;
2273
2274         /**
2275          * Removes an event listener or any matching listeners if arguments are omitted.
2276          * @param [evt] Event name. Removes all listeners if omitted.
2277          * @param [fn] Listener to remove. Removes all listeners of `evt` if omitted.
2278          * @returns `this`
2279          */
2280         public off(evt?: string, fn?: EventEmitterListener): this;
2281
2282         /**
2283          * Emits an event by calling its listeners with the specified arguments.
2284          * @param evt Event name
2285          * @param args Arguments
2286          * @returns `this`
2287          */
2288         public emit(evt: string, ...args: any[]): this;
2289     }
2290
2291     /** Reads / writes floats / doubles from / to buffers. */
2292     namespace float {
2293
2294         /**
2295          * Writes a 32 bit float to a buffer using little endian byte order.
2296          * @param val Value to write
2297          * @param buf Target buffer
2298          * @param pos Target buffer offset
2299          */
2300         function writeFloatLE(val: number, buf: Uint8Array, pos: number): void;
2301
2302         /**
2303          * Writes a 32 bit float to a buffer using big endian byte order.
2304          * @param val Value to write
2305          * @param buf Target buffer
2306          * @param pos Target buffer offset
2307          */
2308         function writeFloatBE(val: number, buf: Uint8Array, pos: number): void;
2309
2310         /**
2311          * Reads a 32 bit float from a buffer using little endian byte order.
2312          * @param buf Source buffer
2313          * @param pos Source buffer offset
2314          * @returns Value read
2315          */
2316         function readFloatLE(buf: Uint8Array, pos: number): number;
2317
2318         /**
2319          * Reads a 32 bit float from a buffer using big endian byte order.
2320          * @param buf Source buffer
2321          * @param pos Source buffer offset
2322          * @returns Value read
2323          */
2324         function readFloatBE(buf: Uint8Array, pos: number): number;
2325
2326         /**
2327          * Writes a 64 bit double to a buffer using little endian byte order.
2328          * @param val Value to write
2329          * @param buf Target buffer
2330          * @param pos Target buffer offset
2331          */
2332         function writeDoubleLE(val: number, buf: Uint8Array, pos: number): void;
2333
2334         /**
2335          * Writes a 64 bit double to a buffer using big endian byte order.
2336          * @param val Value to write
2337          * @param buf Target buffer
2338          * @param pos Target buffer offset
2339          */
2340         function writeDoubleBE(val: number, buf: Uint8Array, pos: number): void;
2341
2342         /**
2343          * Reads a 64 bit double from a buffer using little endian byte order.
2344          * @param buf Source buffer
2345          * @param pos Source buffer offset
2346          * @returns Value read
2347          */
2348         function readDoubleLE(buf: Uint8Array, pos: number): number;
2349
2350         /**
2351          * Reads a 64 bit double from a buffer using big endian byte order.
2352          * @param buf Source buffer
2353          * @param pos Source buffer offset
2354          * @returns Value read
2355          */
2356         function readDoubleBE(buf: Uint8Array, pos: number): number;
2357     }
2358
2359     /**
2360      * Fetches the contents of a file.
2361      * @param filename File path or url
2362      * @param options Fetch options
2363      * @param callback Callback function
2364      */
2365     function fetch(filename: string, options: IFetchOptions, callback: FetchCallback): void;
2366
2367     /**
2368      * Fetches the contents of a file.
2369      * @param path File path or url
2370      * @param callback Callback function
2371      */
2372     function fetch(path: string, callback: FetchCallback): void;
2373
2374     /**
2375      * Fetches the contents of a file.
2376      * @param path File path or url
2377      * @param [options] Fetch options
2378      * @returns Promise
2379      */
2380     function fetch(path: string, options?: IFetchOptions): Promise<(string|Uint8Array)>;
2381
2382     /**
2383      * Requires a module only if available.
2384      * @param moduleName Module to require
2385      * @returns Required module if available and not empty, otherwise `null`
2386      */
2387     function inquire(moduleName: string): object;
2388
2389     /** A minimal path module to resolve Unix, Windows and URL paths alike. */
2390     namespace path {
2391
2392         /**
2393          * Tests if the specified path is absolute.
2394          * @param path Path to test
2395          * @returns `true` if path is absolute
2396          */
2397         function isAbsolute(path: string): boolean;
2398
2399         /**
2400          * Normalizes the specified path.
2401          * @param path Path to normalize
2402          * @returns Normalized path
2403          */
2404         function normalize(path: string): string;
2405
2406         /**
2407          * Resolves the specified include path against the specified origin path.
2408          * @param originPath Path to the origin file
2409          * @param includePath Include path relative to origin path
2410          * @param [alreadyNormalized=false] `true` if both paths are already known to be normalized
2411          * @returns Path to the include file
2412          */
2413         function resolve(originPath: string, includePath: string, alreadyNormalized?: boolean): string;
2414     }
2415
2416     /**
2417      * A general purpose buffer pool.
2418      * @param alloc Allocator
2419      * @param slice Slicer
2420      * @param [size=8192] Slab size
2421      * @returns Pooled allocator
2422      */
2423     function pool(alloc: PoolAllocator, slice: PoolSlicer, size?: number): PoolAllocator;
2424
2425     /** A minimal UTF8 implementation for number arrays. */
2426     namespace utf8 {
2427
2428         /**
2429          * Calculates the UTF8 byte length of a string.
2430          * @param string String
2431          * @returns Byte length
2432          */
2433         function length(string: string): number;
2434
2435         /**
2436          * Reads UTF8 bytes as a string.
2437          * @param buffer Source buffer
2438          * @param start Source start
2439          * @param end Source end
2440          * @returns String read
2441          */
2442         function read(buffer: Uint8Array, start: number, end: number): string;
2443
2444         /**
2445          * Writes a string as UTF8 bytes.
2446          * @param string Source string
2447          * @param buffer Destination buffer
2448          * @param offset Destination offset
2449          * @returns Bytes written
2450          */
2451         function write(string: string, buffer: Uint8Array, offset: number): number;
2452     }
2453 }
2454
2455 /**
2456  * Generates a verifier specific to the specified message type.
2457  * @param mtype Message type
2458  * @returns Codegen instance
2459  */
2460 export function verifier(mtype: Type): Codegen;
2461
2462 /** Wrappers for common types. */
2463 export const wrappers: { [k: string]: IWrapper };
2464
2465 /**
2466  * From object converter part of an {@link IWrapper}.
2467  * @param object Plain object
2468  * @returns Message instance
2469  */
2470 type WrapperFromObjectConverter = (this: Type, object: { [k: string]: any }) => Message<{}>;
2471
2472 /**
2473  * To object converter part of an {@link IWrapper}.
2474  * @param message Message instance
2475  * @param [options] Conversion options
2476  * @returns Plain object
2477  */
2478 type WrapperToObjectConverter = (this: Type, message: Message<{}>, options?: IConversionOptions) => { [k: string]: any };
2479
2480 /** Common type wrapper part of {@link wrappers}. */
2481 export interface IWrapper {
2482
2483     /** From object converter */
2484     fromObject?: WrapperFromObjectConverter;
2485
2486     /** To object converter */
2487     toObject?: WrapperToObjectConverter;
2488 }
2489
2490 /** Wire format writer using `Uint8Array` if available, otherwise `Array`. */
2491 export class Writer {
2492
2493     /** Constructs a new writer instance. */
2494     constructor();
2495
2496     /** Current length. */
2497     public len: number;
2498
2499     /** Operations head. */
2500     public head: object;
2501
2502     /** Operations tail */
2503     public tail: object;
2504
2505     /** Linked forked states. */
2506     public states: (object|null);
2507
2508     /**
2509      * Creates a new writer.
2510      * @returns A {@link BufferWriter} when Buffers are supported, otherwise a {@link Writer}
2511      */
2512     public static create(): (BufferWriter|Writer);
2513
2514     /**
2515      * Allocates a buffer of the specified size.
2516      * @param size Buffer size
2517      * @returns Buffer
2518      */
2519     public static alloc(size: number): Uint8Array;
2520
2521     /**
2522      * Writes an unsigned 32 bit value as a varint.
2523      * @param value Value to write
2524      * @returns `this`
2525      */
2526     public uint32(value: number): Writer;
2527
2528     /**
2529      * Writes a signed 32 bit value as a varint.
2530      * @param value Value to write
2531      * @returns `this`
2532      */
2533     public int32(value: number): Writer;
2534
2535     /**
2536      * Writes a 32 bit value as a varint, zig-zag encoded.
2537      * @param value Value to write
2538      * @returns `this`
2539      */
2540     public sint32(value: number): Writer;
2541
2542     /**
2543      * Writes an unsigned 64 bit value as a varint.
2544      * @param value Value to write
2545      * @returns `this`
2546      * @throws {TypeError} If `value` is a string and no long library is present.
2547      */
2548     public uint64(value: (Long|number|string)): Writer;
2549
2550     /**
2551      * Writes a signed 64 bit value as a varint.
2552      * @param value Value to write
2553      * @returns `this`
2554      * @throws {TypeError} If `value` is a string and no long library is present.
2555      */
2556     public int64(value: (Long|number|string)): Writer;
2557
2558     /**
2559      * Writes a signed 64 bit value as a varint, zig-zag encoded.
2560      * @param value Value to write
2561      * @returns `this`
2562      * @throws {TypeError} If `value` is a string and no long library is present.
2563      */
2564     public sint64(value: (Long|number|string)): Writer;
2565
2566     /**
2567      * Writes a boolish value as a varint.
2568      * @param value Value to write
2569      * @returns `this`
2570      */
2571     public bool(value: boolean): Writer;
2572
2573     /**
2574      * Writes an unsigned 32 bit value as fixed 32 bits.
2575      * @param value Value to write
2576      * @returns `this`
2577      */
2578     public fixed32(value: number): Writer;
2579
2580     /**
2581      * Writes a signed 32 bit value as fixed 32 bits.
2582      * @param value Value to write
2583      * @returns `this`
2584      */
2585     public sfixed32(value: number): Writer;
2586
2587     /**
2588      * Writes an unsigned 64 bit value as fixed 64 bits.
2589      * @param value Value to write
2590      * @returns `this`
2591      * @throws {TypeError} If `value` is a string and no long library is present.
2592      */
2593     public fixed64(value: (Long|number|string)): Writer;
2594
2595     /**
2596      * Writes a signed 64 bit value as fixed 64 bits.
2597      * @param value Value to write
2598      * @returns `this`
2599      * @throws {TypeError} If `value` is a string and no long library is present.
2600      */
2601     public sfixed64(value: (Long|number|string)): Writer;
2602
2603     /**
2604      * Writes a float (32 bit).
2605      * @param value Value to write
2606      * @returns `this`
2607      */
2608     public float(value: number): Writer;
2609
2610     /**
2611      * Writes a double (64 bit float).
2612      * @param value Value to write
2613      * @returns `this`
2614      */
2615     public double(value: number): Writer;
2616
2617     /**
2618      * Writes a sequence of bytes.
2619      * @param value Buffer or base64 encoded string to write
2620      * @returns `this`
2621      */
2622     public bytes(value: (Uint8Array|string)): Writer;
2623
2624     /**
2625      * Writes a string.
2626      * @param value Value to write
2627      * @returns `this`
2628      */
2629     public string(value: string): Writer;
2630
2631     /**
2632      * Forks this writer's state by pushing it to a stack.
2633      * Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
2634      * @returns `this`
2635      */
2636     public fork(): Writer;
2637
2638     /**
2639      * Resets this instance to the last state.
2640      * @returns `this`
2641      */
2642     public reset(): Writer;
2643
2644     /**
2645      * Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
2646      * @returns `this`
2647      */
2648     public ldelim(): Writer;
2649
2650     /**
2651      * Finishes the write operation.
2652      * @returns Finished buffer
2653      */
2654     public finish(): Uint8Array;
2655 }
2656
2657 /** Wire format writer using node buffers. */
2658 export class BufferWriter extends Writer {
2659
2660     /** Constructs a new buffer writer instance. */
2661     constructor();
2662
2663     /**
2664      * Allocates a buffer of the specified size.
2665      * @param size Buffer size
2666      * @returns Buffer
2667      */
2668     public static alloc(size: number): Buffer;
2669
2670     /**
2671      * Finishes the write operation.
2672      * @returns Finished buffer
2673      */
2674     public finish(): Buffer;
2675 }
2676
2677 /**
2678  * Callback as used by {@link util.asPromise}.
2679  * @param error Error, if any
2680  * @param params Additional arguments
2681  */
2682 type asPromiseCallback = (error: (Error|null), ...params: any[]) => void;
2683
2684 /**
2685  * Appends code to the function's body or finishes generation.
2686  * @param [formatStringOrScope] Format string or, to finish the function, an object of additional scope variables, if any
2687  * @param [formatParams] Format parameters
2688  * @returns Itself or the generated function if finished
2689  * @throws {Error} If format parameter counts do not match
2690  */
2691 type Codegen = (formatStringOrScope?: (string|{ [k: string]: any }), ...formatParams: any[]) => (Codegen|Function);
2692
2693 /**
2694  * Event listener as used by {@link util.EventEmitter}.
2695  * @param args Arguments
2696  */
2697 type EventEmitterListener = (...args: any[]) => void;
2698
2699 /**
2700  * Node-style callback as used by {@link util.fetch}.
2701  * @param error Error, if any, otherwise `null`
2702  * @param [contents] File contents, if there hasn't been an error
2703  */
2704 type FetchCallback = (error: Error, contents?: string) => void;
2705
2706 /** Options as used by {@link util.fetch}. */
2707 export interface IFetchOptions {
2708
2709     /** Whether expecting a binary response */
2710     binary?: boolean;
2711
2712     /** If `true`, forces the use of XMLHttpRequest */
2713     xhr?: boolean;
2714 }
2715
2716 /**
2717  * An allocator as used by {@link util.pool}.
2718  * @param size Buffer size
2719  * @returns Buffer
2720  */
2721 type PoolAllocator = (size: number) => Uint8Array;
2722
2723 /**
2724  * A slicer as used by {@link util.pool}.
2725  * @param start Start offset
2726  * @param end End offset
2727  * @returns Buffer slice
2728  */
2729 type PoolSlicer = (this: Uint8Array, start: number, end: number) => Uint8Array;