1 |
|
2 | import { EventEmitter } from "events";
|
3 | import * as stream from "stream";
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export function encode(input: any, options?: EncoderOptions): Buffer;
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | export function decode(input: Buffer | Uint8Array | number[], options?: DecoderOptions): any;
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | export function createEncodeStream(options?: EncoderOptions & stream.TransformOptions): EncodeStream;
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | export function createDecodeStream(options?: DecoderOptions & stream.TransformOptions): DecodeStream;
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | export function createCodec(options?: CodecOptions): Codec;
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | export const codec: {
|
37 | |
38 |
|
39 |
|
40 | preset: Codec;
|
41 | };
|
42 |
|
43 | export interface Codec {
|
44 | |
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | addExtPacker<T>(
|
52 | etype: number,
|
53 | Class: new(...args: any[]) => T,
|
54 | packer: (t: T) => Buffer | Uint8Array,
|
55 | ): void;
|
56 |
|
57 | |
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | addExtUnpacker<T>(etype: number, unpacker: (data: Buffer | Uint8Array) => T): void;
|
64 | }
|
65 |
|
66 | export interface Encoder {
|
67 | bufferish: any;
|
68 | maxBufferSize: number;
|
69 | minBufferSize: number;
|
70 | offset: number;
|
71 | start: number;
|
72 | write(chunk: any): void;
|
73 | fetch(): void;
|
74 | flush(): void;
|
75 | push(chunk: any): void;
|
76 | pull(): number;
|
77 | read(): number;
|
78 | reserve(length: number): number;
|
79 | send(buffer: Buffer): void;
|
80 | encode(chunk: any): void;
|
81 | end(chunk: any): void;
|
82 | }
|
83 |
|
84 | export function Decoder(options?: DecoderOptions): Decoder;
|
85 |
|
86 | export interface Decoder extends EventEmitter {
|
87 | bufferish: any;
|
88 | offset: number;
|
89 | fetch(): void;
|
90 | flush(): void;
|
91 | pull(): number;
|
92 | read(): number;
|
93 | write(chunk: any): void;
|
94 | reserve(length: number): number;
|
95 | decode(chunk: any): void;
|
96 | push(chunk: any): void;
|
97 | end(chunk: any): void;
|
98 | }
|
99 |
|
100 | export interface EncodeStream extends stream.Transform {
|
101 | encoder: Encoder;
|
102 | }
|
103 |
|
104 | export interface DecodeStream extends stream.Transform {
|
105 | decoder: Decoder;
|
106 | }
|
107 |
|
108 | export interface CodecOptions {
|
109 | /**
|
110 | * It includes the preset extensions for JavaScript native objects.
|
111 | * @see https://github.com/kawanet/msgpack-lite#extension-types
|
112 | * @default false
|
113 | */
|
114 | preset?: boolean | undefined;
|
115 | /**
|
116 | * It runs a validation of the value before writing it into buffer.
|
117 | * This is the default behavior for some old browsers which do not support ArrayBuffer object.
|
118 | * @default varies
|
119 | */
|
120 | safe?: boolean | undefined;
|
121 | /**
|
122 | * It uses raw formats instead of bin and str.
|
123 | * Set true for compatibility with msgpack's old spec.
|
124 | * @see https://github.com/kawanet/msgpack-lite#compatibility-mode
|
125 | * @default false
|
126 | */
|
127 | useraw?: boolean | undefined;
|
128 | /**
|
129 | * It decodes msgpack's int64/uint64 formats with int64-buffer object.
|
130 | * int64-buffer is a cutom integer type with 64 bits of precision instead
|
131 | * of the built-in IEEE-754 53 bits. See https://github.com/kawanet/int64-buffer
|
132 | * @default false
|
133 | */
|
134 | int64?: boolean | undefined;
|
135 | /**
|
136 | * It ties msgpack's bin format with ArrayBuffer object, instead of Buffer object.
|
137 | * @default false
|
138 | */
|
139 | binarraybuffer?: boolean | undefined;
|
140 | /**
|
141 | * It returns Uint8Array object when encoding, instead of Buffer object.
|
142 | * @default false
|
143 | */
|
144 | uint8array?: boolean | undefined;
|
145 | /**
|
146 | * It uses the global JavaScript Map type, if available, to unpack MessagePack map elements.
|
147 | * @default false
|
148 | */
|
149 | usemap?: boolean | undefined;
|
150 | }
|
151 |
|
152 | export interface EncoderOptions {
|
153 | codec?: Codec | undefined;
|
154 | }
|
155 |
|
156 | export interface DecoderOptions {
|
157 | codec?: Codec | undefined;
|
158 | }
|
159 |
|
\ | No newline at end of file |