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