mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
Typings for individual Decoder factory (#38631)
Decoder can be built standalone (is part of the actual public interface and part of the performance-test interface described in the README.md of the project). Moreover, Decoder is an event emitter. The interface has been update accordingly.
This commit is contained in:
committed by
Michael Crane
parent
06886907f1
commit
ed41e25e73
5
types/msgpack-lite/index.d.ts
vendored
5
types/msgpack-lite/index.d.ts
vendored
@@ -5,6 +5,7 @@
|
||||
|
||||
/// <reference types="node" />
|
||||
import * as stream from 'stream';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
/**
|
||||
* encode from JS Object to MessagePack
|
||||
@@ -84,7 +85,9 @@ export interface Encoder {
|
||||
end(chunk: any): void;
|
||||
}
|
||||
|
||||
export interface Decoder {
|
||||
export function Decoder(options?: DecoderOptions): Decoder;
|
||||
|
||||
export interface Decoder extends EventEmitter {
|
||||
bufferish: any;
|
||||
offset: number;
|
||||
fetch(): void;
|
||||
|
||||
@@ -84,3 +84,18 @@ function customExtensionTypes() {
|
||||
return new MyVector(array[0], array[1]); // return Object deserialized
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/kawanet/msgpack-lite#benchmarks
|
||||
// (this is not well documented, but in the test there is an example usage.)
|
||||
function standaloneDecoder() {
|
||||
const decoder = msgpack.Decoder();
|
||||
const object = { test: "Object" };
|
||||
const encoded = msgpack.encode(object);
|
||||
decoder.on('data', (obj) => {
|
||||
if (object.test !== obj.test) {
|
||||
throw Error();
|
||||
}
|
||||
});
|
||||
|
||||
decoder.push(encoded);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user