@cloudpss/ubjson
Version:
Opinionated UBJSON encoder/decoder for CloudPSS.
40 lines • 1.08 kB
JavaScript
import { Subject } from 'rxjs';
import { decode } from '../rxjs/decoder.js';
/** 流式解码 UBJSON */
export class DecodeTransformer {
constructor(options) {
this.buffer = new Subject();
this.buffer.pipe(decode(options)).subscribe({
next: (value) => {
// null is not allowed in a stream
if (value == null)
return;
this.controller.enqueue(value);
},
error: (err) => {
this.controller.error(err);
},
complete: () => {
this.controller.terminate();
},
});
}
buffer;
controller;
/** @inheritdoc */
transform(obj, controller) {
try {
this.controller = controller;
this.buffer.next(obj);
}
catch (ex) {
controller.error(ex);
}
}
/** @inheritdoc */
flush(controller) {
this.controller = controller;
this.buffer.complete();
}
}
//# sourceMappingURL=decoder.js.map