@cobol-ts/cursor-loader-protobuf 0.0.0-stage → 0.0.17
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 +94 -2
- package/dist/index.d.ts +18 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/src/protobuf.accumulator.d.ts +24 -0
- package/dist/src/protobuf.accumulator.file.d.ts +24 -0
- package/dist/src/protobuf.accumulator.file.js +164 -0
- package/dist/src/protobuf.accumulator.file.js.map +1 -0
- package/dist/src/protobuf.accumulator.js +110 -0
- package/dist/src/protobuf.accumulator.js.map +1 -0
- package/dist/src/protobuf.buffered.spec.d.ts +1 -0
- package/dist/src/protobuf.buffered.spec.js +97 -0
- package/dist/src/protobuf.buffered.spec.js.map +1 -0
- package/dist/src/protobuf.cursor.integration.spec.d.ts +1 -0
- package/dist/src/protobuf.cursor.integration.spec.js +116 -0
- package/dist/src/protobuf.cursor.integration.spec.js.map +1 -0
- package/dist/src/protobuf.envelope.d.ts +6 -0
- package/dist/src/protobuf.envelope.js +48 -0
- package/dist/src/protobuf.envelope.js.map +1 -0
- package/dist/src/protobuf.file.node.d.ts +16 -0
- package/dist/src/protobuf.file.node.js +43 -0
- package/dist/src/protobuf.file.node.js.map +1 -0
- package/dist/src/protobuf.file.spec.d.ts +1 -0
- package/dist/src/protobuf.file.spec.js +162 -0
- package/dist/src/protobuf.file.spec.js.map +1 -0
- package/dist/src/protobuf.mixed.codec.d.ts +7 -0
- package/dist/src/protobuf.mixed.codec.js +105 -0
- package/dist/src/protobuf.mixed.codec.js.map +1 -0
- package/dist/src/protobuf.number.file.d.ts +17 -0
- package/dist/src/protobuf.number.file.js +107 -0
- package/dist/src/protobuf.number.file.js.map +1 -0
- package/dist/src/protobuf.number.projection.d.ts +25 -0
- package/dist/src/protobuf.number.projection.js +310 -0
- package/dist/src/protobuf.number.projection.js.map +1 -0
- package/dist/src/protobuf.number.projection.spec.d.ts +1 -0
- package/dist/src/protobuf.number.projection.spec.js +111 -0
- package/dist/src/protobuf.number.projection.spec.js.map +1 -0
- package/dist/src/protobuf.number.rolling.d.ts +21 -0
- package/dist/src/protobuf.number.rolling.js +162 -0
- package/dist/src/protobuf.number.rolling.js.map +1 -0
- package/dist/src/protobuf.parser.d.ts +35 -0
- package/dist/src/protobuf.parser.js +142 -0
- package/dist/src/protobuf.parser.js.map +1 -0
- package/dist/src/protobuf.projection.support.d.ts +14 -0
- package/dist/src/protobuf.projection.support.js +75 -0
- package/dist/src/protobuf.projection.support.js.map +1 -0
- package/dist/src/protobuf.rdw.d.ts +15 -0
- package/dist/src/protobuf.rdw.js +107 -0
- package/dist/src/protobuf.rdw.js.map +1 -0
- package/dist/src/protobuf.registration.d.ts +3 -0
- package/dist/src/protobuf.registration.js +8 -0
- package/dist/src/protobuf.registration.js.map +1 -0
- package/dist/src/protobuf.reuse.spec.d.ts +1 -0
- package/dist/src/protobuf.reuse.spec.js +117 -0
- package/dist/src/protobuf.reuse.spec.js.map +1 -0
- package/dist/src/protobuf.rolling.layout.d.ts +13 -0
- package/dist/src/protobuf.rolling.layout.js +69 -0
- package/dist/src/protobuf.rolling.layout.js.map +1 -0
- package/dist/src/protobuf.rolling.spec.d.ts +1 -0
- package/dist/src/protobuf.rolling.spec.js +174 -0
- package/dist/src/protobuf.rolling.spec.js.map +1 -0
- package/dist/src/protobuf.roundtrip.spec.d.ts +1 -0
- package/dist/src/protobuf.roundtrip.spec.js +195 -0
- package/dist/src/protobuf.roundtrip.spec.js.map +1 -0
- package/dist/src/protobuf.safe-integer.d.ts +10 -0
- package/dist/src/protobuf.safe-integer.js +88 -0
- package/dist/src/protobuf.safe-integer.js.map +1 -0
- package/dist/src/protobuf.scalar.codec.d.ts +17 -0
- package/dist/src/protobuf.scalar.codec.js +276 -0
- package/dist/src/protobuf.scalar.codec.js.map +1 -0
- package/dist/src/protobuf.schema.d.ts +17 -0
- package/dist/src/protobuf.schema.first.parser.d.ts +10 -0
- package/dist/src/protobuf.schema.first.parser.js +23 -0
- package/dist/src/protobuf.schema.first.parser.js.map +1 -0
- package/dist/src/protobuf.schema.js +91 -0
- package/dist/src/protobuf.schema.js.map +1 -0
- package/package.json +68 -3
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareRollingNumberBackedProtobufProjection = prepareRollingNumberBackedProtobufProjection;
|
|
4
|
+
const protobuf_1 = require("@bufbuild/protobuf");
|
|
5
|
+
const ring_buffer_1 = require("@cobol-ts/ring-buffer");
|
|
6
|
+
const protobuf_rolling_layout_1 = require("./protobuf.rolling.layout");
|
|
7
|
+
/** Descriptor-driven adapter: native on disk, reusable RingBuffer values in the graph. */
|
|
8
|
+
function prepareRollingNumberBackedProtobufProjection(schema, graph) {
|
|
9
|
+
const layouts = (0, protobuf_rolling_layout_1.protobufRollingLayouts)(schema);
|
|
10
|
+
const descriptor = schema.descriptorSet.file.flatMap(f => f.messageType).find(m => m.name === 'Accumulator');
|
|
11
|
+
if (!descriptor)
|
|
12
|
+
throw new Error('Accumulator descriptor not found');
|
|
13
|
+
const indexes = new Map(graph.map((f, i) => [f.name, i]));
|
|
14
|
+
if (indexes.size !== graph.length)
|
|
15
|
+
throw new Error('Duplicate graph nodes');
|
|
16
|
+
const fields = descriptor.field;
|
|
17
|
+
if (fields.length !== graph.length + 1)
|
|
18
|
+
throw new Error('Protobuf accumulator schema does not match graph');
|
|
19
|
+
for (const field of fields) {
|
|
20
|
+
if (field.name === 'customerId') {
|
|
21
|
+
if (field.type !== 3)
|
|
22
|
+
throw new Error('Accumulator customerId must be protobuf int64');
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const idx = indexes.get(field.name);
|
|
26
|
+
if (idx === undefined)
|
|
27
|
+
throw new Error(`Stored accumulator node ${field.name} is not in the graph`);
|
|
28
|
+
const type = graph[idx].valueType;
|
|
29
|
+
const layout = layouts.get(field.name);
|
|
30
|
+
if (type.kind === 'rolling-window') {
|
|
31
|
+
if (!layout || type.size !== layout.size || type.periodicity !== layout.periodicity)
|
|
32
|
+
throw new Error(`Protobuf rolling-window layout mismatch for ${field.name}`);
|
|
33
|
+
if (type.element.semanticType !== layout.element.semanticType ||
|
|
34
|
+
(type.element.javascriptType !== 'number' && type.element.javascriptType !== layout.element.javascriptType))
|
|
35
|
+
throw new Error(`Protobuf rolling-window element type mismatch for ${field.name}`);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
if (layout)
|
|
39
|
+
throw new Error(`Expected scalar accumulator node ${field.name}`);
|
|
40
|
+
const kind = type.semanticType;
|
|
41
|
+
const compatible = (kind === 'integer' || kind === 'fixed2' || kind === 'fixed3') ? field.type === 3 :
|
|
42
|
+
kind === 'unsignedInteger' ? field.type === 4 : kind === 'float' ? field.type === 1 :
|
|
43
|
+
kind === 'boolean' ? field.type === 8 : kind === 'string' ? field.type === 9 : false;
|
|
44
|
+
if (!compatible)
|
|
45
|
+
throw new Error(`Accumulator schema type incompatible with graph node ${field.name}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const typeNames = new Map(fields.filter(f => f.type === 11)
|
|
49
|
+
.map(f => [f.name, (f.typeName ?? '').replace(/^\./, '')]));
|
|
50
|
+
const INT_MIN = -(1n << 63n), INT_MAX = (1n << 63n) - 1n, UINT_MAX = (1n << 64n) - 1n;
|
|
51
|
+
function toProtobufScalar(value, type, name) {
|
|
52
|
+
switch (type.javascriptType) {
|
|
53
|
+
case 'number': {
|
|
54
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
55
|
+
throw new Error(`Expected finite number for ${name}`);
|
|
56
|
+
if (type.semanticType === 'float')
|
|
57
|
+
return value;
|
|
58
|
+
if (!Number.isSafeInteger(value))
|
|
59
|
+
throw new Error(`Invalid int64 number for ${name}`);
|
|
60
|
+
const result = BigInt(value);
|
|
61
|
+
if (result < INT_MIN || result > INT_MAX || (type.semanticType === 'unsignedInteger' && result < 0n))
|
|
62
|
+
throw new Error(`Integer out of range for ${name}`);
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
case 'bigint': {
|
|
66
|
+
if (typeof value !== 'bigint' || value < (type.semanticType === 'unsignedInteger' ? 0n : INT_MIN) ||
|
|
67
|
+
value > (type.semanticType === 'unsignedInteger' ? UINT_MAX : INT_MAX))
|
|
68
|
+
throw new Error(`Invalid bigint for ${name}`);
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
case 'string':
|
|
72
|
+
if (typeof value !== 'string')
|
|
73
|
+
throw new Error(`Expected string for ${name}`);
|
|
74
|
+
return value;
|
|
75
|
+
case 'boolean':
|
|
76
|
+
if (typeof value !== 'boolean')
|
|
77
|
+
throw new Error(`Expected boolean for ${name}`);
|
|
78
|
+
return value;
|
|
79
|
+
default: throw new Error(`Unsupported representation for ${name}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function fromProtobufScalar(value, type, name) {
|
|
83
|
+
if (type.javascriptType === 'number' && type.semanticType !== 'float') {
|
|
84
|
+
if (typeof value !== 'bigint' || value > BigInt(Number.MAX_SAFE_INTEGER) || value < BigInt(Number.MIN_SAFE_INTEGER))
|
|
85
|
+
throw new Error(`Accumulator integer exceeds JavaScript safe-integer range for ${name}`);
|
|
86
|
+
return Number(value);
|
|
87
|
+
}
|
|
88
|
+
if (typeof value !== type.javascriptType)
|
|
89
|
+
throw new Error(`Incorrect Protobuf scalar type for ${name}`);
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
function encodeRecord(row) {
|
|
93
|
+
if (row.values.length !== graph.length)
|
|
94
|
+
throw new Error('Incorrect graph value array length');
|
|
95
|
+
if (typeof row.customerId !== 'bigint' || row.customerId < INT_MIN || row.customerId > INT_MAX)
|
|
96
|
+
throw new Error('Accumulator customerId is outside int64 range');
|
|
97
|
+
const message = (0, protobuf_1.create)(schema.message);
|
|
98
|
+
message.customerId = row.customerId;
|
|
99
|
+
for (let i = 0; i < graph.length; i++) {
|
|
100
|
+
const { name, valueType } = graph[i], value = row.values[i];
|
|
101
|
+
if (valueType.kind === 'rolling-window') {
|
|
102
|
+
if (!value || typeof value !== 'object' || !('values' in value) || value.size !== valueType.size)
|
|
103
|
+
throw new Error(`Invalid rolling-window value for ${name}`);
|
|
104
|
+
(0, ring_buffer_1.validateRingBuffer)(value);
|
|
105
|
+
const fill = (0, protobuf_rolling_layout_1.emptyProtobufScalar)(valueType.element);
|
|
106
|
+
message[name] = { $typeName: typeNames.get(name), count: value.count, excluded: value.excluded,
|
|
107
|
+
hasExpired: value.hasExpired, values: value.values.map(v => v === undefined ? fill :
|
|
108
|
+
toProtobufScalar(v, valueType.element, name)) };
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
if (value === undefined || typeof value === 'object')
|
|
112
|
+
throw new Error(`Missing scalar value for ${name}`);
|
|
113
|
+
message[name] = toProtobufScalar(value, valueType, name);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return (0, protobuf_1.toBinary)(schema.message, message);
|
|
117
|
+
}
|
|
118
|
+
function decodeInto(bytes, target) {
|
|
119
|
+
if (target.values.length !== graph.length)
|
|
120
|
+
throw new Error('Incorrect graph value array length');
|
|
121
|
+
const message = (0, protobuf_1.fromBinary)(schema.message, bytes);
|
|
122
|
+
target.customerId = message.customerId;
|
|
123
|
+
for (let i = 0; i < graph.length; i++) {
|
|
124
|
+
const { name, valueType } = graph[i];
|
|
125
|
+
const raw = message[name];
|
|
126
|
+
if (valueType.kind === 'rolling-window') {
|
|
127
|
+
if (!raw || typeof raw !== 'object')
|
|
128
|
+
throw new Error(`Missing rolling-window state ${name}`);
|
|
129
|
+
const wire = raw;
|
|
130
|
+
if (!Array.isArray(wire.values) || wire.values.length !== valueType.size + 1)
|
|
131
|
+
throw new Error(`Invalid rolling-window physical capacity ${name}`);
|
|
132
|
+
const previous = target.values[i];
|
|
133
|
+
const ring = previous && typeof previous === 'object' && 'values' in previous && previous.size === valueType.size
|
|
134
|
+
? previous : (0, ring_buffer_1.createRingBuffer)(valueType.size);
|
|
135
|
+
ring.count = wire.count;
|
|
136
|
+
ring.excluded = wire.excluded;
|
|
137
|
+
ring.hasExpired = wire.hasExpired;
|
|
138
|
+
for (let k = 0; k < ring.values.length; k++) {
|
|
139
|
+
const logical = (k - ring.excluded - 1 + ring.values.length) % ring.values.length;
|
|
140
|
+
const present = logical < ring.count || (ring.hasExpired && k === ring.excluded);
|
|
141
|
+
ring.values[k] = present ? fromProtobufScalar(wire.values[k], valueType.element, name) : undefined;
|
|
142
|
+
}
|
|
143
|
+
(0, ring_buffer_1.validateRingBuffer)(ring);
|
|
144
|
+
target.values[i] = ring;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
if (raw === undefined)
|
|
148
|
+
throw new Error(`Missing accumulator field ${name}`);
|
|
149
|
+
target.values[i] = fromProtobufScalar(raw, valueType, name);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return { decodeInto, encodedLength: (row) => encodeRecord(row).length,
|
|
154
|
+
encodeInto(row, out, offset) {
|
|
155
|
+
const bytes = encodeRecord(row);
|
|
156
|
+
if (!Number.isSafeInteger(offset) || offset < 0 || bytes.length > out.length - offset)
|
|
157
|
+
throw new Error('Accumulator output buffer too small');
|
|
158
|
+
out.set(bytes, offset);
|
|
159
|
+
return bytes.length;
|
|
160
|
+
} };
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=protobuf.number.rolling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protobuf.number.rolling.js","sourceRoot":"","sources":["../../src/protobuf.number.rolling.ts"],"names":[],"mappings":";;AAYA,oGA8HC;AA1ID,iDAA2E;AAC3E,uDAA0F;AAG1F,uEAAqF;AAOrF,0FAA0F;AAC1F,SAAgB,4CAA4C,CAAC,MAAwB,EACjF,KAA6C;IAC7C,MAAM,OAAO,GAAC,IAAA,gDAAsB,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K,CAAC,MAAM,GAAC,GAAG,CAAC,MAAM,GAAC,MAAM;gBACtE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;YAC3D,GAAG,CAAC,GAAG,CAAC,KAAK,EAAC,MAAM,CAAC,CAAC;YAAA,OAAO,KAAK,CAAC,MAAM,CAAC;QAC9C,CAAC,EAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type DescMessage } from '@bufbuild/protobuf';
|
|
2
|
+
import type { Parser, ParserPhysicalRecordContent, PhysicalRecordContext, ProjectionRecordState } from '@cobol-ts/cursor-loader-types';
|
|
3
|
+
import { bytesToDebugString } from '@cobol-ts/cursor-loader-types';
|
|
4
|
+
export interface ProtobufDetails {
|
|
5
|
+
readonly schema: DescMessage;
|
|
6
|
+
/** Maximum complete physical record size, including the four-byte header. */
|
|
7
|
+
readonly maxRecordBytes: number;
|
|
8
|
+
/** Return physical bytes for the pooled accumulator decoder. */
|
|
9
|
+
readonly rawPayload?: boolean;
|
|
10
|
+
/** Private cursor-owned assembly storage for fragmented raw accumulator payloads. */
|
|
11
|
+
scratch?: Uint8Array;
|
|
12
|
+
}
|
|
13
|
+
export interface ProtobufRecordState extends ProjectionRecordState {
|
|
14
|
+
}
|
|
15
|
+
export declare function createProtobufRecordState(): ProtobufRecordState;
|
|
16
|
+
export type ProtobufParser = Parser<unknown, ProtobufDetails, ProtobufDetails, ProtobufRecordState, readonly (string | number)[]>;
|
|
17
|
+
export declare const protobufParser: {
|
|
18
|
+
toDebugString: typeof bytesToDebugString;
|
|
19
|
+
parse: typeof parse;
|
|
20
|
+
parseBuffered: typeof parseBuffered;
|
|
21
|
+
compileProjectionPath: (_details: unknown, _context: PhysicalRecordContext | undefined, path: readonly (string | number)[]) => import("./protobuf.projection.support").ProtobufProjectionPath;
|
|
22
|
+
integer(representation: unknown, _details: unknown, path: import("./protobuf.projection.support").ProtobufProjectionPath, ...indices: number[]): number;
|
|
23
|
+
float(representation: unknown, _details: unknown, path: import("./protobuf.projection.support").ProtobufProjectionPath, ...indices: number[]): number;
|
|
24
|
+
character(representation: unknown, _details: unknown, path: import("./protobuf.projection.support").ProtobufProjectionPath, ...indices: number[]): string;
|
|
25
|
+
string(representation: unknown, _details: unknown, path: import("./protobuf.projection.support").ProtobufProjectionPath, ...indices: number[]): string;
|
|
26
|
+
object(representation: unknown, _details: unknown, path: import("./protobuf.projection.support").ProtobufProjectionPath): unknown;
|
|
27
|
+
array(representation: unknown, _details: unknown, path: import("./protobuf.projection.support").ProtobufProjectionPath): import("@cobol-ts/arrays").ProjectedArraySource<unknown>;
|
|
28
|
+
};
|
|
29
|
+
declare function parse(record: ParserPhysicalRecordContent<ProtobufRecordState>, details: ProtobufDetails): Promise<{} | null>;
|
|
30
|
+
/** Reuses the generic cursor's buffers and lease lifecycle, as the COBOL parser does. */
|
|
31
|
+
declare function parseBuffered(record: ParserPhysicalRecordContent<ProtobufRecordState>, details: ProtobufDetails): unknown | {
|
|
32
|
+
errors: string[];
|
|
33
|
+
} | undefined;
|
|
34
|
+
export declare function protobufDetails(schema: DescMessage, maxRecordBytes?: number): ProtobufDetails;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.protobufParser = void 0;
|
|
4
|
+
exports.createProtobufRecordState = createProtobufRecordState;
|
|
5
|
+
exports.protobufDetails = protobufDetails;
|
|
6
|
+
const protobuf_1 = require("@bufbuild/protobuf");
|
|
7
|
+
const cursor_loader_types_1 = require("@cobol-ts/cursor-loader-types");
|
|
8
|
+
const protobuf_projection_support_1 = require("./protobuf.projection.support");
|
|
9
|
+
/** COBOL-compatible RDW: big-endian 16-bit length INCLUDING the four header bytes; two zero control bytes. */
|
|
10
|
+
const HEADER_BYTES = 4;
|
|
11
|
+
const EMPTY_BYTES = new Uint8Array(0);
|
|
12
|
+
function createProtobufRecordState() {
|
|
13
|
+
return { projectionViews: new Map() };
|
|
14
|
+
}
|
|
15
|
+
exports.protobufParser = {
|
|
16
|
+
...protobuf_projection_support_1.protobufProjectionSupport,
|
|
17
|
+
toDebugString: cursor_loader_types_1.bytesToDebugString,
|
|
18
|
+
parse,
|
|
19
|
+
parseBuffered
|
|
20
|
+
};
|
|
21
|
+
async function parse(record, details) {
|
|
22
|
+
let result = parseBuffered(record, details);
|
|
23
|
+
while (result === undefined) {
|
|
24
|
+
await record.readMore();
|
|
25
|
+
result = parseBuffered(record, details);
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
/** Reuses the generic cursor's buffers and lease lifecycle, as the COBOL parser does. */
|
|
30
|
+
function parseBuffered(record, details) {
|
|
31
|
+
const start = record.startByte;
|
|
32
|
+
if (record.lastValidByte - start < HEADER_BYTES) {
|
|
33
|
+
if (!record.fileFinished)
|
|
34
|
+
return undefined;
|
|
35
|
+
if (record.lastValidByte === start) {
|
|
36
|
+
record.endByte = start; // Generic cursor owns EOF detection.
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
record.endByte = record.lastValidByte;
|
|
40
|
+
return { errors: [`Truncated Protobuf record header: expected 4 bytes, got ${record.lastValidByte - start}`] };
|
|
41
|
+
}
|
|
42
|
+
const header = readHeader(record, start);
|
|
43
|
+
if (header.control1 !== 0 || header.control2 !== 0) {
|
|
44
|
+
record.endByte = start + HEADER_BYTES;
|
|
45
|
+
return { errors: [`Unsupported Protobuf RDW control bytes ${header.control1}, ${header.control2}`] };
|
|
46
|
+
}
|
|
47
|
+
const size = header.size;
|
|
48
|
+
if (size < HEADER_BYTES) {
|
|
49
|
+
record.endByte = start + HEADER_BYTES;
|
|
50
|
+
return { errors: [`Invalid Protobuf record length ${size}: must include four header bytes`] };
|
|
51
|
+
}
|
|
52
|
+
if (size > details.maxRecordBytes) {
|
|
53
|
+
record.endByte = start + HEADER_BYTES;
|
|
54
|
+
return { errors: [`Protobuf record length ${size} exceeds configured maximum ${details.maxRecordBytes}`] };
|
|
55
|
+
}
|
|
56
|
+
const end = start + size;
|
|
57
|
+
if (record.lastValidByte < end) {
|
|
58
|
+
if (!record.fileFinished)
|
|
59
|
+
return undefined;
|
|
60
|
+
record.endByte = record.lastValidByte;
|
|
61
|
+
return { errors: [`Truncated Protobuf record: expected ${size} bytes, got ${record.lastValidByte - start}`] };
|
|
62
|
+
}
|
|
63
|
+
record.endByte = end;
|
|
64
|
+
try {
|
|
65
|
+
const payload = payloadBytes(record, start + HEADER_BYTES, end, details);
|
|
66
|
+
return { data: details.rawPayload ? payload : (0, protobuf_1.fromBinary)(details.schema, payload) };
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
return { errors: [`${record.source}: record ${record.recordNumber}: Protobuf decode error: ${error instanceof Error ? error.message : String(error)}`] };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function readHeader(record, start) {
|
|
73
|
+
let offset = 0, count = 0, size = 0, control1 = 0, control2 = 0;
|
|
74
|
+
for (const buffer of record.buffers) {
|
|
75
|
+
const end = offset + buffer.length;
|
|
76
|
+
if (end <= start) {
|
|
77
|
+
offset = end;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
for (let i = Math.max(0, start - offset); i < buffer.length && count < 4; i++) {
|
|
81
|
+
const byte = buffer[i];
|
|
82
|
+
if (count < 2)
|
|
83
|
+
size = size * 256 + byte;
|
|
84
|
+
else if (count === 2)
|
|
85
|
+
control1 = byte;
|
|
86
|
+
else
|
|
87
|
+
control2 = byte;
|
|
88
|
+
count++;
|
|
89
|
+
}
|
|
90
|
+
if (count === 4)
|
|
91
|
+
return { size, control1, control2 };
|
|
92
|
+
offset = end;
|
|
93
|
+
}
|
|
94
|
+
throw new Error('Protobuf RDW outside available buffers');
|
|
95
|
+
}
|
|
96
|
+
/** Avoid payload copies for single-buffer records; copy only when fragmented. */
|
|
97
|
+
function payloadBytes(record, start, end, details) {
|
|
98
|
+
if (start === end)
|
|
99
|
+
return EMPTY_BYTES;
|
|
100
|
+
let offset = 0;
|
|
101
|
+
let assembled;
|
|
102
|
+
let position = 0;
|
|
103
|
+
for (const buffer of record.buffers) {
|
|
104
|
+
const bufferEnd = offset + buffer.length;
|
|
105
|
+
if (bufferEnd <= start) {
|
|
106
|
+
offset = bufferEnd;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (offset >= end)
|
|
110
|
+
break;
|
|
111
|
+
const from = Math.max(0, start - offset);
|
|
112
|
+
const to = Math.min(buffer.length, end - offset);
|
|
113
|
+
if (from < to) {
|
|
114
|
+
if (assembled === undefined && offset + to >= end && position === 0)
|
|
115
|
+
return buffer.subarray(from, to);
|
|
116
|
+
if (assembled === undefined) {
|
|
117
|
+
// Raw accumulator bytes are decoded before the cursor advances. Reuse the
|
|
118
|
+
// same scratch allocation for every fragmented record on this cursor.
|
|
119
|
+
if (details.rawPayload) {
|
|
120
|
+
if (details.scratch === undefined || details.scratch.length < end - start)
|
|
121
|
+
details.scratch = new Uint8Array(details.maxRecordBytes - HEADER_BYTES);
|
|
122
|
+
assembled = details.scratch;
|
|
123
|
+
}
|
|
124
|
+
else
|
|
125
|
+
assembled = new Uint8Array(end - start);
|
|
126
|
+
}
|
|
127
|
+
for (let i = from; i < to; i++)
|
|
128
|
+
assembled[position++] = buffer[i];
|
|
129
|
+
}
|
|
130
|
+
offset = bufferEnd;
|
|
131
|
+
}
|
|
132
|
+
if (position !== end - start)
|
|
133
|
+
throw new Error('Protobuf payload outside available buffers');
|
|
134
|
+
// The reusable scratch may exceed this record. Return only the active payload.
|
|
135
|
+
return assembled.length === end - start ? assembled : assembled.subarray(0, end - start);
|
|
136
|
+
}
|
|
137
|
+
function protobufDetails(schema, maxRecordBytes = 65535) {
|
|
138
|
+
if (!Number.isSafeInteger(maxRecordBytes) || maxRecordBytes < 4 || maxRecordBytes > 65535)
|
|
139
|
+
throw new Error('Protobuf maximum record size must be an integer from 4 to 65535');
|
|
140
|
+
return { schema, maxRecordBytes };
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=protobuf.parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protobuf.parser.js","sourceRoot":"","sources":["../../src/protobuf.parser.ts"],"names":[],"mappings":";;;AAqBA,8DAEC;AA+GD,0CAIC;AA1ID,iDAAgE;AAEhE,uEAAiE;AACjE,+EAAwE;AAExE,8GAA8G;AAC9G,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AActC,SAAgB,yBAAyB;IACrC,OAAO,EAAC,eAAe,EAAC,IAAI,GAAG,EAAE,EAAC,CAAC;AACvC,CAAC;AAIY,QAAA,cAAc,GAAG;IAC1B,GAAG,uDAAyB;IAC5B,aAAa,EAAE,wCAAkB;IACjC,KAAK;IACL,aAAa;CACS,CAAC;AAE3B,KAAK,UAAU,KAAK,CAAC,MAAuD,EAAE,OAAuB;IACjG,IAAI,MAAM,GAAC,aAAa,CAAC,MAAM,EAAC,OAAO,CAAC,CAAC;IACzC,OAAM,MAAM,KAAG,SAAS,EAAE,CAAC;QACvB,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAC;QACxB,MAAM,GAAC,aAAa,CAAC,MAAM,EAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,yFAAyF;AACzF,SAAS,aAAa,CAAC,MAAuD,EAAC,OAAuB;IAClG,MAAM,KAAK,GAAC,MAAM,CAAC,SAAS,CAAC;IAC7B,IAAG,MAAM,CAAC,aAAa,GAAC,KAAK,GAAC,YAAY,EAAE,CAAC;QACzC,IAAG,CAAC,MAAM,CAAC,YAAY;YAAE,OAAO,SAAS,CAAC;QAC1C,IAAG,MAAM,CAAC,aAAa,KAAG,KAAK,EAAE,CAAC;YAC9B,MAAM,CAAC,OAAO,GAAC,KAAK,CAAC,CAAC,qCAAqC;YAC3D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AAC,CAAC,IAAE,cAAc,GAAC,KAAK;QAC5E,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;IACvF,OAAO,EAAC,MAAM,EAAC,cAAc,EAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ProjectedArraySource } from '@cobol-ts/arrays';
|
|
2
|
+
import type { PhysicalRecordContext } from '@cobol-ts/cursor-loader-types';
|
|
3
|
+
export type ProtobufProjectionPath = readonly (string | number)[];
|
|
4
|
+
declare function compileProjectionPath(_details: unknown, _context: PhysicalRecordContext | undefined, path: readonly (string | number)[]): ProtobufProjectionPath;
|
|
5
|
+
export declare const protobufProjectionSupport: {
|
|
6
|
+
compileProjectionPath: typeof compileProjectionPath;
|
|
7
|
+
integer(representation: unknown, _details: unknown, path: ProtobufProjectionPath, ...indices: number[]): number;
|
|
8
|
+
float(representation: unknown, _details: unknown, path: ProtobufProjectionPath, ...indices: number[]): number;
|
|
9
|
+
character(representation: unknown, _details: unknown, path: ProtobufProjectionPath, ...indices: number[]): string;
|
|
10
|
+
string(representation: unknown, _details: unknown, path: ProtobufProjectionPath, ...indices: number[]): string;
|
|
11
|
+
object(representation: unknown, _details: unknown, path: ProtobufProjectionPath): unknown;
|
|
12
|
+
array(representation: unknown, _details: unknown, path: ProtobufProjectionPath): ProjectedArraySource<unknown>;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.protobufProjectionSupport = void 0;
|
|
4
|
+
function compileProjectionPath(_details, _context, path) {
|
|
5
|
+
return path;
|
|
6
|
+
}
|
|
7
|
+
function select(representation, path, indices = []) {
|
|
8
|
+
let value = (representation !== null && typeof representation === 'object' && 'data' in representation)
|
|
9
|
+
? representation.data : representation;
|
|
10
|
+
let index = 0;
|
|
11
|
+
for (const part of path) {
|
|
12
|
+
if (value === null || value === undefined)
|
|
13
|
+
throw new Error(`Missing Protobuf field at ${path.join('.')}`);
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
const position = typeof part === 'number' ? part : indices[index++];
|
|
16
|
+
if (position === undefined || !Number.isSafeInteger(position) || position < 0 || position >= value.length)
|
|
17
|
+
throw new Error(`Invalid Protobuf array index for ${path.join('.')}`);
|
|
18
|
+
value = value[position];
|
|
19
|
+
if (typeof part === 'number')
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (typeof value !== 'object')
|
|
23
|
+
throw new Error(`Protobuf field is not an object at ${path.join('.')}`);
|
|
24
|
+
value = value[String(part)];
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
function numeric(value, path) {
|
|
29
|
+
if (typeof value === 'number')
|
|
30
|
+
return value;
|
|
31
|
+
if (typeof value === 'bigint') {
|
|
32
|
+
const n = Number(value);
|
|
33
|
+
if (Number.isSafeInteger(n))
|
|
34
|
+
return n;
|
|
35
|
+
throw new Error(`Protobuf integer exceeds JavaScript safe integer range at ${path.join('.')}`);
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`Expected Protobuf number at ${path.join('.')}`);
|
|
38
|
+
}
|
|
39
|
+
exports.protobufProjectionSupport = {
|
|
40
|
+
compileProjectionPath,
|
|
41
|
+
integer(representation, _details, path, ...indices) {
|
|
42
|
+
const result = numeric(select(representation, path, indices), path);
|
|
43
|
+
if (!Number.isSafeInteger(result))
|
|
44
|
+
throw new Error(`Expected safe Protobuf integer at ${path.join('.')}`);
|
|
45
|
+
return result;
|
|
46
|
+
},
|
|
47
|
+
float(representation, _details, path, ...indices) {
|
|
48
|
+
return numeric(select(representation, path, indices), path);
|
|
49
|
+
},
|
|
50
|
+
character(representation, _details, path, ...indices) {
|
|
51
|
+
const result = select(representation, path, indices);
|
|
52
|
+
if (typeof result !== 'string' || result.length !== 1)
|
|
53
|
+
throw new Error(`Expected Protobuf character at ${path.join('.')}`);
|
|
54
|
+
return result;
|
|
55
|
+
},
|
|
56
|
+
string(representation, _details, path, ...indices) {
|
|
57
|
+
const result = select(representation, path, indices);
|
|
58
|
+
if (typeof result !== 'string')
|
|
59
|
+
throw new Error(`Expected Protobuf string at ${path.join('.')}`);
|
|
60
|
+
return result;
|
|
61
|
+
},
|
|
62
|
+
object(representation, _details, path) {
|
|
63
|
+
const result = select(representation, path);
|
|
64
|
+
if (result === null || typeof result !== 'object' || Array.isArray(result))
|
|
65
|
+
throw new Error(`Expected Protobuf object at ${path.join('.')}`);
|
|
66
|
+
return result;
|
|
67
|
+
},
|
|
68
|
+
array(representation, _details, path) {
|
|
69
|
+
const result = select(representation, path);
|
|
70
|
+
if (!Array.isArray(result))
|
|
71
|
+
throw new Error(`Expected Protobuf array at ${path.join('.')}`);
|
|
72
|
+
return { length: () => result.length, element: (index) => result[index] };
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=protobuf.projection.support.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protobuf.projection.support.js","sourceRoot":"","sources":["../../src/protobuf.projection.support.ts"],"names":[],"mappings":";;;AAKA,SAAS,qBAAqB,CAAC,QAAgB,EAAC,QAAwC,EAAC,IAA+B;IACpH,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,MAAM,CAAC,cAAsB,EAAC,IAA2B,EAAC,UAA0B,EAAE;IAC3F,IAAI,KAAK,GAAC,CAAC,cAAc,KAAK,IAAI,IAAI,OAAO,cAAc,KAAK,QAAQ,IAAI,MAAM,IAAI,cAAc,CAAC;QACjG,CAAC,CAAE,cAAiC,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC;IAC/D,IAAI,KAAK,GAAC,CAAC,CAAC;IACZ,KAAI,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QACrB,IAAG,KAAK,KAAG,IAAI,IAAE,KAAK,KAAG,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,6BAA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IAAI,KAAK,CAAC,+BAA+B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC9F,OAAO,MAAM,CAAC;IAClB,CAAC;IACD,MAAM,CAAC,cAAsB,EAAC,QAAgB,EAAC,IAA2B;QACtE,MAAM,MAAM,GAAC,MAAM,CAAC,cAAc,EAAC,IAAI,CAAC,CAAC;QACzC,IAAG,MAAM,KAAG,IAAI,IAAE,OAAO,MAAM,KAAG,QAAQ,IAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACpI,OAAO,MAAM,CAAC;IAClB,CAAC;IACD,KAAK,CAAC,cAAsB,EAAC,QAAgB,EAAC,IAA2B;QACrE,MAAM,MAAM,GAAC,MAAM,CAAC,cAAc,EAAC,IAAI,CAAC,CAAC;QACzC,IAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC3F,OAAO,EAAC,MAAM,EAAC,GAAE,EAAE,CAAA,MAAM,CAAC,MAAM,EAAC,OAAO,EAAC,CAAC,KAAY,EAAC,EAAE,CAAA,MAAM,CAAC,KAAK,CAAC,EAAC,CAAC;IAC5E,CAAC;CACgE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { FileHandle } from 'node:fs/promises';
|
|
2
|
+
/** Same RDW convention as the COBOL variable-record cursor. */
|
|
3
|
+
export declare function rdwFrame(bytes: Uint8Array): Uint8Array;
|
|
4
|
+
/** Read exactly one record; a clean EOF at the next RDW returns undefined. */
|
|
5
|
+
export declare function readRdw(handle: FileHandle): Promise<Uint8Array | undefined>;
|
|
6
|
+
export declare function writeRdw(handle: FileHandle, bytes: Uint8Array): Promise<void>;
|
|
7
|
+
/** Hot-path writer: one reusable buffer holds many complete RDW records. */
|
|
8
|
+
export declare function createBufferedRdwWriter(handle: FileHandle, capacity?: number): {
|
|
9
|
+
appendRecord: (bytes: Uint8Array) => boolean;
|
|
10
|
+
appendEncoded: <T>(message: T, codec: {
|
|
11
|
+
encodedLength(message: T): number;
|
|
12
|
+
encodeInto(message: T, out: Uint8Array, offset: number, knownLength?: number): number;
|
|
13
|
+
}) => boolean;
|
|
14
|
+
flush: () => Promise<void>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rdwFrame = rdwFrame;
|
|
4
|
+
exports.readRdw = readRdw;
|
|
5
|
+
exports.writeRdw = writeRdw;
|
|
6
|
+
exports.createBufferedRdwWriter = createBufferedRdwWriter;
|
|
7
|
+
const HEADER = 4;
|
|
8
|
+
const MAX_RECORD = 65535;
|
|
9
|
+
/** Same RDW convention as the COBOL variable-record cursor. */
|
|
10
|
+
function rdwFrame(bytes) {
|
|
11
|
+
const size = bytes.length + HEADER;
|
|
12
|
+
if (size > MAX_RECORD)
|
|
13
|
+
throw new Error(`Protobuf RDW record exceeds ${MAX_RECORD} bytes`);
|
|
14
|
+
const framed = new Uint8Array(size);
|
|
15
|
+
framed[0] = size >>> 8;
|
|
16
|
+
framed[1] = size & 255;
|
|
17
|
+
framed.set(bytes, HEADER);
|
|
18
|
+
return framed;
|
|
19
|
+
}
|
|
20
|
+
async function fill(handle, bytes) {
|
|
21
|
+
let offset = 0;
|
|
22
|
+
while (offset < bytes.length) {
|
|
23
|
+
const { bytesRead } = await handle.read(bytes, offset, bytes.length - offset, null);
|
|
24
|
+
if (bytesRead === 0)
|
|
25
|
+
break;
|
|
26
|
+
offset += bytesRead;
|
|
27
|
+
}
|
|
28
|
+
return offset;
|
|
29
|
+
}
|
|
30
|
+
/** Read exactly one record; a clean EOF at the next RDW returns undefined. */
|
|
31
|
+
async function readRdw(handle) {
|
|
32
|
+
const header = new Uint8Array(HEADER);
|
|
33
|
+
const got = await fill(handle, header);
|
|
34
|
+
if (got === 0)
|
|
35
|
+
return undefined;
|
|
36
|
+
if (got !== HEADER)
|
|
37
|
+
throw new Error(`Truncated Protobuf record header: expected 4 bytes, got ${got}`);
|
|
38
|
+
const size = header[0] * 256 + header[1];
|
|
39
|
+
if (header[2] !== 0 || header[3] !== 0)
|
|
40
|
+
throw new Error(`Unsupported Protobuf RDW control bytes ${header[2]}, ${header[3]}`);
|
|
41
|
+
if (size < HEADER)
|
|
42
|
+
throw new Error(`Invalid Protobuf record length ${size}: must include four header bytes`);
|
|
43
|
+
const bytes = new Uint8Array(size - HEADER);
|
|
44
|
+
const received = await fill(handle, bytes);
|
|
45
|
+
if (received !== bytes.length)
|
|
46
|
+
throw new Error(`Truncated Protobuf record: expected ${size} bytes, got ${HEADER + received}`);
|
|
47
|
+
return bytes;
|
|
48
|
+
}
|
|
49
|
+
async function writeRdw(handle, bytes) {
|
|
50
|
+
const framed = rdwFrame(bytes);
|
|
51
|
+
let offset = 0;
|
|
52
|
+
while (offset < framed.length) {
|
|
53
|
+
const { bytesWritten } = await handle.write(framed, offset, framed.length - offset, null);
|
|
54
|
+
if (bytesWritten === 0)
|
|
55
|
+
throw new Error('Unable to write Protobuf RDW record');
|
|
56
|
+
offset += bytesWritten;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Hot-path writer: one reusable buffer holds many complete RDW records. */
|
|
60
|
+
function createBufferedRdwWriter(handle, capacity = 1024 * 1024) {
|
|
61
|
+
if (!Number.isSafeInteger(capacity) || capacity < MAX_RECORD)
|
|
62
|
+
throw new Error(`Protobuf writer capacity must be at least ${MAX_RECORD} bytes`);
|
|
63
|
+
const buffer = new Uint8Array(capacity);
|
|
64
|
+
let used = 0;
|
|
65
|
+
async function flush() {
|
|
66
|
+
let offset = 0;
|
|
67
|
+
while (offset < used) {
|
|
68
|
+
const { bytesWritten } = await handle.write(buffer, offset, used - offset, null);
|
|
69
|
+
if (bytesWritten <= 0)
|
|
70
|
+
throw new Error('Unable to write buffered Protobuf records');
|
|
71
|
+
offset += bytesWritten;
|
|
72
|
+
}
|
|
73
|
+
used = 0;
|
|
74
|
+
}
|
|
75
|
+
function header(offset, length) {
|
|
76
|
+
buffer[offset] = length >>> 8;
|
|
77
|
+
buffer[offset + 1] = length & 255;
|
|
78
|
+
buffer[offset + 2] = 0;
|
|
79
|
+
buffer[offset + 3] = 0;
|
|
80
|
+
}
|
|
81
|
+
function appendRecord(bytes) {
|
|
82
|
+
const length = bytes.length + HEADER;
|
|
83
|
+
if (length > MAX_RECORD)
|
|
84
|
+
throw new Error(`Protobuf RDW record exceeds ${MAX_RECORD} bytes`);
|
|
85
|
+
if (capacity - used < length)
|
|
86
|
+
return false;
|
|
87
|
+
header(used, length);
|
|
88
|
+
buffer.set(bytes, used + HEADER);
|
|
89
|
+
used += length;
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
function appendEncoded(message, codec) {
|
|
93
|
+
const length = codec.encodedLength(message) + HEADER;
|
|
94
|
+
if (length > MAX_RECORD)
|
|
95
|
+
throw new Error(`Protobuf RDW record exceeds ${MAX_RECORD} bytes`);
|
|
96
|
+
if (capacity - used < length)
|
|
97
|
+
return false;
|
|
98
|
+
header(used, length);
|
|
99
|
+
const written = codec.encodeInto(message, buffer, used + HEADER, length - HEADER);
|
|
100
|
+
if (written !== length - HEADER)
|
|
101
|
+
throw new Error('Accumulator encoder wrote an unexpected byte count');
|
|
102
|
+
used += length;
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
return { appendRecord, appendEncoded, flush };
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=protobuf.rdw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protobuf.rdw.js","sourceRoot":"","sources":["../../src/protobuf.rdw.ts"],"names":[],"mappings":";;AAMA,4BAQC;AAaD,0BAYC;A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QAAQ,CAAC,CAAC;QACzF,IAAG,QAAQ,GAAC,IAAI,GAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QACtC,MAAM,CAAC,IAAI,EAAC,MAAM,CAAC,CAAC;QACpB,MAAM,CAAC,GAAG,CAAC,KAAK,EAAC,IAAI,GAAC,MAAM,CAAC,CAAC;QAC9B,IAAI,IAAE,MAAM,CAAC;QACb,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,SAAS,aAAa,CAClB,OAAS,EACT,KAAqH;QAErH,MAAM,MAAM,GAAC,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,GAAC,MAAM,CAAC;QACjD,IAAG,MAAM,GAAC,UAAU;YAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,UAAU,QAAQ,CAAC,CAAC;QACzF,IAAG,QAAQ,GAAC,IAAI,GAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QACtC,MAAM,CAAC,IAAI,EAAC,MAAM,CAAC,CAAC;QACpB,MAAM,OAAO,GAAC,KAAK,CAAC,UAAU,CAAC,OAAO,EAAC,MAAM,EAAC,IAAI,GAAC,MAAM,EAAC,MAAM,GAAC,MAAM,CAAC,CAAC;QACzE,IAAG,OAAO,KAAG,MAAM,GAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QAClG,IAAI,IAAE,MAAM,CAAC;QACb,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,EAAC,YAAY,EAAC,aAAa,EAAC,KAAK,EAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createProtobufParserRegistry = createProtobufParserRegistry;
|
|
4
|
+
const protobuf_parser_1 = require("./protobuf.parser");
|
|
5
|
+
function createProtobufParserRegistry(details) {
|
|
6
|
+
return { protobuf: { parser: protobuf_parser_1.protobufParser, parserConfig: () => details, createRecordState: protobuf_parser_1.createProtobufRecordState } };
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=protobuf.registration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protobuf.registration.js","sourceRoot":"","sources":["../../src/protobuf.registration.ts"],"names":[],"mappings":";;AAGA,oEAEC;AAJD,uDAAgG;AAEhG,SAAgB,4BAA4B,CAAC,OAAuB;IAChE,OAAO,EAAC,QAAQ,EAAC,EAAC,MAAM,EAAC,gCAAc,EAAC,YAAY,EAAC,GAAE,EAAE,CAAA,OAAO,EAAC,iBAAiB,EAAC,2CAAyB,EAAC,EAAC,CAAC;AACnH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|