@cobol-ts/codec 0.0.0-stage → 0.0.2
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/README.md +87 -3
- package/dist/index.d.ts +3 -0
- package/dist/index.js +20 -0
- package/package.json +57 -3
package/README.md
CHANGED
|
@@ -1,3 +1,87 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
This
|
|
1
|
+
# `@cobol-ts/codec` — byte-backed COBOL primitive decoding
|
|
2
|
+
|
|
3
|
+
This replaces the old, unused generic JSON/string codec in `modules/utils/codec`.
|
|
4
|
+
The legacy **different** package `@cobol-ts/cobolcodec`, still used by the
|
|
5
|
+
older file readers/writers, is unchanged.
|
|
6
|
+
|
|
7
|
+
## Core invariant
|
|
8
|
+
|
|
9
|
+
`FragmentedByteCursor.bind(record, from, to)` consumes an **absolute**
|
|
10
|
+
exclusive-end range in the concatenation of `record.buffers`. `next()` reads
|
|
11
|
+
it directly, crossing arbitrarily many fragment boundaries. There is no
|
|
12
|
+
intermediate `Uint8Array`, `Buffer.concat`, `Array.from` of the record, or
|
|
13
|
+
allocation on `bind()` or `next()`. The cursor object belongs to the pooled
|
|
14
|
+
COBOL `recordState` and is rebound for each scalar read.
|
|
15
|
+
|
|
16
|
+
The `decode()` functions return only application values. The first version
|
|
17
|
+
of the **text** decoder builds the resulting JS string with incremental
|
|
18
|
+
concatenation of characters from the static CP037 lookup table (or ASCII).
|
|
19
|
+
This is deliberately uncomplicated, and does not trim trailing spaces. A
|
|
20
|
+
separate string may be produced for each accessor invocation; no decoded
|
|
21
|
+
string is cached on the row. Benchmark string construction before replacing
|
|
22
|
+
this baseline with chunked code units or a specialised decoder.
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import {FragmentedByteCursor,compileCobolFieldDecoder} from '@cobol-ts/codec';
|
|
28
|
+
|
|
29
|
+
const decoder = compileCobolFieldDecoder({picture:'S9(3)V99',clauses:[
|
|
30
|
+
{kind:'usage',usage:'COMP-3'}
|
|
31
|
+
]}, 3); // during opened-source setup
|
|
32
|
+
const cursor = new FragmentedByteCursor(); // once per pooled physical record
|
|
33
|
+
cursor.bind(physicalRecord, absoluteStartByte, absoluteEndByte);
|
|
34
|
+
const value = decoder.decode(cursor); // e.g. -123.45
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
From the COBOL projection factory, choose decoded details:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
const details = valueOrThrow(createCobolDecodedFixedDetails(layout));
|
|
41
|
+
// Or createCobolDecodedProjectionDetails(layout) when an ODO frame
|
|
42
|
+
// length is supplied independently.
|
|
43
|
+
const factory = createProjection(cobolParser, details, undefined, projection);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Projection-path compilation caches each selected elementary field's decoder
|
|
47
|
+
by stable compiled declaration identity. The runtime preserves existing lazy
|
|
48
|
+
geometry and array selection; only the final byte interpretation changes.
|
|
49
|
+
Original diagnostic fixtures retain `createCobolFixedDetails()` and
|
|
50
|
+
`createCobolProjectionDetails()` until migrated.
|
|
51
|
+
|
|
52
|
+
## Supported now
|
|
53
|
+
|
|
54
|
+
- IBM EBCDIC CP037 text and unsigned DISPLAY digits; ASCII as an explicit option.
|
|
55
|
+
- Single-character and fixed-width text, including embedded/trailing spaces.
|
|
56
|
+
- Unedited integer / implied-decimal DISPLAY, signed zone overpunch, optional
|
|
57
|
+
leading/trailing separate sign.
|
|
58
|
+
- COMP-3 / PACKED-DECIMAL (signed/unsigned, validated digits/sign nibble).
|
|
59
|
+
- Mainframe big-endian COMP / COMP-4 / BINARY signed/unsigned integers.
|
|
60
|
+
- Exact integers through `Number.MAX_SAFE_INTEGER` only. Binary uses number
|
|
61
|
+
arithmetic rather than creating a BigInt per scalar access; unsafe values
|
|
62
|
+
**throw** rather than losing bits silently.
|
|
63
|
+
- Implied decimal positions are returned as JavaScript `number`, with its
|
|
64
|
+
usual floating-point rounding. Exact scaled-decimal types remain future work.
|
|
65
|
+
|
|
66
|
+
Unsupported representations fail explicitly: edited pictures, PIC P scale,
|
|
67
|
+
NATIONAL/DBCS/UTF-8, IBM hexadecimal COMP-1/COMP-2 floating point, COMP-5,
|
|
68
|
+
non-CP037 EBCDIC dialects and decimal values beyond JS safe integer precision.
|
|
69
|
+
No claim of general Enterprise COBOL primitive-codec conformance is made.
|
|
70
|
+
|
|
71
|
+
## Validation and fair benchmarking
|
|
72
|
+
|
|
73
|
+
`src/cobol.decoder.spec.ts` covers fragmented fields, supported numeric
|
|
74
|
+
representations, invalid data, and cursor rebinding.
|
|
75
|
+
`cursor-loader-cobol/src/cobol.decoded.integration.spec.ts` exercises real
|
|
76
|
+
copybook compilation and the **actual** FB cursor with 3-byte physical reads,
|
|
77
|
+
plus nested OCCURS/REDEFINES, alignment and three-level ODO scalar decoding.
|
|
78
|
+
`cursor-loader-cobol/src/cobol.decoded.file.spec.ts` reads a genuine
|
|
79
|
+
filesystem-backed `.fb` file through Node file I/O.
|
|
80
|
+
|
|
81
|
+
For the one-million-record benchmark, compare exactly the same byte fixture,
|
|
82
|
+
projected fields and output consumption against JRecord. Separate disk-reading,
|
|
83
|
+
page-cache warm/cold, parsing-only and decoding workloads; record time,
|
|
84
|
+
bytes/sec, allocated bytes per record, GC events, CPU cycles and cache misses
|
|
85
|
+
where available. Do not assume JRecord materialises a whole object graph
|
|
86
|
+
without verifying its chosen API and usage pattern. Treat the L1-cache
|
|
87
|
+
hypothesis as an experiment, not a known outcome.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./src/fragmented.bytes"), exports);
|
|
18
|
+
__exportStar(require("./src/ebcdic.037"), exports);
|
|
19
|
+
__exportStar(require("./src/cobol.decoder"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobol-ts/codec",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"description": "COBOL primitive decoders over fragmented borrowed bytes",
|
|
4
|
+
"version": "0.0.2",
|
|
5
|
+
"main": "dist/index",
|
|
6
|
+
"types": "dist/index",
|
|
7
|
+
"browserslist": {
|
|
8
|
+
"development": [
|
|
9
|
+
"last 1 chrome version",
|
|
10
|
+
"last 1 firefox version",
|
|
11
|
+
"last 1 safari version"
|
|
12
|
+
],
|
|
13
|
+
"production": [
|
|
14
|
+
">0.2%",
|
|
15
|
+
"not dead",
|
|
16
|
+
"not op_mini all"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@cobol-ts/layout": "0.0.2"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^5.2.2",
|
|
24
|
+
"@testing-library/jest-dom": "^6.1.4",
|
|
25
|
+
"@types/jest": "^29.0.0",
|
|
26
|
+
"@types/node": "^14.0.0",
|
|
27
|
+
"jest": "^29.0.0",
|
|
28
|
+
"ts-jest": "^29.0.0"
|
|
29
|
+
},
|
|
30
|
+
"eslintConfig": {
|
|
31
|
+
"extends": [
|
|
32
|
+
"react-app",
|
|
33
|
+
"react-app/jest"
|
|
34
|
+
],
|
|
35
|
+
"overrides": [
|
|
36
|
+
{
|
|
37
|
+
"files": [
|
|
38
|
+
"**/*.stories.*"
|
|
39
|
+
],
|
|
40
|
+
"rules": {
|
|
41
|
+
"import/no-anonymous-default-export": "off"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist/index.js",
|
|
48
|
+
"dist/index.d.ts",
|
|
49
|
+
"dist/src/"
|
|
50
|
+
],
|
|
51
|
+
"keywords": [
|
|
52
|
+
"indexing"
|
|
53
|
+
],
|
|
54
|
+
"license": "MIT",
|
|
55
|
+
"repository": "git@github.com:intellimaintain/intellimaintain.git",
|
|
56
|
+
"scripts": {
|
|
57
|
+
"test": "jest --config jest.config.json --env node",
|
|
58
|
+
"test:watch": "npm run test -- --watch"
|
|
59
|
+
}
|
|
6
60
|
}
|