1 | (function() {
|
2 | 'use strict';
|
3 |
|
4 |
|
5 |
|
6 | this.Hollerith_codec = class Hollerith_codec {
|
7 |
|
8 | constructor() {
|
9 | this.sign_delta = 0x80000000
|
10 | this.u32_width = 4
|
11 | this.vnr_width = 5
|
12 | this.nr_min = -0x80000000
|
13 | this.nr_max = +0x7fffffff
|
14 | return void 0;
|
15 | }
|
16 |
|
17 |
|
18 | encode(vnr) {
|
19 | var R, i, idx, offset, ref, ref1, ref2;
|
20 | if (!((0 < (ref = vnr.length) && ref <= this.vnr_width))) {
|
21 | throw new Error(`^44798^ expected VNR to be between 1 and ${this.vnr_width} elements long, got length ${vnr.length}`);
|
22 | }
|
23 | R = Buffer.alloc(this.vnr_width * this.u32_width, 0x00);
|
24 | offset = -this.u32_width;
|
25 | for (idx = i = 0, ref1 = this.vnr_width; (0 <= ref1 ? i < ref1 : i > ref1); idx = 0 <= ref1 ? ++i : --i) {
|
26 | R.writeUInt32BE(((ref2 = vnr[idx]) != null ? ref2 : 0) + this.sign_delta, (offset += this.u32_width));
|
27 | }
|
28 | return R;
|
29 | }
|
30 |
|
31 |
|
32 | _encode_bcd(vnr) {
|
33 | var R, base, dpe, i, idx, minus, nr, padder, plus, ref, ref1, sign, vnr_width;
|
34 | vnr_width = 5
|
35 | dpe = 4
|
36 | base = 36;
|
37 | plus = '+';
|
38 | minus = '!';
|
39 | padder = '.';
|
40 | R = [];
|
41 | for (idx = i = 0, ref = vnr_width; (0 <= ref ? i < ref : i > ref); idx = 0 <= ref ? ++i : --i) {
|
42 | nr = (ref1 = vnr[idx]) != null ? ref1 : 0;
|
43 | sign = nr >= 0 ? plus : minus;
|
44 | R.push(sign + ((Math.abs(nr)).toString(base)).padStart(dpe, padder));
|
45 | }
|
46 | R = R.join(',');
|
47 | return R;
|
48 | }
|
49 |
|
50 | };
|
51 |
|
52 |
|
53 | this.HOLLERITH_CODEC = new this.Hollerith_codec();
|
54 |
|
55 | }).call(this);
|
56 |
|
57 |
|
\ | No newline at end of file |