Created
October 15, 2017 15:52
-
-
Save BrokenR3C0RD/fc2f80277cf14d6f038784a02647c3ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Declaration file for js-binary */ | |
declare module "js-binary" { | |
export class Data { | |
public constructor(capacity: number); | |
private _buffer: Buffer; | |
private _length: number; | |
public appendBuffer(data: Buffer): void; | |
public writeUInt8(value: number): void; | |
public writeUInt16(value: number): void; | |
public writeUInt32(value: number): void; | |
public writeDouble(value: number): void; | |
public toBuffer(): Buffer; | |
private _alloc(byes: number): void; | |
} | |
export class Field { | |
public constructor(name: string, type: string | object | Array<string> | Array<object>); | |
public optional: boolean; | |
public name: string; | |
public array: boolean; | |
public type: Type; | |
} | |
export class ReadState { | |
public constructor(buffer: Buffer); | |
private _buffer: Buffer; | |
private _offset: number; | |
public peekUInt8(): number; | |
public readUInt8(): number; | |
public readUInt16(): number; | |
public readUInt32(): number; | |
public readDouble(): number; | |
public readBuffer(length: number): Buffer; | |
public hasEnded(): boolean; | |
} | |
export module Type { | |
export enum TYPES { | |
UINT = "uint", | |
INT = "int", | |
FLOAT = "float", | |
STRING = "string", | |
BUFFER = "buffer", | |
BOOLEAN = "boolean", | |
JSON = "json", | |
OID = "oid", | |
REGEX = "regex", | |
DATE = "date", | |
ARRAY = "[array]", | |
OBJECT = "{object}" | |
} | |
} | |
export class Type { | |
public constructor(type: string | object | Array<string> | Array<object>); | |
public types: types; | |
public encode(value: any): Buffer; | |
public decode(value: Buffer): any; | |
public write(value: any, data: Data, path: string): void; | |
private _writeArray(value: any, data: Data, path: string, type: Type): void; | |
public read(state: ReadState): any; | |
public getHash(): Buffer; | |
private _compileRead(): (state: ReadState) => any; | |
private _readArray(type: Type, state: ReadState): Array<any>; | |
} | |
interface JSBinType<T> { | |
write(value: T, data: Data, path: string): void; | |
read(state: ReadState): T; | |
} | |
export class types { | |
public uint: JSBinType<number>; | |
public int: JSBinType<number>; | |
public float: JSBinType<number>; | |
public string: JSBinType<string>; | |
public Buffer: JSBinType<Buffer>; | |
public boolean: JSBinType<boolean>; | |
public json: JSBinType<object>; | |
public oid: JSBinType<string>; | |
public regex: JSBinType<RegExp>; | |
public date: JSBinType<Date>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment