1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.quality = void 0;
|
4 | const types_1 = require("./types");
|
5 | const decimal_js_1 = require("decimal.js");
|
6 | const bigInt = require("big-integer");
|
7 | const buffer_1 = require("buffer/");
|
8 |
|
9 |
|
10 |
|
11 | class quality {
|
12 | |
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | static encode(quality) {
|
19 | const decimal = new decimal_js_1.Decimal(quality);
|
20 | const exponent = decimal.e - 15;
|
21 | const qualityString = decimal.times(`1e${-exponent}`).abs().toString();
|
22 | const bytes = types_1.coreTypes.UInt64.from(bigInt(qualityString)).toBytes();
|
23 | bytes[0] = exponent + 100;
|
24 | return bytes;
|
25 | }
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | static decode(quality) {
|
33 | const bytes = buffer_1.Buffer.from(quality, 'hex').slice(-8);
|
34 | const exponent = bytes[0] - 100;
|
35 | const mantissa = new decimal_js_1.Decimal(`0x${bytes.slice(1).toString('hex')}`);
|
36 | return mantissa.times(`1e${exponent}`);
|
37 | }
|
38 | }
|
39 | exports.quality = quality;
|
40 |
|
\ | No newline at end of file |