20 lines
598 B
JavaScript
20 lines
598 B
JavaScript
|
|
||
|
export function augmentParserWithThroughput(Parser) {
|
||
|
const {Decoder, Encoder} = Parser;
|
||
|
// Decoder.
|
||
|
Decoder.throughput = 0;
|
||
|
const {parseBinary} = Decoder.prototype;
|
||
|
Decoder.prototype.parseBinary = function (obj) {
|
||
|
Decoder.throughput += obj.length || obj.byteLength;
|
||
|
return parseBinary.call(this, obj);
|
||
|
};
|
||
|
// Encoder.
|
||
|
Encoder.throughput = 0;
|
||
|
const {pack} = Encoder.prototype;
|
||
|
Encoder.prototype.pack = function (packet) {
|
||
|
const buffer = pack.call(this, packet);
|
||
|
Encoder.throughput += buffer.length || buffer.byteLength;
|
||
|
return buffer;
|
||
|
};
|
||
|
return Parser;
|
||
|
}
|