@abaplint/runtime 2.8.12 → 2.8.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/abap_regex.js +1 -0
- package/build/src/compare/eq.js +7 -9
- package/build/src/compare/gt.js +6 -8
- package/build/src/compare/initial.js +1 -1
- package/build/src/offset_length.d.ts +1 -1
- package/build/src/offset_length.js +21 -18
- package/build/src/operators/_parse.js +5 -2
- package/build/src/operators/divide.d.ts +1 -1
- package/build/src/operators/multiply.d.ts +1 -1
- package/build/src/operators/power.d.ts +1 -1
- package/build/src/statements/describe.js +2 -1
- package/build/src/statements/get_bit.d.ts +2 -2
- package/build/src/statements/get_bit.js +1 -0
- package/build/src/statements/set_bit.d.ts +2 -2
- package/build/src/statements/set_bit.js +1 -0
- package/build/src/types/data_reference.d.ts +1 -1
- package/build/src/types/field_symbol.d.ts +1 -1
- package/build/src/types/field_symbol.js +2 -1
- package/build/src/types/hex.d.ts +1 -1
- package/build/src/types/hex.js +20 -19
- package/build/src/types/hex_uint8.d.ts +26 -0
- package/build/src/types/hex_uint8.js +148 -0
- package/build/src/types/index.d.ts +1 -0
- package/build/src/types/index.js +1 -0
- package/build/src/types/integer.js +4 -2
- package/build/src/types/integer8.js +2 -1
- package/build/src/types/xstring.js +8 -6
- package/package.json +1 -1
package/build/src/abap_regex.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ABAPRegExp = void 0;
|
|
4
|
+
// https://github.com/TooTallNate/pcre-to-regexp/blob/master/src/index.ts
|
|
4
5
|
class ABAPRegExp {
|
|
5
6
|
// converts from ABAP specific regex to javascript regex
|
|
6
7
|
static convert(input) {
|
package/build/src/compare/eq.js
CHANGED
|
@@ -54,6 +54,7 @@ function eq(left, right) {
|
|
|
54
54
|
else if (left instanceof types_1.String
|
|
55
55
|
|| left instanceof types_1.XString
|
|
56
56
|
|| left instanceof types_1.Numc
|
|
57
|
+
|| left instanceof types_1.HexUInt8
|
|
57
58
|
|| left instanceof types_1.Hex) {
|
|
58
59
|
return right.getTrimEnd() === left.get();
|
|
59
60
|
}
|
|
@@ -105,13 +106,8 @@ function eq(left, right) {
|
|
|
105
106
|
return false;
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
|
-
else if (right instanceof types_1.Hex) {
|
|
109
|
-
if (left instanceof types_1.Hex || left instanceof types_1.XString) {
|
|
110
|
-
return right.get() === left.get();
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
else if (right instanceof types_1.XString) {
|
|
114
|
-
if (left instanceof types_1.Hex || left instanceof types_1.XString) {
|
|
109
|
+
else if (right instanceof types_1.Hex || right instanceof types_1.HexUInt8 || right instanceof types_1.XString) {
|
|
110
|
+
if (left instanceof types_1.Hex || left instanceof types_1.XString || left instanceof types_1.HexUInt8) {
|
|
115
111
|
return right.get() === left.get();
|
|
116
112
|
}
|
|
117
113
|
}
|
|
@@ -203,10 +199,12 @@ function eq(left, right) {
|
|
|
203
199
|
else {
|
|
204
200
|
r = right;
|
|
205
201
|
}
|
|
206
|
-
if (right instanceof types_1.Hex && typeof l === "number") {
|
|
202
|
+
if ((right instanceof types_1.Hex || right instanceof types_1.HexUInt8) && typeof l === "number") {
|
|
203
|
+
// todo, handle this case earlier
|
|
207
204
|
r = parseInt(right.get(), 16);
|
|
208
205
|
}
|
|
209
|
-
else if (left instanceof types_1.Hex && typeof r === "number") {
|
|
206
|
+
else if ((left instanceof types_1.Hex || left instanceof types_1.HexUInt8) && typeof r === "number") {
|
|
207
|
+
// todo, handle this case earlier
|
|
210
208
|
l = parseInt(left.get(), 16);
|
|
211
209
|
}
|
|
212
210
|
if (right instanceof types_1.Float && left instanceof types_1.Float) {
|
package/build/src/compare/gt.js
CHANGED
|
@@ -20,7 +20,7 @@ function gt(left, right) {
|
|
|
20
20
|
if (left instanceof types_1.Table || right instanceof types_1.Table || left instanceof types_1.HashedTable || right instanceof types_1.HashedTable) {
|
|
21
21
|
throw new Error("runtime_todo, gt TABLE");
|
|
22
22
|
}
|
|
23
|
-
if (left instanceof types_1.Hex || right instanceof types_1.Hex) {
|
|
23
|
+
if (left instanceof types_1.Hex || right instanceof types_1.Hex || left instanceof types_1.HexUInt8 || right instanceof types_1.HexUInt8) {
|
|
24
24
|
return gt_with_hex(left, right);
|
|
25
25
|
}
|
|
26
26
|
if (left instanceof types_1.Integer8 || right instanceof types_1.Integer8) {
|
|
@@ -79,6 +79,7 @@ function gt_with_hex(left, right) {
|
|
|
79
79
|
return left_hex > right_hex;
|
|
80
80
|
}
|
|
81
81
|
function get_hex_from_parameter(comparison_part) {
|
|
82
|
+
// todo: optimize?
|
|
82
83
|
let hex_from_parameter = "";
|
|
83
84
|
switch (typeof comparison_part) {
|
|
84
85
|
case "number":
|
|
@@ -90,7 +91,10 @@ function get_hex_from_parameter(comparison_part) {
|
|
|
90
91
|
.join("");
|
|
91
92
|
break;
|
|
92
93
|
case "object":
|
|
93
|
-
if (comparison_part instanceof types_1.Hex
|
|
94
|
+
if (comparison_part instanceof types_1.Hex
|
|
95
|
+
|| comparison_part instanceof types_1.XString
|
|
96
|
+
|| comparison_part instanceof types_1.HexUInt8
|
|
97
|
+
|| comparison_part instanceof types_1.Character) {
|
|
94
98
|
hex_from_parameter = comparison_part.get();
|
|
95
99
|
}
|
|
96
100
|
else if (comparison_part instanceof integer_1.Integer) {
|
|
@@ -99,12 +103,6 @@ function get_hex_from_parameter(comparison_part) {
|
|
|
99
103
|
hex_from_parameter = "0" + hex_from_parameter;
|
|
100
104
|
}
|
|
101
105
|
}
|
|
102
|
-
else if (comparison_part instanceof types_1.Character) {
|
|
103
|
-
hex_from_parameter = comparison_part.get();
|
|
104
|
-
}
|
|
105
|
-
else if (comparison_part instanceof types_1.XString) {
|
|
106
|
-
hex_from_parameter = comparison_part.get();
|
|
107
|
-
}
|
|
108
106
|
else {
|
|
109
107
|
throw new Error("runtime_todo, gt hex1");
|
|
110
108
|
}
|
|
@@ -21,7 +21,7 @@ function initial(val) {
|
|
|
21
21
|
else if (val instanceof types_1.Numc) {
|
|
22
22
|
return val.get().match(REGEX_ZEROS) !== null;
|
|
23
23
|
}
|
|
24
|
-
else if (val instanceof types_1.Hex) {
|
|
24
|
+
else if (val instanceof types_1.Hex || val instanceof types_1.HexUInt8) {
|
|
25
25
|
return val.get().match(REGEX_ZEROS) !== null;
|
|
26
26
|
}
|
|
27
27
|
else if (val instanceof types_1.Time) {
|
|
@@ -12,5 +12,5 @@ export declare class OffsetLength {
|
|
|
12
12
|
private readonly isHex;
|
|
13
13
|
constructor(obj: ICharacter | Character | Hex | XString | Structure | FieldSymbol, options: IOffsetLengthOptions);
|
|
14
14
|
get(): string;
|
|
15
|
-
set(value: ICharacter | string): void;
|
|
15
|
+
set(value: ICharacter | string | Hex | XString): void;
|
|
16
16
|
}
|
|
@@ -11,7 +11,7 @@ class OffsetLength {
|
|
|
11
11
|
throw new Error("GETWA_NOT_ASSIGNED");
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
this.isHex = this.obj instanceof types_1.Hex || this.obj instanceof types_1.XString;
|
|
14
|
+
this.isHex = this.obj instanceof types_1.Hex || this.obj instanceof types_1.XString || this.obj instanceof types_1.HexUInt8;
|
|
15
15
|
if (options.offset) {
|
|
16
16
|
if (typeof options.offset === "number") {
|
|
17
17
|
this.offset = options.offset;
|
|
@@ -62,16 +62,12 @@ class OffsetLength {
|
|
|
62
62
|
else if (value instanceof types_1.Integer) {
|
|
63
63
|
val = value.get() + "";
|
|
64
64
|
if (this.isHex) {
|
|
65
|
-
val = Number(val).toString(16);
|
|
65
|
+
val = Number(val).toString(16).toUpperCase();
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
else {
|
|
69
69
|
val = value.get() + "";
|
|
70
70
|
}
|
|
71
|
-
let old = this.obj instanceof types_1.Structure ? this.obj.getCharacter() : this.obj.get();
|
|
72
|
-
if (this.obj instanceof types_1.Character) {
|
|
73
|
-
old = old.padEnd(this.obj.getLength(), " ");
|
|
74
|
-
}
|
|
75
71
|
if (this.length) {
|
|
76
72
|
val = val.substr(0, this.length);
|
|
77
73
|
if (this.isHex || this.obj instanceof types_1.Time) {
|
|
@@ -81,20 +77,27 @@ class OffsetLength {
|
|
|
81
77
|
val = val.padEnd(this.length, " ");
|
|
82
78
|
}
|
|
83
79
|
}
|
|
84
|
-
if (this.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
old = old.substr(0, this.offset) + val;
|
|
80
|
+
if (this.isHex === true && this.obj instanceof types_1.HexUInt8) {
|
|
81
|
+
let base = this.offset ? this.offset / 2 : 0;
|
|
82
|
+
for (let current = 0; current < val.length; current += 2) {
|
|
83
|
+
const v = Number.parseInt(val.substr(current, 2), 16);
|
|
84
|
+
this.obj.setOffset(base, v);
|
|
85
|
+
base++;
|
|
86
|
+
}
|
|
92
87
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
88
|
+
else {
|
|
89
|
+
let old = this.obj instanceof types_1.Structure ? this.obj.getCharacter() : this.obj.get();
|
|
90
|
+
if (this.length && this.offset) {
|
|
91
|
+
old = old.substr(0, this.offset) + val + old.substr(this.offset + this.length);
|
|
92
|
+
}
|
|
93
|
+
else if (this.length) {
|
|
94
|
+
old = val + old.substr(this.length);
|
|
95
|
+
}
|
|
96
|
+
else if (this.offset) {
|
|
97
|
+
old = old.substr(0, this.offset) + val;
|
|
98
|
+
}
|
|
99
|
+
this.obj.set(old);
|
|
96
100
|
}
|
|
97
|
-
this.obj.set(old);
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
103
|
exports.OffsetLength = OffsetLength;
|
|
@@ -22,13 +22,16 @@ function parse(val) {
|
|
|
22
22
|
else if (val instanceof types_1.Float) {
|
|
23
23
|
return val.getRaw();
|
|
24
24
|
}
|
|
25
|
-
else if (val instanceof xstring_1.XString
|
|
25
|
+
else if (val instanceof xstring_1.XString) {
|
|
26
26
|
if (val.get() === "") {
|
|
27
27
|
return 0;
|
|
28
28
|
}
|
|
29
|
+
return parseInt(val.get(), 16);
|
|
30
|
+
}
|
|
31
|
+
else if (val instanceof types_1.Hex || val instanceof types_1.HexUInt8) {
|
|
29
32
|
let num = parseInt(val.get(), 16);
|
|
30
33
|
// handle two complement,
|
|
31
|
-
if (val
|
|
34
|
+
if (val.getLength() >= 4) {
|
|
32
35
|
const maxVal = Math.pow(2, val.get().length / 2 * 8);
|
|
33
36
|
if (num > maxVal / 2 - 1) {
|
|
34
37
|
num = num - maxVal;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Float, Integer, Integer8 } from "../types";
|
|
2
2
|
import { ICharacter } from "../types/_character";
|
|
3
3
|
import { INumeric } from "../types/_numeric";
|
|
4
|
-
export declare function divide(left: INumeric | ICharacter | Integer8 | string | number, right: INumeric | ICharacter | Integer8 | string | number): Integer |
|
|
4
|
+
export declare function divide(left: INumeric | ICharacter | Integer8 | string | number, right: INumeric | ICharacter | Integer8 | string | number): Integer | Integer8 | Float;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Float, Integer, Integer8 } from "../types";
|
|
2
2
|
import { ICharacter } from "../types/_character";
|
|
3
3
|
import { INumeric } from "../types/_numeric";
|
|
4
|
-
export declare function multiply(left: INumeric | ICharacter | string | Integer8 | number, right: INumeric | ICharacter | string | Integer8 | number): Integer |
|
|
4
|
+
export declare function multiply(left: INumeric | ICharacter | string | Integer8 | number, right: INumeric | ICharacter | string | Integer8 | number): Integer | Integer8 | Float;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Float, Integer8 } from "../types";
|
|
2
2
|
import { ICharacter } from "../types/_character";
|
|
3
3
|
import { INumeric } from "../types/_numeric";
|
|
4
|
-
export declare function power(left: INumeric | ICharacter | Integer8 | string | number, right: INumeric | ICharacter | Integer8 | string | number):
|
|
4
|
+
export declare function power(left: INumeric | ICharacter | Integer8 | string | number, right: INumeric | ICharacter | Integer8 | string | number): Integer8 | Float;
|
|
@@ -33,7 +33,7 @@ function describe(input) {
|
|
|
33
33
|
else if (input.field instanceof types_1.Numc) {
|
|
34
34
|
input.type.set("N");
|
|
35
35
|
}
|
|
36
|
-
else if (input.field instanceof types_1.Hex) {
|
|
36
|
+
else if (input.field instanceof types_1.Hex || input.field instanceof types_1.HexUInt8) {
|
|
37
37
|
input.type.set("X");
|
|
38
38
|
}
|
|
39
39
|
else if (input.field instanceof types_1.Packed) {
|
|
@@ -68,6 +68,7 @@ function describe(input) {
|
|
|
68
68
|
if (input.field instanceof types_1.Character
|
|
69
69
|
|| input.field instanceof types_1.Packed
|
|
70
70
|
|| input.field instanceof types_1.Numc
|
|
71
|
+
|| input.field instanceof types_1.HexUInt8
|
|
71
72
|
|| input.field instanceof types_1.Hex) {
|
|
72
73
|
input.length.set(input.field.getLength());
|
|
73
74
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Hex, XString } from "../types";
|
|
1
|
+
import { Hex, HexUInt8, XString } from "../types";
|
|
2
2
|
import { ICharacter } from "../types/_character";
|
|
3
3
|
import { INumeric } from "../types/_numeric";
|
|
4
|
-
export declare function getBit(number: INumeric, hex: XString | Hex, output: ICharacter): void;
|
|
4
|
+
export declare function getBit(number: INumeric, hex: XString | Hex | HexUInt8, output: ICharacter): void;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getBit = void 0;
|
|
4
4
|
function getBit(number, hex, output) {
|
|
5
|
+
// todo: optimize for HexUInt8
|
|
5
6
|
const charIndex = Math.floor((number.get() - 1) / 8);
|
|
6
7
|
const bitIndex = (number.get() - 1) % 8;
|
|
7
8
|
if (bitIndex < 0) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Hex, XString } from "../types";
|
|
1
|
+
import { Hex, HexUInt8, XString } from "../types";
|
|
2
2
|
import { ICharacter } from "../types/_character";
|
|
3
3
|
import { INumeric } from "../types/_numeric";
|
|
4
|
-
export declare function setBit(number: INumeric, hex: XString | Hex, val?: INumeric | ICharacter): void;
|
|
4
|
+
export declare function setBit(number: INumeric, hex: XString | Hex | HexUInt8, val?: INumeric | ICharacter): void;
|
|
@@ -5,6 +5,7 @@ function setBit(number, hex, val) {
|
|
|
5
5
|
if (number.get() <= 0) {
|
|
6
6
|
throw new Error("BIT_OFFSET_NOT_POSITIVE");
|
|
7
7
|
}
|
|
8
|
+
// todo: optimize for HexUInt8
|
|
8
9
|
const hexFull = hex.get();
|
|
9
10
|
const fullByteLength = Math.ceil(hexFull.length / 2);
|
|
10
11
|
const byteNum = Math.ceil(number.get() / 8);
|
|
@@ -21,7 +21,7 @@ export declare class DataReference {
|
|
|
21
21
|
get(): any;
|
|
22
22
|
array(): any;
|
|
23
23
|
getArrayLength(): any;
|
|
24
|
-
set(value: any): void |
|
|
24
|
+
set(value: any): void | Integer8 | Float | ABAPObject | this | Table | Structure;
|
|
25
25
|
getOffset(input: {
|
|
26
26
|
offset?: number | INumeric | Hex;
|
|
27
27
|
length?: number | INumeric | Hex;
|
|
@@ -17,7 +17,7 @@ export declare class FieldSymbol {
|
|
|
17
17
|
unassign(): void;
|
|
18
18
|
isAssigned(): boolean;
|
|
19
19
|
getPointer(): any;
|
|
20
|
-
dereference(): INumeric | ICharacter |
|
|
20
|
+
dereference(): INumeric | ICharacter | import("packages/runtime/src/types").Integer8 | Float | ABAPObject | Table | Structure | undefined;
|
|
21
21
|
clear(): void | Structure | undefined;
|
|
22
22
|
get(): any;
|
|
23
23
|
appendInitial(): import("./table").TableRowType | undefined;
|
|
@@ -6,6 +6,7 @@ const string_1 = require("./string");
|
|
|
6
6
|
const hex_1 = require("./hex");
|
|
7
7
|
const float_1 = require("./float");
|
|
8
8
|
const data_reference_1 = require("./data_reference");
|
|
9
|
+
const hex_uint8_1 = require("./hex_uint8");
|
|
9
10
|
class FieldSymbol {
|
|
10
11
|
constructor(type) {
|
|
11
12
|
this.pointer = undefined;
|
|
@@ -49,7 +50,7 @@ class FieldSymbol {
|
|
|
49
50
|
}
|
|
50
51
|
get() {
|
|
51
52
|
if (this.casting) {
|
|
52
|
-
if (this.type instanceof hex_1.Hex) {
|
|
53
|
+
if (this.type instanceof hex_1.Hex || this.type instanceof hex_uint8_1.HexUInt8) {
|
|
53
54
|
const pt = this.pointer;
|
|
54
55
|
if (pt instanceof float_1.Float) {
|
|
55
56
|
const buf = Buffer.allocUnsafe(8);
|
package/build/src/types/hex.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare class Hex implements ICharacter {
|
|
|
13
13
|
qualifiedName?: string;
|
|
14
14
|
});
|
|
15
15
|
getQualifiedName(): string | undefined;
|
|
16
|
-
set(value: ICharacter | INumeric | string | number | Integer | Integer8 | Float): Hex;
|
|
16
|
+
set(value: ICharacter | INumeric | string | number | Integer | Integer8 | Float | Hex | XString): Hex;
|
|
17
17
|
getLength(): number;
|
|
18
18
|
clear(): void;
|
|
19
19
|
get(): string;
|
package/build/src/types/hex.js
CHANGED
|
@@ -6,6 +6,7 @@ const float_1 = require("./float");
|
|
|
6
6
|
const xstring_1 = require("./xstring");
|
|
7
7
|
const throw_error_1 = require("../throw_error");
|
|
8
8
|
const integer8_1 = require("./integer8");
|
|
9
|
+
const REGEXP = /^(?![A-F0-9])/;
|
|
9
10
|
class Hex {
|
|
10
11
|
constructor(input) {
|
|
11
12
|
this.length = input?.length ? input?.length : 1;
|
|
@@ -16,6 +17,7 @@ class Hex {
|
|
|
16
17
|
return this.qualifiedName;
|
|
17
18
|
}
|
|
18
19
|
set(value) {
|
|
20
|
+
const doubleLength = this.length * 2;
|
|
19
21
|
if (typeof value === "string") {
|
|
20
22
|
this.value = value;
|
|
21
23
|
}
|
|
@@ -23,57 +25,56 @@ class Hex {
|
|
|
23
25
|
const maxVal = Math.pow(2, this.length * 8);
|
|
24
26
|
if (value < 0) {
|
|
25
27
|
let hex = Math.round(value + 0x100000000).toString(16).toUpperCase();
|
|
26
|
-
if (hex.length >
|
|
27
|
-
hex = hex.substring(hex.length -
|
|
28
|
+
if (hex.length > doubleLength) {
|
|
29
|
+
hex = hex.substring(hex.length - doubleLength);
|
|
28
30
|
}
|
|
29
31
|
this.value = hex;
|
|
30
32
|
}
|
|
31
33
|
else if (value >= maxVal) {
|
|
32
34
|
const sub = value % maxVal;
|
|
33
|
-
this.value = Math.round(sub).toString(16);
|
|
35
|
+
this.value = Math.round(sub).toString(16).toUpperCase();
|
|
34
36
|
}
|
|
35
37
|
else {
|
|
36
|
-
this.value = Math.round(value).toString(16);
|
|
38
|
+
this.value = Math.round(value).toString(16).toUpperCase();
|
|
37
39
|
}
|
|
38
|
-
this.value = this.value.padStart(
|
|
40
|
+
this.value = this.value.padStart(doubleLength, "0");
|
|
39
41
|
}
|
|
40
42
|
else if (value instanceof integer8_1.Integer8) {
|
|
41
43
|
let hex = "";
|
|
42
44
|
if (value.get() < 0) {
|
|
43
45
|
hex = (value.get() + 0x10000000000000000n).toString(16).toUpperCase();
|
|
44
|
-
if (hex.length >
|
|
45
|
-
hex = hex.substring(hex.length -
|
|
46
|
+
if (hex.length > doubleLength) {
|
|
47
|
+
hex = hex.substring(hex.length - doubleLength);
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
else {
|
|
49
51
|
hex = value.get().toString(16).toUpperCase();
|
|
50
|
-
hex = hex.padStart(
|
|
52
|
+
hex = hex.padStart(doubleLength, "0");
|
|
51
53
|
}
|
|
52
|
-
this.set(hex);
|
|
54
|
+
return this.set(hex);
|
|
53
55
|
}
|
|
54
56
|
else {
|
|
55
|
-
|
|
57
|
+
const v = value.get();
|
|
56
58
|
if (value instanceof float_1.Float) {
|
|
57
|
-
|
|
58
|
-
this.set(v);
|
|
59
|
+
return this.set(value.getRaw());
|
|
59
60
|
}
|
|
60
61
|
else if (typeof v === "number") {
|
|
61
|
-
this.set(v);
|
|
62
|
+
return this.set(v);
|
|
62
63
|
}
|
|
63
64
|
else {
|
|
64
65
|
this.value = v;
|
|
65
|
-
if (this.value.match(
|
|
66
|
+
if (this.value.match(REGEXP)) {
|
|
66
67
|
this.value = "";
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
|
-
if (this.value.length >
|
|
71
|
-
this.value = this.value.substr(0,
|
|
71
|
+
if (this.value.length > doubleLength) {
|
|
72
|
+
this.value = this.value.substr(0, doubleLength);
|
|
72
73
|
}
|
|
73
|
-
if (this.value.length <
|
|
74
|
-
this.value = this.value.padEnd(
|
|
74
|
+
else if (this.value.length < doubleLength) {
|
|
75
|
+
this.value = this.value.padEnd(doubleLength, "0");
|
|
75
76
|
}
|
|
76
|
-
this.value = this.value.toUpperCase();
|
|
77
|
+
// this.value = this.value.toUpperCase(); // todo, for some reason abapNTLM needs this? investigate
|
|
77
78
|
return this;
|
|
78
79
|
}
|
|
79
80
|
getLength() {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Float } from "./float";
|
|
2
|
+
import { Integer } from "./integer";
|
|
3
|
+
import { XString } from "./xstring";
|
|
4
|
+
import { ICharacter } from "./_character";
|
|
5
|
+
import { INumeric } from "./_numeric";
|
|
6
|
+
import { Integer8 } from "./integer8";
|
|
7
|
+
import { Hex } from "./hex";
|
|
8
|
+
export declare class HexUInt8 implements ICharacter {
|
|
9
|
+
private value;
|
|
10
|
+
private readonly length;
|
|
11
|
+
private readonly qualifiedName;
|
|
12
|
+
constructor(input?: {
|
|
13
|
+
length?: number;
|
|
14
|
+
qualifiedName?: string;
|
|
15
|
+
});
|
|
16
|
+
getQualifiedName(): string | undefined;
|
|
17
|
+
setOffset(offset: number, value: number): void;
|
|
18
|
+
set(value: ICharacter | INumeric | string | number | Integer | Integer8 | Float | Hex | XString): HexUInt8;
|
|
19
|
+
getLength(): number;
|
|
20
|
+
clear(): void;
|
|
21
|
+
get(): string;
|
|
22
|
+
getOffset(input: {
|
|
23
|
+
offset?: number | INumeric | Hex | Integer8;
|
|
24
|
+
length?: number | INumeric | Hex | Integer8;
|
|
25
|
+
}): XString;
|
|
26
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HexUInt8 = void 0;
|
|
4
|
+
const _parse_1 = require("../operators/_parse");
|
|
5
|
+
const float_1 = require("./float");
|
|
6
|
+
const xstring_1 = require("./xstring");
|
|
7
|
+
const throw_error_1 = require("../throw_error");
|
|
8
|
+
const integer8_1 = require("./integer8");
|
|
9
|
+
const REGEXP = /^(?![A-F0-9])/;
|
|
10
|
+
class HexUInt8 {
|
|
11
|
+
constructor(input) {
|
|
12
|
+
this.length = input?.length ? input?.length : 1;
|
|
13
|
+
this.qualifiedName = input?.qualifiedName;
|
|
14
|
+
this.value = new Uint8Array(this.length);
|
|
15
|
+
}
|
|
16
|
+
getQualifiedName() {
|
|
17
|
+
return this.qualifiedName;
|
|
18
|
+
}
|
|
19
|
+
setOffset(offset, value) {
|
|
20
|
+
// caller must validate offset
|
|
21
|
+
this.value[offset] = value;
|
|
22
|
+
}
|
|
23
|
+
set(value) {
|
|
24
|
+
let hexString = "";
|
|
25
|
+
if (typeof value === "string") {
|
|
26
|
+
hexString = value;
|
|
27
|
+
if (hexString.length < this.length * 2) {
|
|
28
|
+
hexString = hexString.padEnd(this.length * 2, "0");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if (typeof value === "number") {
|
|
32
|
+
const maxVal = Math.pow(2, this.length * 8);
|
|
33
|
+
if (value < 0) {
|
|
34
|
+
hexString = Math.round(value + 0x100000000).toString(16).toUpperCase();
|
|
35
|
+
}
|
|
36
|
+
else if (value >= maxVal) {
|
|
37
|
+
const sub = value % maxVal;
|
|
38
|
+
hexString = Math.round(sub).toString(16).toUpperCase();
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
hexString = Math.round(value).toString(16).toUpperCase();
|
|
42
|
+
}
|
|
43
|
+
if (hexString.length > this.length * 2) {
|
|
44
|
+
hexString = hexString.substring(hexString.length - this.length * 2);
|
|
45
|
+
}
|
|
46
|
+
else if (hexString.length < this.length * 2) {
|
|
47
|
+
hexString = hexString.padStart(this.length * 2, "0");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else if (value instanceof integer8_1.Integer8) {
|
|
51
|
+
if (value.get() < 0) {
|
|
52
|
+
hexString = (value.get() + 0x10000000000000000n).toString(16).toUpperCase();
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
hexString = value.get().toString(16).toUpperCase();
|
|
56
|
+
}
|
|
57
|
+
if (hexString.length > this.length * 2) {
|
|
58
|
+
hexString = hexString.substring(hexString.length - this.length * 2);
|
|
59
|
+
}
|
|
60
|
+
else if (hexString.length < this.length * 2) {
|
|
61
|
+
hexString = hexString.padStart(this.length * 2, "0");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const v = value.get();
|
|
66
|
+
if (value instanceof float_1.Float) {
|
|
67
|
+
return this.set(value.getRaw());
|
|
68
|
+
}
|
|
69
|
+
else if (typeof v === "number") {
|
|
70
|
+
return this.set(v);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
hexString = v;
|
|
74
|
+
if (hexString.match(REGEXP)) {
|
|
75
|
+
hexString = "";
|
|
76
|
+
}
|
|
77
|
+
if (hexString.length < this.length * 2) {
|
|
78
|
+
hexString = hexString.padEnd(this.length * 2, "0");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (hexString.length > this.length * 2) {
|
|
83
|
+
hexString = hexString.substring(0, this.length * 2);
|
|
84
|
+
}
|
|
85
|
+
this.value = Uint8Array.from(Buffer.from(hexString, "hex"));
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
getLength() {
|
|
89
|
+
return this.length;
|
|
90
|
+
}
|
|
91
|
+
clear() {
|
|
92
|
+
// optimize? https://gist.github.com/chrisj/872283d15e1bb460a4766a52f50ebcf6
|
|
93
|
+
for (let i = 0; i < this.value.length; i++) {
|
|
94
|
+
this.value[i] = 0;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
get() {
|
|
98
|
+
return Buffer.from(this.value).toString("hex").toUpperCase();
|
|
99
|
+
}
|
|
100
|
+
getOffset(input) {
|
|
101
|
+
let offset = input?.offset;
|
|
102
|
+
if (offset) {
|
|
103
|
+
if (offset instanceof integer8_1.Integer8) {
|
|
104
|
+
offset = Number(offset.get());
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
offset = (0, _parse_1.parse)(offset);
|
|
108
|
+
}
|
|
109
|
+
if (offset > this.length
|
|
110
|
+
|| offset < 0) {
|
|
111
|
+
(0, throw_error_1.throwError)("CX_SY_RANGE_OUT_OF_BOUNDS");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
offset = 0;
|
|
116
|
+
}
|
|
117
|
+
let length = input?.length;
|
|
118
|
+
if (length) {
|
|
119
|
+
if (length instanceof integer8_1.Integer8) {
|
|
120
|
+
length = Number(length.get());
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
length = (0, _parse_1.parse)(length);
|
|
124
|
+
}
|
|
125
|
+
if (length > this.length
|
|
126
|
+
|| length < 0) {
|
|
127
|
+
(0, throw_error_1.throwError)("CX_SY_RANGE_OUT_OF_BOUNDS");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (offset !== undefined && length !== undefined) {
|
|
131
|
+
if (offset + length > this.length) {
|
|
132
|
+
(0, throw_error_1.throwError)("CX_SY_RANGE_OUT_OF_BOUNDS");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// not sure how this works: without copying, https://nodejs.org/api/buffer.html#static-method-bufferfromarraybuffer-byteoffset-length
|
|
136
|
+
/*
|
|
137
|
+
console.dir(offset);
|
|
138
|
+
console.dir(length);
|
|
139
|
+
console.dir(this.value.subarray(offset, length ? offset + length : undefined));
|
|
140
|
+
console.dir(Buffer.from(this.value.subarray(offset, length ? offset + length : undefined)));
|
|
141
|
+
*/
|
|
142
|
+
const str = Buffer.from(this.value.subarray(offset, length ? offset + length : undefined)).toString("hex")
|
|
143
|
+
.toUpperCase();
|
|
144
|
+
return new xstring_1.XString().set(str);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.HexUInt8 = HexUInt8;
|
|
148
|
+
//# sourceMappingURL=hex_uint8.js.map
|
package/build/src/types/index.js
CHANGED
|
@@ -22,6 +22,7 @@ __exportStar(require("./decfloat34"), exports);
|
|
|
22
22
|
__exportStar(require("./field_symbol"), exports);
|
|
23
23
|
__exportStar(require("./float"), exports);
|
|
24
24
|
__exportStar(require("./hex"), exports);
|
|
25
|
+
__exportStar(require("./hex_uint8"), exports);
|
|
25
26
|
__exportStar(require("./integer"), exports);
|
|
26
27
|
__exportStar(require("./integer8"), exports);
|
|
27
28
|
__exportStar(require("./numc"), exports);
|
|
@@ -6,6 +6,7 @@ const float_1 = require("./float");
|
|
|
6
6
|
const hex_1 = require("./hex");
|
|
7
7
|
const xstring_1 = require("./xstring");
|
|
8
8
|
const integer8_1 = require("./integer8");
|
|
9
|
+
const hex_uint8_1 = require("./hex_uint8");
|
|
9
10
|
exports.DIGITS = new RegExp(/^\s*-?\+?\d+\.?\d* *$/i);
|
|
10
11
|
exports.MAX_INTEGER = 2147483647;
|
|
11
12
|
exports.MIN_INTEGER = -2147483648;
|
|
@@ -56,10 +57,11 @@ class Integer {
|
|
|
56
57
|
else if (value instanceof float_1.Float) {
|
|
57
58
|
this.set(Math.round(value.getRaw()));
|
|
58
59
|
}
|
|
59
|
-
else if (value instanceof hex_1.Hex || value instanceof xstring_1.XString) {
|
|
60
|
+
else if (value instanceof hex_1.Hex || value instanceof xstring_1.XString || value instanceof hex_uint8_1.HexUInt8) {
|
|
60
61
|
let num = parseInt(value.get(), 16);
|
|
61
62
|
// handle two complement,
|
|
62
|
-
if (value instanceof hex_1.Hex
|
|
63
|
+
if ((value instanceof hex_1.Hex || value instanceof hex_uint8_1.HexUInt8)
|
|
64
|
+
&& value.getLength() >= 4) {
|
|
63
65
|
const maxVal = Math.pow(2, value.get().length / 2 * 8);
|
|
64
66
|
if (num > maxVal / 2 - 1) {
|
|
65
67
|
num = num - maxVal;
|
|
@@ -8,6 +8,7 @@ const xstring_1 = require("./xstring");
|
|
|
8
8
|
const integer_1 = require("./integer");
|
|
9
9
|
const get_bit_1 = require("../statements/get_bit");
|
|
10
10
|
const character_1 = require("./character");
|
|
11
|
+
const hex_uint8_1 = require("./hex_uint8");
|
|
11
12
|
const digits = new RegExp(/^\s*-?\+?\d+\.?\d* *$/i);
|
|
12
13
|
class Integer8 {
|
|
13
14
|
constructor(input) {
|
|
@@ -39,7 +40,7 @@ class Integer8 {
|
|
|
39
40
|
else if (value instanceof float_1.Float) {
|
|
40
41
|
this.set(Math.round(value.getRaw()));
|
|
41
42
|
}
|
|
42
|
-
else if (value instanceof hex_1.Hex || value instanceof xstring_1.XString) {
|
|
43
|
+
else if (value instanceof hex_1.Hex || value instanceof xstring_1.XString || value instanceof hex_uint8_1.HexUInt8) {
|
|
43
44
|
if (value.get().length === 16) {
|
|
44
45
|
const lv_bit = new character_1.Character();
|
|
45
46
|
(0, get_bit_1.getBit)(new integer_1.Integer().set(1), value, lv_bit);
|
|
@@ -17,11 +17,12 @@ class XString {
|
|
|
17
17
|
set(value) {
|
|
18
18
|
if (typeof value === "string") {
|
|
19
19
|
this.value = value;
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
if (this.value.length % 2 === 1) {
|
|
21
|
+
this.value = this.value + "0";
|
|
22
|
+
}
|
|
22
23
|
}
|
|
23
24
|
else if (typeof value === "number") {
|
|
24
|
-
this.value = Math.round(value).toString(16);
|
|
25
|
+
this.value = Math.round(value).toString(16).toUpperCase();
|
|
25
26
|
if (this.value.length % 2 === 1) {
|
|
26
27
|
this.value = "0" + this.value;
|
|
27
28
|
}
|
|
@@ -36,9 +37,10 @@ class XString {
|
|
|
36
37
|
this.set(value.getTrimEnd());
|
|
37
38
|
}
|
|
38
39
|
else if (typeof v === "number") {
|
|
39
|
-
this.value = v.toString(16);
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
this.value = v.toString(16).toUpperCase();
|
|
41
|
+
if (this.value.length % 2 === 1) {
|
|
42
|
+
this.value = "0" + this.value;
|
|
43
|
+
}
|
|
42
44
|
}
|
|
43
45
|
else {
|
|
44
46
|
this.set(v);
|