diff options
Diffstat (limited to 'node_modules/capnp-ts/src/serialization')
176 files changed, 11414 insertions, 0 deletions
diff --git a/node_modules/capnp-ts/src/serialization/arena/any-arena.d.ts b/node_modules/capnp-ts/src/serialization/arena/any-arena.d.ts new file mode 100644 index 0000000..dc7e62a --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/any-arena.d.ts @@ -0,0 +1,3 @@ +import { MultiSegmentArena } from "./multi-segment-arena"; +import { SingleSegmentArena } from "./single-segment-arena"; +export declare type AnyArena = MultiSegmentArena | SingleSegmentArena; diff --git a/node_modules/capnp-ts/src/serialization/arena/any-arena.js b/node_modules/capnp-ts/src/serialization/arena/any-arena.js new file mode 100644 index 0000000..ce181cb --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/any-arena.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=any-arena.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/arena/any-arena.js.map b/node_modules/capnp-ts/src/serialization/arena/any-arena.js.map new file mode 100644 index 0000000..151e5db --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/any-arena.js.map @@ -0,0 +1 @@ +{"version":3,"file":"any-arena.js","sourceRoot":"","sources":["any-arena.ts"],"names":[],"mappings":""}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/arena/any-arena.ts b/node_modules/capnp-ts/src/serialization/arena/any-arena.ts new file mode 100644 index 0000000..3f96922 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/any-arena.ts @@ -0,0 +1,4 @@ +import { MultiSegmentArena } from "./multi-segment-arena"; +import { SingleSegmentArena } from "./single-segment-arena"; + +export type AnyArena = MultiSegmentArena | SingleSegmentArena; diff --git a/node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.d.ts b/node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.d.ts new file mode 100644 index 0000000..3099d3d --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.d.ts @@ -0,0 +1,18 @@ +/** + * @author jdiaz5513 + */ +export declare class ArenaAllocationResult { + /** + * The newly allocated buffer. This buffer might be a copy of an existing segment's buffer with free space appended. + * + * @type {ArrayBuffer} + */ + readonly buffer: ArrayBuffer; + /** + * The id of the newly-allocated segment. + * + * @type {number} + */ + readonly id: number; + constructor(id: number, buffer: ArrayBuffer); +} diff --git a/node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.js b/node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.js new file mode 100644 index 0000000..6984a19 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.js @@ -0,0 +1,19 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ArenaAllocationResult = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const trace = debug_1.default("capnp:serialization:arena:arena-allocation-result"); +trace("load"); +class ArenaAllocationResult { + constructor(id, buffer) { + this.id = id; + this.buffer = buffer; + trace("new", this); + } +} +exports.ArenaAllocationResult = ArenaAllocationResult; +//# sourceMappingURL=arena-allocation-result.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.js.map b/node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.js.map new file mode 100644 index 0000000..062fcbb --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.js.map @@ -0,0 +1 @@ +{"version":3,"file":"arena-allocation-result.js","sourceRoot":"","sources":["arena-allocation-result.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,MAAM,KAAK,GAAG,eAAS,CAAC,mDAAmD,CAAC,CAAC;AAC7E,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,qBAAqB;IAiBhC,YAAY,EAAU,EAAE,MAAmB;QACzC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACrB,CAAC;CACF;AAvBD,sDAuBC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.ts b/node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.ts new file mode 100644 index 0000000..a2c746c --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.ts @@ -0,0 +1,33 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +const trace = initTrace("capnp:serialization:arena:arena-allocation-result"); +trace("load"); + +export class ArenaAllocationResult { + /** + * The newly allocated buffer. This buffer might be a copy of an existing segment's buffer with free space appended. + * + * @type {ArrayBuffer} + */ + + readonly buffer: ArrayBuffer; + + /** + * The id of the newly-allocated segment. + * + * @type {number} + */ + + readonly id: number; + + constructor(id: number, buffer: ArrayBuffer) { + this.id = id; + this.buffer = buffer; + + trace("new", this); + } +} diff --git a/node_modules/capnp-ts/src/serialization/arena/arena-kind.d.ts b/node_modules/capnp-ts/src/serialization/arena/arena-kind.d.ts new file mode 100644 index 0000000..6437de1 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/arena-kind.d.ts @@ -0,0 +1,4 @@ +export declare enum ArenaKind { + SINGLE_SEGMENT = 0, + MULTI_SEGMENT = 1 +} diff --git a/node_modules/capnp-ts/src/serialization/arena/arena-kind.js b/node_modules/capnp-ts/src/serialization/arena/arena-kind.js new file mode 100644 index 0000000..a01cb84 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/arena-kind.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ArenaKind = void 0; +var ArenaKind; +(function (ArenaKind) { + ArenaKind[ArenaKind["SINGLE_SEGMENT"] = 0] = "SINGLE_SEGMENT"; + ArenaKind[ArenaKind["MULTI_SEGMENT"] = 1] = "MULTI_SEGMENT"; +})(ArenaKind = exports.ArenaKind || (exports.ArenaKind = {})); +//# sourceMappingURL=arena-kind.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/arena/arena-kind.js.map b/node_modules/capnp-ts/src/serialization/arena/arena-kind.js.map new file mode 100644 index 0000000..aec7139 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/arena-kind.js.map @@ -0,0 +1 @@ +{"version":3,"file":"arena-kind.js","sourceRoot":"","sources":["arena-kind.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,6DAAc,CAAA;IACd,2DAAa,CAAA;AACf,CAAC,EAHW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAGpB"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/arena/arena-kind.ts b/node_modules/capnp-ts/src/serialization/arena/arena-kind.ts new file mode 100644 index 0000000..66357be --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/arena-kind.ts @@ -0,0 +1,4 @@ +export enum ArenaKind { + SINGLE_SEGMENT, + MULTI_SEGMENT +} diff --git a/node_modules/capnp-ts/src/serialization/arena/arena.d.ts b/node_modules/capnp-ts/src/serialization/arena/arena.d.ts new file mode 100644 index 0000000..e14ec81 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/arena.d.ts @@ -0,0 +1,14 @@ +/** + * @author jdiaz5513 + */ +import { Segment } from "../segment"; +import { AnyArena } from "./any-arena"; +import { ArenaAllocationResult } from "./arena-allocation-result"; +export declare abstract class Arena { + static readonly allocate: typeof allocate; + static readonly getBuffer: typeof getBuffer; + static readonly getNumSegments: typeof getNumSegments; +} +export declare function allocate(minSize: number, segments: Segment[], a: AnyArena): ArenaAllocationResult; +export declare function getBuffer(id: number, a: AnyArena): ArrayBuffer; +export declare function getNumSegments(a: AnyArena): number; diff --git a/node_modules/capnp-ts/src/serialization/arena/arena.js b/node_modules/capnp-ts/src/serialization/arena/arena.js new file mode 100644 index 0000000..bf2642e --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/arena.js @@ -0,0 +1,54 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getNumSegments = exports.getBuffer = exports.allocate = exports.Arena = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const errors_1 = require("../../errors"); +const arena_kind_1 = require("./arena-kind"); +const multi_segment_arena_1 = require("./multi-segment-arena"); +const single_segment_arena_1 = require("./single-segment-arena"); +const trace = debug_1.default("capnp:arena"); +trace("load"); +class Arena { +} +exports.Arena = Arena; +Arena.allocate = allocate; +Arena.getBuffer = getBuffer; +Arena.getNumSegments = getNumSegments; +function allocate(minSize, segments, a) { + switch (a.kind) { + case arena_kind_1.ArenaKind.MULTI_SEGMENT: + return multi_segment_arena_1.MultiSegmentArena.allocate(minSize, a); + case arena_kind_1.ArenaKind.SINGLE_SEGMENT: + return single_segment_arena_1.SingleSegmentArena.allocate(minSize, segments, a); + default: + return errors_1.assertNever(a); + } +} +exports.allocate = allocate; +function getBuffer(id, a) { + switch (a.kind) { + case arena_kind_1.ArenaKind.MULTI_SEGMENT: + return multi_segment_arena_1.MultiSegmentArena.getBuffer(id, a); + case arena_kind_1.ArenaKind.SINGLE_SEGMENT: + return single_segment_arena_1.SingleSegmentArena.getBuffer(id, a); + default: + return errors_1.assertNever(a); + } +} +exports.getBuffer = getBuffer; +function getNumSegments(a) { + switch (a.kind) { + case arena_kind_1.ArenaKind.MULTI_SEGMENT: + return multi_segment_arena_1.MultiSegmentArena.getNumSegments(a); + case arena_kind_1.ArenaKind.SINGLE_SEGMENT: + return single_segment_arena_1.SingleSegmentArena.getNumSegments(); + default: + return errors_1.assertNever(a); + } +} +exports.getNumSegments = getNumSegments; +//# sourceMappingURL=arena.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/arena/arena.js.map b/node_modules/capnp-ts/src/serialization/arena/arena.js.map new file mode 100644 index 0000000..2089f01 --- /dev/null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AAC,IAAI,EAAE;QACd,KAAK,sBAAS,CAAC,aAAa;YAC1B,OAAO,uCAAiB,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;QAE7C,KAAK,sBAAS,CAAC,cAAc;YAC3B,OAAO,yCAAkB,CAAC,cAAc,EAAE,CAAC;QAE7C;YACE,OAAO,oBAAW,CAAC,CAAC,CAAC,CAAC;KACzB;AACH,CAAC;AAXD,wCAWC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/arena/arena.ts b/node_modules/capnp-ts/src/serialization/arena/arena.ts new file mode 100644 index 0000000..1c88859 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/arena.ts @@ -0,0 +1,60 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; +import { assertNever } from "../../errors"; +import { Segment } from "../segment"; +import { AnyArena } from "./any-arena"; +import { ArenaAllocationResult } from "./arena-allocation-result"; +import { ArenaKind } from "./arena-kind"; +import { MultiSegmentArena } from "./multi-segment-arena"; +import { SingleSegmentArena } from "./single-segment-arena"; + +const trace = initTrace("capnp:arena"); +trace("load"); + +export abstract class Arena { + static readonly allocate = allocate; + static readonly getBuffer = getBuffer; + static readonly getNumSegments = getNumSegments; +} + +export function allocate(minSize: number, segments: Segment[], a: AnyArena): ArenaAllocationResult { + switch (a.kind) { + case ArenaKind.MULTI_SEGMENT: + return MultiSegmentArena.allocate(minSize, a); + + case ArenaKind.SINGLE_SEGMENT: + return SingleSegmentArena.allocate(minSize, segments, a); + + default: + return assertNever(a); + } +} + +export function getBuffer(id: number, a: AnyArena): ArrayBuffer { + switch (a.kind) { + case ArenaKind.MULTI_SEGMENT: + return MultiSegmentArena.getBuffer(id, a); + + case ArenaKind.SINGLE_SEGMENT: + return SingleSegmentArena.getBuffer(id, a); + + default: + return assertNever(a); + } +} + +export function getNumSegments(a: AnyArena): number { + switch (a.kind) { + case ArenaKind.MULTI_SEGMENT: + return MultiSegmentArena.getNumSegments(a); + + case ArenaKind.SINGLE_SEGMENT: + return SingleSegmentArena.getNumSegments(); + + default: + return assertNever(a); + } +} diff --git a/node_modules/capnp-ts/src/serialization/arena/index.d.ts b/node_modules/capnp-ts/src/serialization/arena/index.d.ts new file mode 100644 index 0000000..86f6210 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/index.d.ts @@ -0,0 +1,8 @@ +/** + * @author jdiaz5513 + */ +export { AnyArena } from "./any-arena"; +export { Arena } from "./arena"; +export { ArenaKind } from "./arena-kind"; +export { MultiSegmentArena } from "./multi-segment-arena"; +export { SingleSegmentArena } from "./single-segment-arena"; diff --git a/node_modules/capnp-ts/src/serialization/arena/index.js b/node_modules/capnp-ts/src/serialization/arena/index.js new file mode 100644 index 0000000..e2ee4e5 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/index.js @@ -0,0 +1,15 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SingleSegmentArena = exports.MultiSegmentArena = exports.ArenaKind = exports.Arena = void 0; +var arena_1 = require("./arena"); +Object.defineProperty(exports, "Arena", { enumerable: true, get: function () { return arena_1.Arena; } }); +var arena_kind_1 = require("./arena-kind"); +Object.defineProperty(exports, "ArenaKind", { enumerable: true, get: function () { return arena_kind_1.ArenaKind; } }); +var multi_segment_arena_1 = require("./multi-segment-arena"); +Object.defineProperty(exports, "MultiSegmentArena", { enumerable: true, get: function () { return multi_segment_arena_1.MultiSegmentArena; } }); +var single_segment_arena_1 = require("./single-segment-arena"); +Object.defineProperty(exports, "SingleSegmentArena", { enumerable: true, get: function () { return single_segment_arena_1.SingleSegmentArena; } }); +//# sourceMappingURL=index.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/arena/index.js.map b/node_modules/capnp-ts/src/serialization/arena/index.js.map new file mode 100644 index 0000000..aef7b57 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAGH,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAClB,6DAA0D;AAAjD,wHAAA,iBAAiB,OAAA;AAC1B,+DAA4D;AAAnD,0HAAA,kBAAkB,OAAA"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/arena/index.ts b/node_modules/capnp-ts/src/serialization/arena/index.ts new file mode 100644 index 0000000..5128c6e --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/index.ts @@ -0,0 +1,9 @@ +/** + * @author jdiaz5513 + */ + +export { AnyArena } from "./any-arena"; +export { Arena } from "./arena"; +export { ArenaKind } from "./arena-kind"; +export { MultiSegmentArena } from "./multi-segment-arena"; +export { SingleSegmentArena } from "./single-segment-arena"; diff --git a/node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.d.ts b/node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.d.ts new file mode 100644 index 0000000..84b5412 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.d.ts @@ -0,0 +1,17 @@ +/** + * @author jdiaz5513 + */ +import { ArenaAllocationResult } from "./arena-allocation-result"; +import { ArenaKind } from "./arena-kind"; +export declare class MultiSegmentArena { + static readonly allocate: typeof allocate; + static readonly getBuffer: typeof getBuffer; + static readonly getNumSegments: typeof getNumSegments; + readonly buffers: ArrayBuffer[]; + readonly kind = ArenaKind.MULTI_SEGMENT; + constructor(buffers?: ArrayBuffer[]); + toString(): string; +} +export declare function allocate(minSize: number, m: MultiSegmentArena): ArenaAllocationResult; +export declare function getBuffer(id: number, m: MultiSegmentArena): ArrayBuffer; +export declare function getNumSegments(m: MultiSegmentArena): number; diff --git a/node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.js b/node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.js new file mode 100644 index 0000000..8e5d064 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.js @@ -0,0 +1,47 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getNumSegments = exports.getBuffer = exports.allocate = exports.MultiSegmentArena = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const constants_1 = require("../../constants"); +const errors_1 = require("../../errors"); +const util_1 = require("../../util"); +const arena_allocation_result_1 = require("./arena-allocation-result"); +const arena_kind_1 = require("./arena-kind"); +const trace = debug_1.default("capnp:arena:multi"); +trace("load"); +class MultiSegmentArena { + constructor(buffers = []) { + this.kind = arena_kind_1.ArenaKind.MULTI_SEGMENT; + this.buffers = buffers; + trace("new %s", this); + } + toString() { + return util_1.format("MultiSegmentArena_segments:%d", getNumSegments(this)); + } +} +exports.MultiSegmentArena = MultiSegmentArena; +MultiSegmentArena.allocate = allocate; +MultiSegmentArena.getBuffer = getBuffer; +MultiSegmentArena.getNumSegments = getNumSegments; +function allocate(minSize, m) { + const b = new ArrayBuffer(util_1.padToWord(Math.max(minSize, constants_1.DEFAULT_BUFFER_SIZE))); + m.buffers.push(b); + return new arena_allocation_result_1.ArenaAllocationResult(m.buffers.length - 1, b); +} +exports.allocate = allocate; +function getBuffer(id, m) { + if (id < 0 || id >= m.buffers.length) { + throw new Error(util_1.format(errors_1.SEG_ID_OUT_OF_BOUNDS, id)); + } + return m.buffers[id]; +} +exports.getBuffer = getBuffer; +function getNumSegments(m) { + return m.buffers.length; +} +exports.getNumSegments = getNumSegments; +//# sourceMappingURL=multi-segment-arena.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.js.map b/node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.js.map new file mode 100644 index 0000000..b86b981 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.js.map @@ -0,0 +1 @@ +{"version":3,"file":"multi-segment-arena.js","sourceRoot":"","sources":["multi-segment-arena.ts"],"names":[],"mappings":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,CAAC;AACvB,CAAC;AAND,8BAMC;AAED,SAAgB,cAAc,CAAC,CAAoB;IACjD,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;AAC1B,CAAC;AAFD,wCAEC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.ts b/node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.ts new file mode 100644 index 0000000..7a53e1b --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.ts @@ -0,0 +1,51 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; +import { DEFAULT_BUFFER_SIZE } from "../../constants"; +import { SEG_ID_OUT_OF_BOUNDS } from "../../errors"; +import { padToWord, format } from "../../util"; +import { ArenaAllocationResult } from "./arena-allocation-result"; +import { ArenaKind } from "./arena-kind"; + +const trace = initTrace("capnp:arena:multi"); +trace("load"); + +export class MultiSegmentArena { + static readonly allocate = allocate; + static readonly getBuffer = getBuffer; + static readonly getNumSegments = getNumSegments; + + readonly buffers: ArrayBuffer[]; + readonly kind = ArenaKind.MULTI_SEGMENT; + + constructor(buffers: ArrayBuffer[] = []) { + this.buffers = buffers; + + trace("new %s", this); + } + + toString(): string { + return format("MultiSegmentArena_segments:%d", getNumSegments(this)); + } +} + +export function allocate(minSize: number, m: MultiSegmentArena): ArenaAllocationResult { + const b = new ArrayBuffer(padToWord(Math.max(minSize, DEFAULT_BUFFER_SIZE))); + m.buffers.push(b); + + return new ArenaAllocationResult(m.buffers.length - 1, b); +} + +export function getBuffer(id: number, m: MultiSegmentArena): ArrayBuffer { + if (id < 0 || id >= m.buffers.length) { + throw new Error(format(SEG_ID_OUT_OF_BOUNDS, id)); + } + + return m.buffers[id]; +} + +export function getNumSegments(m: MultiSegmentArena): number { + return m.buffers.length; +} diff --git a/node_modules/capnp-ts/src/serialization/arena/single-segment-arena.d.ts b/node_modules/capnp-ts/src/serialization/arena/single-segment-arena.d.ts new file mode 100644 index 0000000..07b2950 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/single-segment-arena.d.ts @@ -0,0 +1,18 @@ +/** + * @author jdiaz5513 + */ +import { Segment } from "../segment"; +import { ArenaAllocationResult } from "./arena-allocation-result"; +import { ArenaKind } from "./arena-kind"; +export declare class SingleSegmentArena { + static readonly allocate: typeof allocate; + static readonly getBuffer: typeof getBuffer; + static readonly getNumSegments: typeof getNumSegments; + buffer: ArrayBuffer; + readonly kind = ArenaKind.SINGLE_SEGMENT; + constructor(buffer?: ArrayBuffer); + toString(): string; +} +export declare function allocate(minSize: number, segments: Segment[], s: SingleSegmentArena): ArenaAllocationResult; +export declare function getBuffer(id: number, s: SingleSegmentArena): ArrayBuffer; +export declare function getNumSegments(): number; diff --git a/node_modules/capnp-ts/src/serialization/arena/single-segment-arena.js b/node_modules/capnp-ts/src/serialization/arena/single-segment-arena.js new file mode 100644 index 0000000..3edc8b5 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/single-segment-arena.js @@ -0,0 +1,59 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getNumSegments = exports.getBuffer = exports.allocate = exports.SingleSegmentArena = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const constants_1 = require("../../constants"); +const errors_1 = require("../../errors"); +const util_1 = require("../../util"); +const arena_allocation_result_1 = require("./arena-allocation-result"); +const arena_kind_1 = require("./arena-kind"); +const trace = debug_1.default("capnp:arena:single"); +trace("load"); +class SingleSegmentArena { + constructor(buffer = new ArrayBuffer(constants_1.DEFAULT_BUFFER_SIZE)) { + this.kind = arena_kind_1.ArenaKind.SINGLE_SEGMENT; + if ((buffer.byteLength & 7) !== 0) { + throw new Error(util_1.format(errors_1.SEG_NOT_WORD_ALIGNED, buffer.byteLength)); + } + this.buffer = buffer; + trace("new %s", this); + } + toString() { + return util_1.format("SingleSegmentArena_len:%x", this.buffer.byteLength); + } +} +exports.SingleSegmentArena = SingleSegmentArena; +SingleSegmentArena.allocate = allocate; +SingleSegmentArena.getBuffer = getBuffer; +SingleSegmentArena.getNumSegments = getNumSegments; +function allocate(minSize, segments, s) { + trace("Allocating %x bytes for segment 0 in %s.", minSize, s); + const srcBuffer = segments.length > 0 ? segments[0].buffer : s.buffer; + if (minSize < constants_1.MIN_SINGLE_SEGMENT_GROWTH) { + minSize = constants_1.MIN_SINGLE_SEGMENT_GROWTH; + } + else { + minSize = util_1.padToWord(minSize); + } + s.buffer = new ArrayBuffer(srcBuffer.byteLength + minSize); + // PERF: Assume that the source and destination buffers are word-aligned and use Float64Array to copy them one word + // at a time. + new Float64Array(s.buffer).set(new Float64Array(srcBuffer)); + return new arena_allocation_result_1.ArenaAllocationResult(0, s.buffer); +} +exports.allocate = allocate; +function getBuffer(id, s) { + if (id !== 0) + throw new Error(util_1.format(errors_1.SEG_GET_NON_ZERO_SINGLE, id)); + return s.buffer; +} +exports.getBuffer = getBuffer; +function getNumSegments() { + return 1; +} +exports.getNumSegments = getNumSegments; +//# sourceMappingURL=single-segment-arena.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/arena/single-segment-arena.js.map b/node_modules/capnp-ts/src/serialization/arena/single-segment-arena.js.map new file mode 100644 index 0000000..d150e0b --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/single-segment-arena.js.map @@ -0,0 +1 @@ +{"version":3,"file":"single-segment-arena.js","sourceRoot":"","sources":["single-segment-arena.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAC9B,+CAAiF;AACjF,yCAA6E;AAC7E,qCAA+C;AAE/C,uEAAkE;AAClE,6CAAyC;AAEzC,MAAM,KAAK,GAAG,eAAS,CAAC,oBAAoB,CAAC,CAAC;AAC9C,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,kBAAkB;IAQ7B,YAAY,MAAM,GAAG,IAAI,WAAW,CAAC,+BAAmB,CAAC;QAFhD,SAAI,GAAG,sBAAS,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CAAC;AAlBD,4BAkBC;AAED,SAAgB,SAAS,CAAC,EAAU,EAAE,CAAqB;IACzD,IAAI,EAAE,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,aAAM,CAAC,gCAAuB,EAAE,EAAE,CAAC,CAAC,CAAC;IAEnE,OAAO,CAAC,CAAC,MAAM,CAAC;AAClB,CAAC;AAJD,8BAIC;AAED,SAAgB,cAAc;IAC5B,OAAO,CAAC,CAAC;AACX,CAAC;AAFD,wCAEC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/arena/single-segment-arena.ts b/node_modules/capnp-ts/src/serialization/arena/single-segment-arena.ts new file mode 100644 index 0000000..250568c --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/arena/single-segment-arena.ts @@ -0,0 +1,67 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; +import { DEFAULT_BUFFER_SIZE, MIN_SINGLE_SEGMENT_GROWTH } from "../../constants"; +import { SEG_GET_NON_ZERO_SINGLE, SEG_NOT_WORD_ALIGNED } from "../../errors"; +import { format, padToWord } from "../../util"; +import { Segment } from "../segment"; +import { ArenaAllocationResult } from "./arena-allocation-result"; +import { ArenaKind } from "./arena-kind"; + +const trace = initTrace("capnp:arena:single"); +trace("load"); + +export class SingleSegmentArena { + static readonly allocate = allocate; + static readonly getBuffer = getBuffer; + static readonly getNumSegments = getNumSegments; + + buffer: ArrayBuffer; + readonly kind = ArenaKind.SINGLE_SEGMENT; + + constructor(buffer = new ArrayBuffer(DEFAULT_BUFFER_SIZE)) { + if ((buffer.byteLength & 7) !== 0) { + throw new Error(format(SEG_NOT_WORD_ALIGNED, buffer.byteLength)); + } + + this.buffer = buffer; + + trace("new %s", this); + } + + toString(): string { + return format("SingleSegmentArena_len:%x", this.buffer.byteLength); + } +} + +export function allocate(minSize: number, segments: Segment[], s: SingleSegmentArena): ArenaAllocationResult { + trace("Allocating %x bytes for segment 0 in %s.", minSize, s); + + const srcBuffer = segments.length > 0 ? segments[0].buffer : s.buffer; + + if (minSize < MIN_SINGLE_SEGMENT_GROWTH) { + minSize = MIN_SINGLE_SEGMENT_GROWTH; + } else { + minSize = padToWord(minSize); + } + + s.buffer = new ArrayBuffer(srcBuffer.byteLength + minSize); + + // PERF: Assume that the source and destination buffers are word-aligned and use Float64Array to copy them one word + // at a time. + new Float64Array(s.buffer).set(new Float64Array(srcBuffer)); + + return new ArenaAllocationResult(0, s.buffer); +} + +export function getBuffer(id: number, s: SingleSegmentArena): ArrayBuffer { + if (id !== 0) throw new Error(format(SEG_GET_NON_ZERO_SINGLE, id)); + + return s.buffer; +} + +export function getNumSegments(): number { + return 1; +} diff --git a/node_modules/capnp-ts/src/serialization/index.d.ts b/node_modules/capnp-ts/src/serialization/index.d.ts new file mode 100644 index 0000000..ef08a70 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/index.d.ts @@ -0,0 +1,8 @@ +/** + * @author jdiaz5513 + */ +export * from "./mask"; +export { ListElementSize } from "./list-element-size"; +export { Message, readRawPointer } from "./message"; +export { ObjectSize } from "./object-size"; +export * from "./pointers/index"; diff --git a/node_modules/capnp-ts/src/serialization/index.js b/node_modules/capnp-ts/src/serialization/index.js new file mode 100644 index 0000000..16f2cea --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/index.js @@ -0,0 +1,17 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ObjectSize = exports.readRawPointer = exports.Message = exports.ListElementSize = void 0; +const tslib_1 = require("tslib"); +tslib_1.__exportStar(require("./mask"), exports); +var list_element_size_1 = require("./list-element-size"); +Object.defineProperty(exports, "ListElementSize", { enumerable: true, get: function () { return list_element_size_1.ListElementSize; } }); +var message_1 = require("./message"); +Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return message_1.Message; } }); +Object.defineProperty(exports, "readRawPointer", { enumerable: true, get: function () { return message_1.readRawPointer; } }); +var object_size_1 = require("./object-size"); +Object.defineProperty(exports, "ObjectSize", { enumerable: true, get: function () { return object_size_1.ObjectSize; } }); +tslib_1.__exportStar(require("./pointers/index"), exports); +//# sourceMappingURL=index.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/index.js.map b/node_modules/capnp-ts/src/serialization/index.js.map new file mode 100644 index 0000000..c68025b --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,iDAAuB;AACvB,yDAAsD;AAA7C,oHAAA,eAAe,OAAA;AACxB,qCAAoD;AAA3C,kGAAA,OAAO,OAAA;AAAE,yGAAA,cAAc,OAAA;AAChC,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,2DAAiC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/index.ts b/node_modules/capnp-ts/src/serialization/index.ts new file mode 100644 index 0000000..805c2da --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/index.ts @@ -0,0 +1,9 @@ +/** + * @author jdiaz5513 + */ + +export * from "./mask"; +export { ListElementSize } from "./list-element-size"; +export { Message, readRawPointer } from "./message"; +export { ObjectSize } from "./object-size"; +export * from "./pointers/index"; diff --git a/node_modules/capnp-ts/src/serialization/list-element-size.d.ts b/node_modules/capnp-ts/src/serialization/list-element-size.d.ts new file mode 100644 index 0000000..96f9a21 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/list-element-size.d.ts @@ -0,0 +1,14 @@ +/** + * @author jdiaz5513 + */ +export declare enum ListElementSize { + VOID = 0, + BIT = 1, + BYTE = 2, + BYTE_2 = 3, + BYTE_4 = 4, + BYTE_8 = 5, + POINTER = 6, + COMPOSITE = 7 +} +export declare const ListElementOffset: number[]; diff --git a/node_modules/capnp-ts/src/serialization/list-element-size.js b/node_modules/capnp-ts/src/serialization/list-element-size.js new file mode 100644 index 0000000..35816c4 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/list-element-size.js @@ -0,0 +1,28 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ListElementOffset = exports.ListElementSize = void 0; +var ListElementSize; +(function (ListElementSize) { + ListElementSize[ListElementSize["VOID"] = 0] = "VOID"; + ListElementSize[ListElementSize["BIT"] = 1] = "BIT"; + ListElementSize[ListElementSize["BYTE"] = 2] = "BYTE"; + ListElementSize[ListElementSize["BYTE_2"] = 3] = "BYTE_2"; + ListElementSize[ListElementSize["BYTE_4"] = 4] = "BYTE_4"; + ListElementSize[ListElementSize["BYTE_8"] = 5] = "BYTE_8"; + ListElementSize[ListElementSize["POINTER"] = 6] = "POINTER"; + ListElementSize[ListElementSize["COMPOSITE"] = 7] = "COMPOSITE"; +})(ListElementSize = exports.ListElementSize || (exports.ListElementSize = {})); +exports.ListElementOffset = [ + 0, + 0.125, + 1, + 2, + 4, + 8, + 8, + NaN // composite +]; +//# sourceMappingURL=list-element-size.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/list-element-size.js.map b/node_modules/capnp-ts/src/serialization/list-element-size.js.map new file mode 100644 index 0000000..ca2a42e --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/list-element-size.js.map @@ -0,0 +1 @@ +{"version":3,"file":"list-element-size.js","sourceRoot":"","sources":["list-element-size.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,IAAY,eASX;AATD,WAAY,eAAe;IACzB,qDAAQ,CAAA;IACR,mDAAO,CAAA;IACP,qDAAQ,CAAA;IACR,yDAAU,CAAA;IACV,yDAAU,CAAA;IACV,yDAAU,CAAA;IACV,2DAAW,CAAA;IACX,+DAAa,CAAA;AACf,CAAC,EATW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAS1B;AAEY,QAAA,iBAAiB,GAAG;IAC/B,CAAC;IACD,KAAK;IACL,CAAC;IACD,CAAC;IACD,CAAC;IACD,CAAC;IACD,CAAC;IACD,GAAG,CAAC,YAAY;CACjB,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/list-element-size.ts b/node_modules/capnp-ts/src/serialization/list-element-size.ts new file mode 100644 index 0000000..0aaac25 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/list-element-size.ts @@ -0,0 +1,25 @@ +/** + * @author jdiaz5513 + */ + +export enum ListElementSize { + VOID = 0, + BIT = 1, + BYTE = 2, + BYTE_2 = 3, + BYTE_4 = 4, + BYTE_8 = 5, + POINTER = 6, + COMPOSITE = 7 +} + +export const ListElementOffset = [ + 0, // void + 0.125, // bit + 1, // byte + 2, // two byte + 4, // four byte + 8, // eight byte + 8, // pointer + NaN // composite +]; diff --git a/node_modules/capnp-ts/src/serialization/mask.d.ts b/node_modules/capnp-ts/src/serialization/mask.d.ts new file mode 100644 index 0000000..c0c71fe --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/mask.d.ts @@ -0,0 +1,16 @@ +/** + * @author jdiaz5513 + */ +import { Int64, Uint64 } from "../types/index"; +export declare const getFloat32Mask: (x: number) => DataView; +export declare const getFloat64Mask: (x: number) => DataView; +export declare const getInt16Mask: (x: number) => DataView; +export declare const getInt32Mask: (x: number) => DataView; +export declare const getInt8Mask: (x: number) => DataView; +export declare const getUint16Mask: (x: number) => DataView; +export declare const getUint32Mask: (x: number) => DataView; +export declare const getUint8Mask: (x: number) => DataView; +export declare function getBitMask(value: boolean, bitOffset: number): DataView; +export declare function getInt64Mask(x: Int64): DataView; +export declare function getUint64Mask(x: Uint64): DataView; +export declare function getVoidMask(): void; diff --git a/node_modules/capnp-ts/src/serialization/mask.js b/node_modules/capnp-ts/src/serialization/mask.js new file mode 100644 index 0000000..784d678 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/mask.js @@ -0,0 +1,45 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getVoidMask = exports.getUint64Mask = exports.getInt64Mask = exports.getBitMask = exports.getUint8Mask = exports.getUint32Mask = exports.getUint16Mask = exports.getInt8Mask = exports.getInt32Mask = exports.getInt16Mask = exports.getFloat64Mask = exports.getFloat32Mask = void 0; +const errors_1 = require("../errors"); +function _makePrimitiveMaskFn(byteLength, setter) { + return (x) => { + const dv = new DataView(new ArrayBuffer(byteLength)); + setter.call(dv, 0, x, true); + return dv; + }; +} +/* eslint-disable @typescript-eslint/unbound-method */ +exports.getFloat32Mask = _makePrimitiveMaskFn(4, DataView.prototype.setFloat32); +exports.getFloat64Mask = _makePrimitiveMaskFn(8, DataView.prototype.setFloat64); +exports.getInt16Mask = _makePrimitiveMaskFn(2, DataView.prototype.setInt16); +exports.getInt32Mask = _makePrimitiveMaskFn(4, DataView.prototype.setInt32); +exports.getInt8Mask = _makePrimitiveMaskFn(1, DataView.prototype.setInt8); +exports.getUint16Mask = _makePrimitiveMaskFn(2, DataView.prototype.setUint16); +exports.getUint32Mask = _makePrimitiveMaskFn(4, DataView.prototype.setUint32); +exports.getUint8Mask = _makePrimitiveMaskFn(1, DataView.prototype.setUint8); +/* eslint-enable */ +function getBitMask(value, bitOffset) { + const dv = new DataView(new ArrayBuffer(1)); + if (!value) + return dv; + dv.setUint8(0, 1 << bitOffset % 8); + return dv; +} +exports.getBitMask = getBitMask; +function getInt64Mask(x) { + return x.toDataView(); +} +exports.getInt64Mask = getInt64Mask; +function getUint64Mask(x) { + return x.toDataView(); +} +exports.getUint64Mask = getUint64Mask; +function getVoidMask() { + throw new Error(errors_1.INVARIANT_UNREACHABLE_CODE); +} +exports.getVoidMask = getVoidMask; +//# sourceMappingURL=mask.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/mask.js.map b/node_modules/capnp-ts/src/serialization/mask.js.map new file mode 100644 index 0000000..104b99a --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/mask.js.map @@ -0,0 +1 @@ +{"version":3,"file":"mask.js","sourceRoot":"","sources":["mask.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,sCAAuD;AAKvD,SAAS,oBAAo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AAE,OAAO,EAAE,CAAC;IAEtB,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC;IACnC,OAAO,EAAE,CAAC;AACZ,CAAC;AAPD,gCAOC;AAED,SAAgB,YAAY,CAAC,CAAQ;IACnC,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC;AACxB,CAAC;AAFD,oCAEC;AAED,SAAgB,aAAa,CAAC,CAAS;IACrC,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC;AACxB,CAAC;AAFD,sCAEC;AAED,SAAgB,WAAW;IACzB,MAAM,IAAI,KAAK,CAAC,mCAA0B,CAAC,CAAC;AAC9C,CAAC;AAFD,kCAEC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/mask.ts b/node_modules/capnp-ts/src/serialization/mask.ts new file mode 100644 index 0000000..dcaa9e9 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/mask.ts @@ -0,0 +1,48 @@ +/** + * @author jdiaz5513 + */ + +import { INVARIANT_UNREACHABLE_CODE } from "../errors"; +import { Int64, Uint64 } from "../types/index"; + +type DataViewSetter = (byteOffset: number, value: number, littleEndian?: boolean) => void; + +function _makePrimitiveMaskFn(byteLength: number, setter: DataViewSetter): (x: number) => DataView { + return (x: number): DataView => { + const dv = new DataView(new ArrayBuffer(byteLength)); + setter.call(dv, 0, x, true); + return dv; + }; +} + +/* eslint-disable @typescript-eslint/unbound-method */ +export const getFloat32Mask = _makePrimitiveMaskFn(4, DataView.prototype.setFloat32); +export const getFloat64Mask = _makePrimitiveMaskFn(8, DataView.prototype.setFloat64); +export const getInt16Mask = _makePrimitiveMaskFn(2, DataView.prototype.setInt16); +export const getInt32Mask = _makePrimitiveMaskFn(4, DataView.prototype.setInt32); +export const getInt8Mask = _makePrimitiveMaskFn(1, DataView.prototype.setInt8); +export const getUint16Mask = _makePrimitiveMaskFn(2, DataView.prototype.setUint16); +export const getUint32Mask = _makePrimitiveMaskFn(4, DataView.prototype.setUint32); +export const getUint8Mask = _makePrimitiveMaskFn(1, DataView.prototype.setUint8); +/* eslint-enable */ + +export function getBitMask(value: boolean, bitOffset: number): DataView { + const dv = new DataView(new ArrayBuffer(1)); + + if (!value) return dv; + + dv.setUint8(0, 1 << bitOffset % 8); + return dv; +} + +export function getInt64Mask(x: Int64): DataView { + return x.toDataView(); +} + +export function getUint64Mask(x: Uint64): DataView { + return x.toDataView(); +} + +export function getVoidMask(): void { + throw new Error(INVARIANT_UNREACHABLE_CODE); +} diff --git a/node_modules/capnp-ts/src/serialization/message.d.ts b/node_modules/capnp-ts/src/serialization/message.d.ts new file mode 100644 index 0000000..4eafff5 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/message.d.ts @@ -0,0 +1,158 @@ +/** + * @author jdiaz5513 + */ +import { AnyArena } from "./arena"; +import { Pointer, StructCtor, Struct } from "./pointers"; +import { Segment } from "./segment"; +export interface _Message { + readonly arena: AnyArena; + segments: Segment[]; + traversalLimit: number; +} +export declare class Message { + static readonly allocateSegment: typeof allocateSegment; + static readonly dump: typeof dump; + static readonly getRoot: typeof getRoot; + static readonly getSegment: typeof getSegment; + static readonly initRoot: typeof initRoot; + static readonly readRawPointer: typeof readRawPointer; + static readonly toArrayBuffer: typeof toArrayBuffer; + static readonly toPackedArrayBuffer: typeof toPackedArrayBuffer; + readonly _capnp: _Message; + /** + * A Cap'n Proto message. + * + * SECURITY WARNING: In nodejs do not pass a Buffer's internal array buffer into this constructor. Pass the buffer + * directly and everything will be fine. If not, your message will potentially be initialized with random memory + * contents! + * + * The constructor method creates a new Message, optionally using a provided arena for segment allocation, or a buffer + * to read from. + * + * @constructor {Message} + * + * @param {AnyArena|ArrayBufferView|ArrayBuffer} [src] The source for the message. + * A value of `undefined` will cause the message to initialize with a single segment arena only big enough for the + * root pointer; it will expand as you go. This is a reasonable choice for most messages. + * + * Passing an arena will cause the message to use that arena for its segment allocation. Contents will be accepted + * as-is. + * + * Passing an array buffer view (like `DataView`, `Uint8Array` or `Buffer`) will create a **copy** of the source + * buffer; beware of the potential performance cost! + * + * @param {boolean} [packed] Whether or not the message is packed. If `true` (the default), the message will be + * unpacked. + * + * @param {boolean} [singleSegment] If true, `src` will be treated as a message consisting of a single segment without + * a framing header. + * + */ + constructor(src?: AnyArena | ArrayBufferView | ArrayBuffer, packed?: boolean, singleSegment?: boolean); + allocateSegment(byteLength: number): Segment; + /** + * Create a pretty-printed string dump of this message; incredibly useful for debugging. + * + * WARNING: Do not call this method on large messages! + * + * @returns {string} A big steaming pile of pretty hex digits. + */ + dump(): string; + /** + * Get a struct pointer for the root of this message. This is primarily used when reading a message; it will not + * overwrite existing data. + * + * @template T + * @param {StructCtor<T>} RootStruct The struct type to use as the root. + * @returns {T} A struct representing the root of the message. + */ + getRoot<T extends Struct>(RootStruct: StructCtor<T>): T; + /** + * Get a segment by its id. + * + * This will lazily allocate the first segment if it doesn't already exist. + * + * @param {number} id The segment id. + * @returns {Segment} The requested segment. + */ + getSegment(id: number): Segment; + /** + * Initialize a new message using the provided struct type as the root. + * + * @template T + * @param {StructCtor<T>} RootStruct The struct type to use as the root. + * @returns {T} An initialized struct pointing to the root of the message. + */ + initRoot<T extends Struct>(RootStruct: StructCtor<T>): T; + /** + * Set the root of the message to a copy of the given pointer. Used internally + * to make copies of pointers for default values. + * + * @param {Pointer} src The source pointer to copy. + * @returns {void} + */ + setRoot(src: Pointer): void; + /** + * Combine the contents of this message's segments into a single array buffer and prepend a stream framing header + * containing information about the following segment data. + * + * @returns {ArrayBuffer} An ArrayBuffer with the contents of this message. + */ + toArrayBuffer(): ArrayBuffer; + /** + * Like `toArrayBuffer()`, but also applies the packing algorithm to the output. This is typically what you want to + * use if you're sending the message over a network link or other slow I/O interface where size matters. + * + * @returns {ArrayBuffer} A packed message. + */ + toPackedArrayBuffer(): ArrayBuffer; + toString(): string; +} +export interface CreateMessageOptions { + packed?: boolean; + singleSegment?: boolean; +} +export declare function initMessage(src?: AnyArena | ArrayBufferView | ArrayBuffer, packed?: boolean, singleSegment?: boolean): _Message; +/** + * Given an _unpacked_ message with a segment framing header, this will generate an ArrayBuffer for each segment in + * the message. + * + * This method is not typically called directly, but can be useful in certain cases. + * + * @static + * @param {ArrayBuffer} message An unpacked message with a framing header. + * @returns {ArrayBuffer[]} An array of buffers containing the segment data. + */ +export declare function getFramedSegments(message: ArrayBuffer): ArrayBuffer[]; +/** + * This method is called on messages that were constructed with existing data to prepopulate the segments array with + * everything we can find in the arena. Each segment will have it's `byteLength` set to the size of its buffer. + * + * Technically speaking, the message's segments will be "full" after calling this function. Calling this on your own + * may void your warranty. + * + * @param {Message} m The message to allocate. + * @returns {void} + */ +export declare function preallocateSegments(m: Message): void; +export declare function allocateSegment(byteLength: number, m: Message): Segment; +export declare function dump(m: Message): string; +export declare function getRoot<T extends Struct>(RootStruct: StructCtor<T>, m: Message): T; +export declare function getSegment(id: number, m: Message): Segment; +export declare function initRoot<T extends Struct>(RootStruct: StructCtor<T>, m: Message): T; +/** + * Read a pointer in raw form (a packed message with framing headers). Does not + * care or attempt to validate the input beyond parsing the message + * segments. + * + * This is typically used by the compiler to load default values, but can be + * useful to work with messages with an unknown schema. + * + * @param {ArrayBuffer} data The raw data to read. + * @returns {Pointer} A root pointer. + */ +export declare function readRawPointer(data: ArrayBuffer): Pointer; +export declare function setRoot(src: Pointer, m: Message): void; +export declare function toArrayBuffer(m: Message): ArrayBuffer; +export declare function toPackedArrayBuffer(m: Message): ArrayBuffer; +export declare function getStreamFrame(m: Message): ArrayBuffer; diff --git a/node_modules/capnp-ts/src/serialization/message.js b/node_modules/capnp-ts/src/serialization/message.js new file mode 100644 index 0000000..818c912 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/message.js @@ -0,0 +1,392 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getStreamFrame = exports.toPackedArrayBuffer = exports.toArrayBuffer = exports.setRoot = exports.readRawPointer = exports.initRoot = exports.getSegment = exports.getRoot = exports.dump = exports.allocateSegment = exports.preallocateSegments = exports.getFramedSegments = exports.initMessage = exports.Message = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const constants_1 = require("../constants"); +const errors_1 = require("../errors"); +const util_1 = require("../util"); +const arena_1 = require("./arena"); +const packing_1 = require("./packing"); +const pointers_1 = require("./pointers"); +const segment_1 = require("./segment"); +const pointer_1 = require("./pointers/pointer"); +const struct_1 = require("./pointers/struct"); +const trace = debug_1.default("capnp:message"); +trace("load"); +class Message { + /** + * A Cap'n Proto message. + * + * SECURITY WARNING: In nodejs do not pass a Buffer's internal array buffer into this constructor. Pass the buffer + * directly and everything will be fine. If not, your message will potentially be initialized with random memory + * contents! + * + * The constructor method creates a new Message, optionally using a provided arena for segment allocation, or a buffer + * to read from. + * + * @constructor {Message} + * + * @param {AnyArena|ArrayBufferView|ArrayBuffer} [src] The source for the message. + * A value of `undefined` will cause the message to initialize with a single segment arena only big enough for the + * root pointer; it will expand as you go. This is a reasonable choice for most messages. + * + * Passing an arena will cause the message to use that arena for its segment allocation. Contents will be accepted + * as-is. + * + * Passing an array buffer view (like `DataView`, `Uint8Array` or `Buffer`) will create a **copy** of the source + * buffer; beware of the potential performance cost! + * + * @param {boolean} [packed] Whether or not the message is packed. If `true` (the default), the message will be + * unpacked. + * + * @param {boolean} [singleSegment] If true, `src` will be treated as a message consisting of a single segment without + * a framing header. + * + */ + constructor(src, packed = true, singleSegment = false) { + this._capnp = initMessage(src, packed, singleSegment); + if (src && !isAnyArena(src)) + preallocateSegments(this); + trace("new %s", this); + } + allocateSegment(byteLength) { + return allocateSegment(byteLength, this); + } + /** + * Create a pretty-printed string dump of this message; incredibly useful for debugging. + * + * WARNING: Do not call this method on large messages! + * + * @returns {string} A big steaming pile of pretty hex digits. + */ + dump() { + return dump(this); + } + /** + * Get a struct pointer for the root of this message. This is primarily used when reading a message; it will not + * overwrite existing data. + * + * @template T + * @param {StructCtor<T>} RootStruct The struct type to use as the root. + * @returns {T} A struct representing the root of the message. + */ + getRoot(RootStruct) { + return getRoot(RootStruct, this); + } + /** + * Get a segment by its id. + * + * This will lazily allocate the first segment if it doesn't already exist. + * + * @param {number} id The segment id. + * @returns {Segment} The requested segment. + */ + getSegment(id) { + return getSegment(id, this); + } + /** + * Initialize a new message using the provided struct type as the root. + * + * @template T + * @param {StructCtor<T>} RootStruct The struct type to use as the root. + * @returns {T} An initialized struct pointing to the root of the message. + */ + initRoot(RootStruct) { + return initRoot(RootStruct, this); + } + /** + * Set the root of the message to a copy of the given pointer. Used internally + * to make copies of pointers for default values. + * + * @param {Pointer} src The source pointer to copy. + * @returns {void} + */ + setRoot(src) { + setRoot(src, this); + } + /** + * Combine the contents of this message's segments into a single array buffer and prepend a stream framing header + * containing information about the following segment data. + * + * @returns {ArrayBuffer} An ArrayBuffer with the contents of this message. + */ + toArrayBuffer() { + return toArrayBuffer(this); + } + /** + * Like `toArrayBuffer()`, but also applies the packing algorithm to the output. This is typically what you want to + * use if you're sending the message over a network link or other slow I/O interface where size matters. + * + * @returns {ArrayBuffer} A packed message. + */ + toPackedArrayBuffer() { + return toPackedArrayBuffer(this); + } + toString() { + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions + return `Message_arena:${this._capnp.arena}`; + } +} +exports.Message = Message; +Message.allocateSegment = allocateSegment; +Message.dump = dump; +Message.getRoot = getRoot; +Message.getSegment = getSegment; +Message.initRoot = initRoot; +Message.readRawPointer = readRawPointer; +Message.toArrayBuffer = toArrayBuffer; +Message.toPackedArrayBuffer = toPackedArrayBuffer; +function initMessage(src, packed = true, singleSegment = false) { + if (src === undefined) { + return { + arena: new arena_1.SingleSegmentArena(), + segments: [], + traversalLimit: constants_1.DEFAULT_TRAVERSE_LIMIT, + }; + } + if (isAnyArena(src)) { + return { arena: src, segments: [], traversalLimit: constants_1.DEFAULT_TRAVERSE_LIMIT }; + } + let buf = src; + if (isArrayBufferView(buf)) { + buf = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength); + } + if (packed) + buf = packing_1.unpack(buf); + if (singleSegment) { + return { + arena: new arena_1.SingleSegmentArena(buf), + segments: [], + traversalLimit: constants_1.DEFAULT_TRAVERSE_LIMIT, + }; + } + return { + arena: new arena_1.MultiSegmentArena(getFramedSegments(buf)), + segments: [], + traversalLimit: constants_1.DEFAULT_TRAVERSE_LIMIT, + }; +} +exports.initMessage = initMessage; +/** + * Given an _unpacked_ message with a segment framing header, this will generate an ArrayBuffer for each segment in + * the message. + * + * This method is not typically called directly, but can be useful in certain cases. + * + * @static + * @param {ArrayBuffer} message An unpacked message with a framing header. + * @returns {ArrayBuffer[]} An array of buffers containing the segment data. + */ +function getFramedSegments(message) { + const dv = new DataView(message); + const segmentCount = dv.getUint32(0, true) + 1; + const segments = new Array(segmentCount); + trace("reading %d framed segments from stream", segmentCount); + let byteOffset = 4 + segmentCount * 4; + byteOffset += byteOffset % 8; + if (byteOffset + segmentCount * 4 > message.byteLength) { + throw new Error(errors_1.MSG_INVALID_FRAME_HEADER); + } + for (let i = 0; i < segmentCount; i++) { + const byteLength = dv.getUint32(4 + i * 4, true) * 8; + if (byteOffset + byteLength > message.byteLength) { + throw new Error(errors_1.MSG_INVALID_FRAME_HEADER); + } + segments[i] = message.slice(byteOffset, byteOffset + byteLength); + byteOffset += byteLength; + } + return segments; +} +exports.getFramedSegments = getFramedSegments; +/** + * This method is called on messages that were constructed with existing data to prepopulate the segments array with + * everything we can find in the arena. Each segment will have it's `byteLength` set to the size of its buffer. + * + * Technically speaking, the message's segments will be "full" after calling this function. Calling this on your own + * may void your warranty. + * + * @param {Message} m The message to allocate. + * @returns {void} + */ +function preallocateSegments(m) { + const numSegments = arena_1.Arena.getNumSegments(m._capnp.arena); + if (numSegments < 1) + throw new Error(errors_1.MSG_NO_SEGMENTS_IN_ARENA); + m._capnp.segments = new Array(numSegments); + for (let i = 0; i < numSegments; i++) { + // Set up each segment so that they're fully allocated to the extents of the existing buffers. + const buffer = arena_1.Arena.getBuffer(i, m._capnp.arena); + const segment = new segment_1.Segment(i, m, buffer, buffer.byteLength); + m._capnp.segments[i] = segment; + } +} +exports.preallocateSegments = preallocateSegments; +function isArrayBufferView(src) { + return src.byteOffset !== undefined; +} +function isAnyArena(o) { + return o.kind !== undefined; +} +function allocateSegment(byteLength, m) { + trace("allocating %x bytes for %s", byteLength, m); + const res = arena_1.Arena.allocate(byteLength, m._capnp.segments, m._capnp.arena); + let s; + if (res.id === m._capnp.segments.length) { + // Note how we're only allowing new segments in if they're exactly the next one in the array. There is no logical + // reason for segments to be created out of order. + s = new segment_1.Segment(res.id, m, res.buffer); + trace("adding new segment %s", s); + m._capnp.segments.push(s); + } + else if (res.id < 0 || res.id > m._capnp.segments.length) { + throw new Error(util_1.format(errors_1.MSG_SEGMENT_OUT_OF_BOUNDS, res.id, m)); + } + else { + s = m._capnp.segments[res.id]; + trace("replacing segment %s with buffer (len:%d)", s, res.buffer.byteLength); + s.replaceBuffer(res.buffer); + } + return s; +} +exports.allocateSegment = allocateSegment; +function dump(m) { + let r = ""; + if (m._capnp.segments.length === 0) { + return "================\nNo Segments\n================\n"; + } + for (let i = 0; i < m._capnp.segments.length; i++) { + r += `================\nSegment #${i}\n================\n`; + const { buffer, byteLength } = m._capnp.segments[i]; + const b = new Uint8Array(buffer, 0, byteLength); + r += util_1.dumpBuffer(b); + } + return r; +} +exports.dump = dump; +function getRoot(RootStruct, m) { + const root = new RootStruct(m.getSegment(0), 0); + pointer_1.validate(pointers_1.PointerType.STRUCT, root); + const ts = pointer_1.getTargetStructSize(root); + // Make sure the underlying pointer is actually big enough to hold the data and pointers as specified in the schema. + // If not a shallow copy of the struct contents needs to be made before returning. + if (ts.dataByteLength < RootStruct._capnp.size.dataByteLength || + ts.pointerLength < RootStruct._capnp.size.pointerLength) { + trace("need to resize root struct %s", root); + struct_1.resize(RootStruct._capnp.size, root); + } + return root; +} +exports.getRoot = getRoot; +function getSegment(id, m) { + const segmentLength = m._capnp.segments.length; + if (id === 0 && segmentLength === 0) { + // Segment zero is special. If we have no segments in the arena we'll want to allocate a new one and leave room + // for the root pointer. + const arenaSegments = arena_1.Arena.getNumSegments(m._capnp.arena); + if (arenaSegments === 0) { + allocateSegment(constants_1.DEFAULT_BUFFER_SIZE, m); + } + else { + // Okay, the arena already has a buffer we can use. This is totally fine. + m._capnp.segments[0] = new segment_1.Segment(0, m, arena_1.Arena.getBuffer(0, m._capnp.arena)); + } + if (!m._capnp.segments[0].hasCapacity(8)) { + throw new Error(errors_1.MSG_SEGMENT_TOO_SMALL); + } + // This will leave room for the root pointer. + m._capnp.segments[0].allocate(8); + return m._capnp.segments[0]; + } + if (id < 0 || id >= segmentLength) { + throw new Error(util_1.format(errors_1.MSG_SEGMENT_OUT_OF_BOUNDS, id, m)); + } + return m._capnp.segments[id]; +} +exports.getSegment = getSegment; +function initRoot(RootStruct, m) { + const root = new RootStruct(m.getSegment(0), 0); + struct_1.initStruct(RootStruct._capnp.size, root); + trace("Initialized root pointer %s for %s.", root, m); + return root; +} +exports.initRoot = initRoot; +/** + * Read a pointer in raw form (a packed message with framing headers). Does not + * care or attempt to validate the input beyond parsing the message + * segments. + * + * This is typically used by the compiler to load default values, but can be + * useful to work with messages with an unknown schema. + * + * @param {ArrayBuffer} data The raw data to read. + * @returns {Pointer} A root pointer. + */ +function readRawPointer(data) { + return new pointers_1.Pointer(new Message(data).getSegment(0), 0); +} +exports.readRawPointer = readRawPointer; +function setRoot(src, m) { + pointers_1.Pointer.copyFrom(src, new pointers_1.Pointer(m.getSegment(0), 0)); +} +exports.setRoot = setRoot; +function toArrayBuffer(m) { + const streamFrame = getStreamFrame(m); + // Make sure the first segment is allocated. + if (m._capnp.segments.length === 0) + getSegment(0, m); + const segments = m._capnp.segments; + // Add space for the stream framing. + const totalLength = streamFrame.byteLength + segments.reduce((l, s) => l + util_1.padToWord(s.byteLength), 0); + const out = new Uint8Array(new ArrayBuffer(totalLength)); + let o = streamFrame.byteLength; + out.set(new Uint8Array(streamFrame)); + segments.forEach((s) => { + const segmentLength = util_1.padToWord(s.byteLength); + out.set(new Uint8Array(s.buffer, 0, segmentLength), o); + o += segmentLength; + }); + return out.buffer; +} +exports.toArrayBuffer = toArrayBuffer; +function toPackedArrayBuffer(m) { + const streamFrame = packing_1.pack(getStreamFrame(m)); + // Make sure the first segment is allocated. + if (m._capnp.segments.length === 0) + m.getSegment(0); + // NOTE: A copy operation can be avoided here if we capture the intermediate array and use that directly in the copy + // loop below, rather than have `pack()` copy it to an ArrayBuffer just to have to copy it again later. If the + // intermediate array can be avoided altogether that's even better! + const segments = m._capnp.segments.map((s) => packing_1.pack(s.buffer, 0, util_1.padToWord(s.byteLength))); + const totalLength = streamFrame.byteLength + segments.reduce((l, s) => l + s.byteLength, 0); + const out = new Uint8Array(new ArrayBuffer(totalLength)); + let o = streamFrame.byteLength; + out.set(new Uint8Array(streamFrame)); + segments.forEach((s) => { + out.set(new Uint8Array(s), o); + o += s.byteLength; + }); + return out.buffer; +} +exports.toPackedArrayBuffer = toPackedArrayBuffer; +function getStreamFrame(m) { + const length = m._capnp.segments.length; + if (length === 0) { + // Don't bother allocating the first segment, just return a single zero word for the frame header. + return new Float64Array(1).buffer; + } + const frameLength = 4 + length * 4 + (1 - (length % 2)) * 4; + const out = new DataView(new ArrayBuffer(frameLength)); + trace("Writing message stream frame with segment count: %d.", length); + out.setUint32(0, length - 1, true); + m._capnp.segments.forEach((s, i) => { + trace("Message segment %d word count: %d.", s.id, s.byteLength / 8); + out.setUint32(i * 4 + 4, s.byteLength / 8, true); + }); + return out.buffer; +} +exports.getStreamFrame = getStreamFrame; +//# sourceMappingURL=message.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/message.js.map b/node_modules/capnp-ts/src/serialization/message.js.map new file mode 100644 index 0000000..9d42066 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/message.js.map @@ -0,0 +1 @@ +{"version":3,"file":"message.js","sourceRoot":"","sources":["message.ts"],"names":[],"mappings":";AAAA;;GA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message.ts b/node_modules/capnp-ts/src/serialization/message.ts new file mode 100644 index 0000000..20e56a2 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/message.ts @@ -0,0 +1,507 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; +import { DEFAULT_TRAVERSE_LIMIT, DEFAULT_BUFFER_SIZE } from "../constants"; +import { + MSG_INVALID_FRAME_HEADER, + MSG_SEGMENT_OUT_OF_BOUNDS, + MSG_SEGMENT_TOO_SMALL, + MSG_NO_SEGMENTS_IN_ARENA, +} from "../errors"; +import { dumpBuffer, format, padToWord } from "../util"; +import { AnyArena, Arena, MultiSegmentArena, SingleSegmentArena, ArenaKind } from "./arena"; +import { pack, unpack } from "./packing"; +import { Pointer, StructCtor, PointerType, Struct } from "./pointers"; +import { Segment } from "./segment"; +import { getTargetStructSize, validate } from "./pointers/pointer"; +import { resize, initStruct } from "./pointers/struct"; + +const trace = initTrace("capnp:message"); +trace("load"); + +export interface _Message { + readonly arena: AnyArena; + segments: Segment[]; + traversalLimit: number; +} + +export class Message { + static readonly allocateSegment = allocateSegment; + static readonly dump = dump; + static readonly getRoot = getRoot; + static readonly getSegment = getSegment; + static readonly initRoot = initRoot; + static readonly readRawPointer = readRawPointer; + static readonly toArrayBuffer = toArrayBuffer; + static readonly toPackedArrayBuffer = toPackedArrayBuffer; + + readonly _capnp: _Message; + + /** + * A Cap'n Proto message. + * + * SECURITY WARNING: In nodejs do not pass a Buffer's internal array buffer into this constructor. Pass the buffer + * directly and everything will be fine. If not, your message will potentially be initialized with random memory + * contents! + * + * The constructor method creates a new Message, optionally using a provided arena for segment allocation, or a buffer + * to read from. + * + * @constructor {Message} + * + * @param {AnyArena|ArrayBufferView|ArrayBuffer} [src] The source for the message. + * A value of `undefined` will cause the message to initialize with a single segment arena only big enough for the + * root pointer; it will expand as you go. This is a reasonable choice for most messages. + * + * Passing an arena will cause the message to use that arena for its segment allocation. Contents will be accepted + * as-is. + * + * Passing an array buffer view (like `DataView`, `Uint8Array` or `Buffer`) will create a **copy** of the source + * buffer; beware of the potential performance cost! + * + * @param {boolean} [packed] Whether or not the message is packed. If `true` (the default), the message will be + * unpacked. + * + * @param {boolean} [singleSegment] If true, `src` will be treated as a message consisting of a single segment without + * a framing header. + * + */ + constructor(src?: AnyArena | ArrayBufferView | ArrayBuffer, packed = true, singleSegment = false) { + this._capnp = initMessage(src, packed, singleSegment); + + if (src && !isAnyArena(src)) preallocateSegments(this); + + trace("new %s", this); + } + + allocateSegment(byteLength: number): Segment { + return allocateSegment(byteLength, this); + } + + /** + * Create a pretty-printed string dump of this message; incredibly useful for debugging. + * + * WARNING: Do not call this method on large messages! + * + * @returns {string} A big steaming pile of pretty hex digits. + */ + + dump(): string { + return dump(this); + } + + /** + * Get a struct pointer for the root of this message. This is primarily used when reading a message; it will not + * overwrite existing data. + * + * @template T + * @param {StructCtor<T>} RootStruct The struct type to use as the root. + * @returns {T} A struct representing the root of the message. + */ + + getRoot<T extends Struct>(RootStruct: StructCtor<T>): T { + return getRoot(RootStruct, this); + } + + /** + * Get a segment by its id. + * + * This will lazily allocate the first segment if it doesn't already exist. + * + * @param {number} id The segment id. + * @returns {Segment} The requested segment. + */ + + getSegment(id: number): Segment { + return getSegment(id, this); + } + + /** + * Initialize a new message using the provided struct type as the root. + * + * @template T + * @param {StructCtor<T>} RootStruct The struct type to use as the root. + * @returns {T} An initialized struct pointing to the root of the message. + */ + + initRoot<T extends Struct>(RootStruct: StructCtor<T>): T { + return initRoot(RootStruct, this); + } + + /** + * Set the root of the message to a copy of the given pointer. Used internally + * to make copies of pointers for default values. + * + * @param {Pointer} src The source pointer to copy. + * @returns {void} + */ + + setRoot(src: Pointer): void { + setRoot(src, this); + } + + /** + * Combine the contents of this message's segments into a single array buffer and prepend a stream framing header + * containing information about the following segment data. + * + * @returns {ArrayBuffer} An ArrayBuffer with the contents of this message. + */ + + toArrayBuffer(): ArrayBuffer { + return toArrayBuffer(this); + } + + /** + * Like `toArrayBuffer()`, but also applies the packing algorithm to the output. This is typically what you want to + * use if you're sending the message over a network link or other slow I/O interface where size matters. + * + * @returns {ArrayBuffer} A packed message. + */ + + toPackedArrayBuffer(): ArrayBuffer { + return toPackedArrayBuffer(this); + } + + toString(): string { + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions + return `Message_arena:${this._capnp.arena}`; + } +} + +export interface CreateMessageOptions { + packed?: boolean; + singleSegment?: boolean; +} + +export function initMessage( + src?: AnyArena | ArrayBufferView | ArrayBuffer, + packed = true, + singleSegment = false +): _Message { + if (src === undefined) { + return { + arena: new SingleSegmentArena(), + segments: [], + traversalLimit: DEFAULT_TRAVERSE_LIMIT, + }; + } + + if (isAnyArena(src)) { + return { arena: src, segments: [], traversalLimit: DEFAULT_TRAVERSE_LIMIT }; + } + + let buf: ArrayBuffer = src as ArrayBuffer; + + if (isArrayBufferView(buf)) { + buf = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength); + } + + if (packed) buf = unpack(buf); + + if (singleSegment) { + return { + arena: new SingleSegmentArena(buf), + segments: [], + traversalLimit: DEFAULT_TRAVERSE_LIMIT, + }; + } + + return { + arena: new MultiSegmentArena(getFramedSegments(buf)), + segments: [], + traversalLimit: DEFAULT_TRAVERSE_LIMIT, + }; +} + +/** + * Given an _unpacked_ message with a segment framing header, this will generate an ArrayBuffer for each segment in + * the message. + * + * This method is not typically called directly, but can be useful in certain cases. + * + * @static + * @param {ArrayBuffer} message An unpacked message with a framing header. + * @returns {ArrayBuffer[]} An array of buffers containing the segment data. + */ + +export function getFramedSegments(message: ArrayBuffer): ArrayBuffer[] { + const dv = new DataView(message); + + const segmentCount = dv.getUint32(0, true) + 1; + + const segments = new Array(segmentCount) as ArrayBuffer[]; + + trace("reading %d framed segments from stream", segmentCount); + + let byteOffset = 4 + segmentCount * 4; + byteOffset += byteOffset % 8; + + if (byteOffset + segmentCount * 4 > message.byteLength) { + throw new Error(MSG_INVALID_FRAME_HEADER); + } + + for (let i = 0; i < segmentCount; i++) { + const byteLength = dv.getUint32(4 + i * 4, true) * 8; + + if (byteOffset + byteLength > message.byteLength) { + throw new Error(MSG_INVALID_FRAME_HEADER); + } + + segments[i] = message.slice(byteOffset, byteOffset + byteLength); + + byteOffset += byteLength; + } + + return segments; +} + +/** + * This method is called on messages that were constructed with existing data to prepopulate the segments array with + * everything we can find in the arena. Each segment will have it's `byteLength` set to the size of its buffer. + * + * Technically speaking, the message's segments will be "full" after calling this function. Calling this on your own + * may void your warranty. + * + * @param {Message} m The message to allocate. + * @returns {void} + */ + +export function preallocateSegments(m: Message): void { + const numSegments = Arena.getNumSegments(m._capnp.arena); + + if (numSegments < 1) throw new Error(MSG_NO_SEGMENTS_IN_ARENA); + + m._capnp.segments = new Array(numSegments) as Segment[]; + + for (let i = 0; i < numSegments; i++) { + // Set up each segment so that they're fully allocated to the extents of the existing buffers. + + const buffer = Arena.getBuffer(i, m._capnp.arena); + const segment = new Segment(i, m, buffer, buffer.byteLength); + + m._capnp.segments[i] = segment; + } +} + +function isArrayBufferView(src: ArrayBuffer | ArrayBufferView): src is ArrayBufferView { + return (src as { byteOffset?: number }).byteOffset !== undefined; +} + +function isAnyArena(o: unknown): o is AnyArena { + return (o as { kind?: ArenaKind }).kind !== undefined; +} + +export function allocateSegment(byteLength: number, m: Message): Segment { + trace("allocating %x bytes for %s", byteLength, m); + + const res = Arena.allocate(byteLength, m._capnp.segments, m._capnp.arena); + let s: Segment; + + if (res.id === m._capnp.segments.length) { + // Note how we're only allowing new segments in if they're exactly the next one in the array. There is no logical + // reason for segments to be created out of order. + + s = new Segment(res.id, m, res.buffer); + + trace("adding new segment %s", s); + + m._capnp.segments.push(s); + } else if (res.id < 0 || res.id > m._capnp.segments.length) { + throw new Error(format(MSG_SEGMENT_OUT_OF_BOUNDS, res.id, m)); + } else { + s = m._capnp.segments[res.id]; + + trace("replacing segment %s with buffer (len:%d)", s, res.buffer.byteLength); + + s.replaceBuffer(res.buffer); + } + + return s; +} + +export function dump(m: Message): string { + let r = ""; + + if (m._capnp.segments.length === 0) { + return "================\nNo Segments\n================\n"; + } + + for (let i = 0; i < m._capnp.segments.length; i++) { + r += `================\nSegment #${i}\n================\n`; + + const { buffer, byteLength } = m._capnp.segments[i]; + const b = new Uint8Array(buffer, 0, byteLength); + + r += dumpBuffer(b); + } + + return r; +} + +export function getRoot<T extends Struct>(RootStruct: StructCtor<T>, m: Message): T { + const root = new RootStruct(m.getSegment(0), 0); + + validate(PointerType.STRUCT, root); + + const ts = getTargetStructSize(root); + + // Make sure the underlying pointer is actually big enough to hold the data and pointers as specified in the schema. + // If not a shallow copy of the struct contents needs to be made before returning. + + if ( + ts.dataByteLength < RootStruct._capnp.size.dataByteLength || + ts.pointerLength < RootStruct._capnp.size.pointerLength + ) { + trace("need to resize root struct %s", root); + + resize(RootStruct._capnp.size, root); + } + + return root; +} + +export function getSegment(id: number, m: Message): Segment { + const segmentLength = m._capnp.segments.length; + + if (id === 0 && segmentLength === 0) { + // Segment zero is special. If we have no segments in the arena we'll want to allocate a new one and leave room + // for the root pointer. + + const arenaSegments = Arena.getNumSegments(m._capnp.arena); + + if (arenaSegments === 0) { + allocateSegment(DEFAULT_BUFFER_SIZE, m); + } else { + // Okay, the arena already has a buffer we can use. This is totally fine. + + m._capnp.segments[0] = new Segment(0, m, Arena.getBuffer(0, m._capnp.arena)); + } + + if (!m._capnp.segments[0].hasCapacity(8)) { + throw new Error(MSG_SEGMENT_TOO_SMALL); + } + + // This will leave room for the root pointer. + + m._capnp.segments[0].allocate(8); + + return m._capnp.segments[0]; + } + + if (id < 0 || id >= segmentLength) { + throw new Error(format(MSG_SEGMENT_OUT_OF_BOUNDS, id, m)); + } + + return m._capnp.segments[id]; +} + +export function initRoot<T extends Struct>(RootStruct: StructCtor<T>, m: Message): T { + const root = new RootStruct(m.getSegment(0), 0); + + initStruct(RootStruct._capnp.size, root); + + trace("Initialized root pointer %s for %s.", root, m); + + return root; +} + +/** + * Read a pointer in raw form (a packed message with framing headers). Does not + * care or attempt to validate the input beyond parsing the message + * segments. + * + * This is typically used by the compiler to load default values, but can be + * useful to work with messages with an unknown schema. + * + * @param {ArrayBuffer} data The raw data to read. + * @returns {Pointer} A root pointer. + */ + +export function readRawPointer(data: ArrayBuffer): Pointer { + return new Pointer(new Message(data).getSegment(0), 0); +} + +export function setRoot(src: Pointer, m: Message): void { + Pointer.copyFrom(src, new Pointer(m.getSegment(0), 0)); +} + +export function toArrayBuffer(m: Message): ArrayBuffer { + const streamFrame = getStreamFrame(m); + + // Make sure the first segment is allocated. + + if (m._capnp.segments.length === 0) getSegment(0, m); + + const segments = m._capnp.segments; + + // Add space for the stream framing. + + const totalLength = streamFrame.byteLength + segments.reduce((l, s) => l + padToWord(s.byteLength), 0); + const out = new Uint8Array(new ArrayBuffer(totalLength)); + let o = streamFrame.byteLength; + + out.set(new Uint8Array(streamFrame)); + + segments.forEach((s) => { + const segmentLength = padToWord(s.byteLength); + out.set(new Uint8Array(s.buffer, 0, segmentLength), o); + + o += segmentLength; + }); + + return out.buffer; +} + +export function toPackedArrayBuffer(m: Message): ArrayBuffer { + const streamFrame = pack(getStreamFrame(m)); + + // Make sure the first segment is allocated. + + if (m._capnp.segments.length === 0) m.getSegment(0); + + // NOTE: A copy operation can be avoided here if we capture the intermediate array and use that directly in the copy + // loop below, rather than have `pack()` copy it to an ArrayBuffer just to have to copy it again later. If the + // intermediate array can be avoided altogether that's even better! + const segments = m._capnp.segments.map((s) => pack(s.buffer, 0, padToWord(s.byteLength))); + + const totalLength = streamFrame.byteLength + segments.reduce((l, s) => l + s.byteLength, 0); + const out = new Uint8Array(new ArrayBuffer(totalLength)); + let o = streamFrame.byteLength; + + out.set(new Uint8Array(streamFrame)); + + segments.forEach((s) => { + out.set(new Uint8Array(s), o); + + o += s.byteLength; + }); + + return out.buffer; +} + +export function getStreamFrame(m: Message): ArrayBuffer { + const length = m._capnp.segments.length; + + if (length === 0) { + // Don't bother allocating the first segment, just return a single zero word for the frame header. + + return new Float64Array(1).buffer; + } + + const frameLength = 4 + length * 4 + (1 - (length % 2)) * 4; + const out = new DataView(new ArrayBuffer(frameLength)); + + trace("Writing message stream frame with segment count: %d.", length); + + out.setUint32(0, length - 1, true); + + m._capnp.segments.forEach((s, i) => { + trace("Message segment %d word count: %d.", s.id, s.byteLength / 8); + + out.setUint32(i * 4 + 4, s.byteLength / 8, true); + }); + + return out.buffer; +} diff --git a/node_modules/capnp-ts/src/serialization/object-size.d.ts b/node_modules/capnp-ts/src/serialization/object-size.d.ts new file mode 100644 index 0000000..bd56f04 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/object-size.d.ts @@ -0,0 +1,21 @@ +/** + * @author jdiaz5513 + */ +/** + * A simple object that describes the size of a struct. + * + * @export + * @class ObjectSize + */ +export declare class ObjectSize { + /** The number of bytes required for the data section. */ + readonly dataByteLength: number; + /** The number of pointers in the object. */ + readonly pointerLength: number; + constructor(dataByteLength: number, pointerCount: number); + toString(): string; +} +export declare function getByteLength(o: ObjectSize): number; +export declare function getDataWordLength(o: ObjectSize): number; +export declare function getWordLength(o: ObjectSize): number; +export declare function padToWord(o: ObjectSize): ObjectSize; diff --git a/node_modules/capnp-ts/src/serialization/object-size.js b/node_modules/capnp-ts/src/serialization/object-size.js new file mode 100644 index 0000000..2a41040 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/object-size.js @@ -0,0 +1,44 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.padToWord = exports.getWordLength = exports.getDataWordLength = exports.getByteLength = exports.ObjectSize = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const _ = tslib_1.__importStar(require("../util")); +const trace = debug_1.default("capnp:object-size"); +trace("load"); +/** + * A simple object that describes the size of a struct. + * + * @export + * @class ObjectSize + */ +class ObjectSize { + constructor(dataByteLength, pointerCount) { + this.dataByteLength = dataByteLength; + this.pointerLength = pointerCount; + } + toString() { + return _.format("ObjectSize_dw:%d,pc:%d", getDataWordLength(this), this.pointerLength); + } +} +exports.ObjectSize = ObjectSize; +function getByteLength(o) { + return o.dataByteLength + o.pointerLength * 8; +} +exports.getByteLength = getByteLength; +function getDataWordLength(o) { + return o.dataByteLength / 8; +} +exports.getDataWordLength = getDataWordLength; +function getWordLength(o) { + return o.dataByteLength / 8 + o.pointerLength; +} +exports.getWordLength = getWordLength; +function padToWord(o) { + return new ObjectSize(_.padToWord(o.dataByteLength), o.pointerLength); +} +exports.padToWord = padToWord; +//# sourceMappingURL=object-size.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/object-size.js.map b/node_modules/capnp-ts/src/serialization/object-size.js.map new file mode 100644 index 0000000..f0960e6 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/object-size.js.map @@ -0,0 +1 @@ +{"version":3,"file":"object-size.js","sourceRoot":"","sources":["object-size.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,mDAA6B;AAE7B,MAAM,KAAK,GAAG,eAAS,CAAC,mBAAmB,CAAC,CAAC;AAC7C,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd;;;;;GAKG;AAEH,MAAa,UAAU;IASrB,YAAY,cAAsB,EAAE,YAAoB;QACtD,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAED,QAAQ;QACN,OAAO,CAAC,CAAC,MAAM,CACb,wBAAwB,EACxB,iBAAiB,CAAC,IAAI,CAAC,EACvB,IAAI,CAAC,aAAa,CACnB,CAAC;IACJ,CAAC;CACF;AArBD,gCAqBC;AAED,SAAgB,aAAa,CAAC,CAAa;IACzC,OAAO,CAAC,CAAC,cAAc,GAAG,CAAC,CAAC,aAAa,GAAG,CAAC,CAAC;AAChD,CAAC;AAFD,sCAEC;AAED,SAAgB,iBAAiB,CAAC,CAAa;IAC7C,OAAO,CAAC,CAAC,cAAc,GAAG,CAAC,CAAC;AAC9B,CAAC;AAFD,8CAEC;AAED,SAAgB,aAAa,CAAC,CAAa;IACzC,OAAO,CAAC,CAAC,cAAc,GAAG,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC;AAChD,CAAC;AAFD,sCAEC;AAED,SAAgB,SAAS,CAAC,CAAa;IACrC,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC;AACxE,CAAC;AAFD,8BAEC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/object-size.ts b/node_modules/capnp-ts/src/serialization/object-size.ts new file mode 100644 index 0000000..1051a07 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/object-size.ts @@ -0,0 +1,56 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import * as _ from "../util"; + +const trace = initTrace("capnp:object-size"); +trace("load"); + +/** + * A simple object that describes the size of a struct. + * + * @export + * @class ObjectSize + */ + +export class ObjectSize { + /** The number of bytes required for the data section. */ + + readonly dataByteLength: number; + + /** The number of pointers in the object. */ + + readonly pointerLength: number; + + constructor(dataByteLength: number, pointerCount: number) { + this.dataByteLength = dataByteLength; + this.pointerLength = pointerCount; + } + + toString(): string { + return _.format( + "ObjectSize_dw:%d,pc:%d", + getDataWordLength(this), + this.pointerLength + ); + } +} + +export function getByteLength(o: ObjectSize): number { + return o.dataByteLength + o.pointerLength * 8; +} + +export function getDataWordLength(o: ObjectSize): number { + return o.dataByteLength / 8; +} + +export function getWordLength(o: ObjectSize): number { + return o.dataByteLength / 8 + o.pointerLength; +} + +export function padToWord(o: ObjectSize): ObjectSize { + return new ObjectSize(_.padToWord(o.dataByteLength), o.pointerLength); +} diff --git a/node_modules/capnp-ts/src/serialization/packing.d.ts b/node_modules/capnp-ts/src/serialization/packing.d.ts new file mode 100644 index 0000000..7127bda --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/packing.d.ts @@ -0,0 +1,78 @@ +/** + * @author jdiaz5513 + */ +/** + * Compute the Hamming weight (number of bits set to 1) of a number. Used to figure out how many bytes follow a tag byte + * while computing the size of a packed message. + * + * WARNING: Using this with floating point numbers will void your warranty. + * + * @param {number} x A real integer. + * @returns {number} The hamming weight (integer). + */ +export declare function getHammingWeight(x: number): number; +export declare type byte = number; +/** + * Compute the tag byte from the 8 bytes of a 64-bit word. + * + * @param {byte} a The first byte. + * @param {byte} b The second byte. + * @param {byte} c The third byte. + * @param {byte} d The fourth byte. + * @param {byte} e The fifth byte. + * @param {byte} f The sixth byte. + * @param {byte} g The seventh byte. + * @param {byte} h The eighth byte (phew!). + * @returns {number} The tag byte. + */ +export declare function getTagByte(a: byte, b: byte, c: byte, d: byte, e: byte, f: byte, g: byte, h: byte): number; +/** + * Efficiently calculate the length of a packed Cap'n Proto message. + * + * @export + * @param {ArrayBuffer} packed The packed message. + * @returns {number} The length of the unpacked message in bytes. + */ +export declare function getUnpackedByteLength(packed: ArrayBuffer): number; +/** + * Compute the number of zero bytes that occur in a given 64-bit word, provided as eight separate bytes. + * + * @param {byte} a The first byte. + * @param {byte} b The second byte. + * @param {byte} c The third byte. + * @param {byte} d The fourth byte. + * @param {byte} e The fifth byte. + * @param {byte} f The sixth byte. + * @param {byte} g The seventh byte. + * @param {byte} h The eighth byte (phew!). + * @returns {number} The number of these bytes that are zero. + */ +export declare function getZeroByteCount(a: byte, b: byte, c: byte, d: byte, e: byte, f: byte, g: byte, h: byte): number; +/** + * Pack a section of a Cap'n Proto message into a compressed format. This will efficiently compress zero bytes (which + * are common in idiomatic Cap'n Proto messages) into a compact form. + * + * For stream-framed messages this is called once for the frame header and once again for each segment in the message. + * + * The returned array buffer is trimmed to the exact size of the packed message with a single copy operation at the end. + * This should be decent on CPU time but does require quite a lot of memory (a normal array is filled up with each + * packed byte until the packing is complete). + * + * @export + * @param {ArrayBuffer} unpacked The message to pack. + * @param {number} [byteOffset] Starting byte offset to read bytes from, defaults to 0. + * @param {number} [byteLength] Total number of bytes to read, defaults to the remainder of the buffer contents. + * @returns {ArrayBuffer} A packed version of the message. + */ +export declare function pack(unpacked: ArrayBuffer, byteOffset?: number, byteLength?: number): ArrayBuffer; +/** + * Unpack a compressed Cap'n Proto message into a new ArrayBuffer. + * + * Unlike the `pack` function, this is able to efficiently determine the exact size needed for the output buffer and + * runs considerably more efficiently. + * + * @export + * @param {ArrayBuffer} packed An array buffer containing the packed message. + * @returns {ArrayBuffer} The unpacked message. + */ +export declare function unpack(packed: ArrayBuffer): ArrayBuffer; diff --git a/node_modules/capnp-ts/src/serialization/packing.js b/node_modules/capnp-ts/src/serialization/packing.js new file mode 100644 index 0000000..ac359d3 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/packing.js @@ -0,0 +1,274 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.unpack = exports.pack = exports.getZeroByteCount = exports.getUnpackedByteLength = exports.getTagByte = exports.getHammingWeight = void 0; +const constants_1 = require("../constants"); +const errors_1 = require("../errors"); +/** + * Compute the Hamming weight (number of bits set to 1) of a number. Used to figure out how many bytes follow a tag byte + * while computing the size of a packed message. + * + * WARNING: Using this with floating point numbers will void your warranty. + * + * @param {number} x A real integer. + * @returns {number} The hamming weight (integer). + */ +function getHammingWeight(x) { + // Thanks, HACKMEM! + let w = x - ((x >> 1) & 0x55555555); + w = (w & 0x33333333) + ((w >> 2) & 0x33333333); + return (((w + (w >> 4)) & 0x0f0f0f0f) * 0x01010101) >> 24; +} +exports.getHammingWeight = getHammingWeight; +/** + * Compute the tag byte from the 8 bytes of a 64-bit word. + * + * @param {byte} a The first byte. + * @param {byte} b The second byte. + * @param {byte} c The third byte. + * @param {byte} d The fourth byte. + * @param {byte} e The fifth byte. + * @param {byte} f The sixth byte. + * @param {byte} g The seventh byte. + * @param {byte} h The eighth byte (phew!). + * @returns {number} The tag byte. + */ +function getTagByte(a, b, c, d, e, f, g, h) { + // Yes, it's pretty. Don't touch it. + return ((a === 0 ? 0 : 0b00000001) | + (b === 0 ? 0 : 0b00000010) | + (c === 0 ? 0 : 0b00000100) | + (d === 0 ? 0 : 0b00001000) | + (e === 0 ? 0 : 0b00010000) | + (f === 0 ? 0 : 0b00100000) | + (g === 0 ? 0 : 0b01000000) | + (h === 0 ? 0 : 0b10000000)); +} +exports.getTagByte = getTagByte; +/** + * Efficiently calculate the length of a packed Cap'n Proto message. + * + * @export + * @param {ArrayBuffer} packed The packed message. + * @returns {number} The length of the unpacked message in bytes. + */ +function getUnpackedByteLength(packed) { + const p = new Uint8Array(packed); + let wordLength = 0; + let lastTag = 0x77; + for (let i = 0; i < p.byteLength;) { + const tag = p[i]; + if (lastTag === 0 /* ZERO */) { + wordLength += tag; + i++; + lastTag = 0x77; + } + else if (lastTag === 255 /* SPAN */) { + wordLength += tag; + i += tag * 8 + 1; + lastTag = 0x77; + } + else { + wordLength++; + i += getHammingWeight(tag) + 1; + lastTag = tag; + } + } + return wordLength * 8; +} +exports.getUnpackedByteLength = getUnpackedByteLength; +/** + * Compute the number of zero bytes that occur in a given 64-bit word, provided as eight separate bytes. + * + * @param {byte} a The first byte. + * @param {byte} b The second byte. + * @param {byte} c The third byte. + * @param {byte} d The fourth byte. + * @param {byte} e The fifth byte. + * @param {byte} f The sixth byte. + * @param {byte} g The seventh byte. + * @param {byte} h The eighth byte (phew!). + * @returns {number} The number of these bytes that are zero. + */ +function getZeroByteCount(a, b, c, d, e, f, g, h) { + return ((a === 0 ? 1 : 0) + + (b === 0 ? 1 : 0) + + (c === 0 ? 1 : 0) + + (d === 0 ? 1 : 0) + + (e === 0 ? 1 : 0) + + (f === 0 ? 1 : 0) + + (g === 0 ? 1 : 0) + + (h === 0 ? 1 : 0)); +} +exports.getZeroByteCount = getZeroByteCount; +/** + * Pack a section of a Cap'n Proto message into a compressed format. This will efficiently compress zero bytes (which + * are common in idiomatic Cap'n Proto messages) into a compact form. + * + * For stream-framed messages this is called once for the frame header and once again for each segment in the message. + * + * The returned array buffer is trimmed to the exact size of the packed message with a single copy operation at the end. + * This should be decent on CPU time but does require quite a lot of memory (a normal array is filled up with each + * packed byte until the packing is complete). + * + * @export + * @param {ArrayBuffer} unpacked The message to pack. + * @param {number} [byteOffset] Starting byte offset to read bytes from, defaults to 0. + * @param {number} [byteLength] Total number of bytes to read, defaults to the remainder of the buffer contents. + * @returns {ArrayBuffer} A packed version of the message. + */ +function pack(unpacked, byteOffset = 0, byteLength) { + if (unpacked.byteLength % 8 !== 0) + throw new Error(errors_1.MSG_PACK_NOT_WORD_ALIGNED); + const src = new Uint8Array(unpacked, byteOffset, byteLength); + // TODO: Maybe we should do this with buffers? This costs more than 8x the final compressed size in temporary RAM. + const dst = []; + /* Just have to be sure it's neither ZERO nor SPAN. */ + let lastTag = 0x77; + /** This is where we need to remember to write the SPAN tag (0xff). */ + let spanTagOffset = NaN; + /** How many words have been copied during the current span. */ + let spanWordLength = 0; + /** + * When this hits zero, we've had PACK_SPAN_THRESHOLD zero bytes pass by and it's time to bail from the span. + */ + let spanThreshold = constants_1.PACK_SPAN_THRESHOLD; + for (let srcByteOffset = 0; srcByteOffset < src.byteLength; srcByteOffset += 8) { + /** Read in the entire word. Yes, this feels silly but it's fast! */ + const a = src[srcByteOffset]; + const b = src[srcByteOffset + 1]; + const c = src[srcByteOffset + 2]; + const d = src[srcByteOffset + 3]; + const e = src[srcByteOffset + 4]; + const f = src[srcByteOffset + 5]; + const g = src[srcByteOffset + 6]; + const h = src[srcByteOffset + 7]; + const tag = getTagByte(a, b, c, d, e, f, g, h); + /** If this is true we'll skip the normal word write logic after the switch statement. */ + let skipWriteWord = true; + switch (lastTag) { + case 0 /* ZERO */: + // We're writing a span of words with all zeroes in them. See if we need to bail out of the fast path. + if (tag !== 0 /* ZERO */ || spanWordLength >= 0xff) { + // There's a bit in there or we got too many zeroes. Damn, we need to bail. + dst.push(spanWordLength); + spanWordLength = 0; + skipWriteWord = false; + } + else { + // Kay, let's quickly inc this and go. + spanWordLength++; + } + break; + case 255 /* SPAN */: { + // We're writing a span of nonzero words. + const zeroCount = getZeroByteCount(a, b, c, d, e, f, g, h); + // See if we need to bail now. + spanThreshold -= zeroCount; + if (spanThreshold <= 0 || spanWordLength >= 0xff) { + // Alright, time to get packing again. Write the number of words we skipped to the beginning of the span. + dst[spanTagOffset] = spanWordLength; + spanWordLength = 0; + spanThreshold = constants_1.PACK_SPAN_THRESHOLD; + // We have to write this word normally. + skipWriteWord = false; + } + else { + // Just write this word verbatim. + dst.push(a, b, c, d, e, f, g, h); + spanWordLength++; + } + break; + } + default: + // Didn't get a special tag last time, let's write this as normal. + skipWriteWord = false; + break; + } + // A goto is fast, idk why people keep hatin'. + if (skipWriteWord) + continue; + dst.push(tag); + lastTag = tag; + if (a !== 0) + dst.push(a); + if (b !== 0) + dst.push(b); + if (c !== 0) + dst.push(c); + if (d !== 0) + dst.push(d); + if (e !== 0) + dst.push(e); + if (f !== 0) + dst.push(f); + if (g !== 0) + dst.push(g); + if (h !== 0) + dst.push(h); + // Record the span tag offset if needed, making sure to actually leave room for it. + if (tag === 255 /* SPAN */) { + spanTagOffset = dst.length; + dst.push(0); + } + } + // We're done. If we were writing a span let's finish it. + if (lastTag === 0 /* ZERO */) { + dst.push(spanWordLength); + } + else if (lastTag === 255 /* SPAN */) { + dst[spanTagOffset] = spanWordLength; + } + return new Uint8Array(dst).buffer; +} +exports.pack = pack; +/** + * Unpack a compressed Cap'n Proto message into a new ArrayBuffer. + * + * Unlike the `pack` function, this is able to efficiently determine the exact size needed for the output buffer and + * runs considerably more efficiently. + * + * @export + * @param {ArrayBuffer} packed An array buffer containing the packed message. + * @returns {ArrayBuffer} The unpacked message. + */ +function unpack(packed) { + // We have no choice but to read the packed buffer one byte at a time. + const src = new Uint8Array(packed); + const dst = new Uint8Array(new ArrayBuffer(getUnpackedByteLength(packed))); + /** The last tag byte that we've seen - it starts at a "neutral" value. */ + let lastTag = 0x77; + for (let srcByteOffset = 0, dstByteOffset = 0; srcByteOffset < src.byteLength;) { + const tag = src[srcByteOffset]; + if (lastTag === 0 /* ZERO */) { + // We have a span of zeroes. New array buffers are guaranteed to be initialized to zero so we just seek ahead. + dstByteOffset += tag * 8; + srcByteOffset++; + lastTag = 0x77; + } + else if (lastTag === 255 /* SPAN */) { + // We have a span of unpacked bytes. Copy them verbatim from the source buffer. + const spanByteLength = tag * 8; + dst.set(src.subarray(srcByteOffset + 1, srcByteOffset + 1 + spanByteLength), dstByteOffset); + dstByteOffset += spanByteLength; + srcByteOffset += 1 + spanByteLength; + lastTag = 0x77; + } + else { + // Okay, a normal tag. Let's read past the tag and copy bytes that have a bit set in the tag. + srcByteOffset++; + for (let i = 1; i <= 0b10000000; i <<= 1) { + // We only need to actually touch `dst` if there's a nonzero byte (it's already initialized to zeroes). + if ((tag & i) !== 0) + dst[dstByteOffset] = src[srcByteOffset++]; + dstByteOffset++; + } + lastTag = tag; + } + } + return dst.buffer; +} +exports.unpack = unpack; +//# sourceMappingURL=packing.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/packing.js.map b/node_modules/capnp-ts/src/serialization/packing.js.map new file mode 100644 index 0000000..ce5c80d --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/packing.js.map @@ -0,0 +1 @@ +{"version":3,"file":"packing.js","sourceRoot":"","sources":["packing.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,4CAAmD;AACnD,sCAAsD;AAmCtD;;;;;;;;GAQG;AAEH,SAAgB,gBAAgB,CAAC,CAAS;IACxC,mBAAmB;IAEnB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC;IACpC,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC;IAC/C,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,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GAAG,CAAC,aAAa,CAAC,GAAG,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC;gBAE/D,aAAa,EAAE,CAAC;aACjB;YAED,OAAO,GAAG,GAAG,CAAC;SACf;KACF;IAED,OAAO,GAAG,CAAC,MAAM,CAAC;AACpB,CAAC;AAlDD,wBAkDC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/packing.ts b/node_modules/capnp-ts/src/serialization/packing.ts new file mode 100644 index 0000000..31e9b6d --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/packing.ts @@ -0,0 +1,372 @@ +/** + * @author jdiaz5513 + */ + +import { PACK_SPAN_THRESHOLD } from "../constants"; +import { MSG_PACK_NOT_WORD_ALIGNED } from "../errors"; + +/** + * When packing a message there are two tags that are interpreted in a special way: `0x00` and `0xff`. + * + * @enum {number} + */ + +const enum PackedTag { + /** + * The tag is followed by a single byte which indicates a count of consecutive zero-valued words, minus 1. E.g. if the + * tag 0x00 is followed by 0x05, the sequence unpacks to 6 words of zero. + * + * Or, put another way: the tag is first decoded as if it were not special. Since none of the bits are set, it is + * followed by no bytes and expands to a word full of zeros. After that, the next byte is interpreted as a count of + * additional words that are also all-zero. + */ + + ZERO = 0x00, + + /** + * The tag is followed by the bytes of the word (as if it weren’t special), but after those bytes is another byte with + * value N. Following that byte is N unpacked words that should be copied directly. + * + * These unpacked words may contain zeroes; in this implementation a minimum of PACK_SPAN_THRESHOLD zero bytes are + * written before ending the span. + * + * The purpose of this rule is to minimize the impact of packing on data that doesn’t contain any zeros – in + * particular, long text blobs. Because of this rule, the worst-case space overhead of packing is 2 bytes per 2 KiB of + * input (256 words = 2KiB). + */ + + SPAN = 0xff, +} + +/** + * Compute the Hamming weight (number of bits set to 1) of a number. Used to figure out how many bytes follow a tag byte + * while computing the size of a packed message. + * + * WARNING: Using this with floating point numbers will void your warranty. + * + * @param {number} x A real integer. + * @returns {number} The hamming weight (integer). + */ + +export function getHammingWeight(x: number): number { + // Thanks, HACKMEM! + + let w = x - ((x >> 1) & 0x55555555); + w = (w & 0x33333333) + ((w >> 2) & 0x33333333); + return (((w + (w >> 4)) & 0x0f0f0f0f) * 0x01010101) >> 24; +} + +export type byte = number; + +/** + * Compute the tag byte from the 8 bytes of a 64-bit word. + * + * @param {byte} a The first byte. + * @param {byte} b The second byte. + * @param {byte} c The third byte. + * @param {byte} d The fourth byte. + * @param {byte} e The fifth byte. + * @param {byte} f The sixth byte. + * @param {byte} g The seventh byte. + * @param {byte} h The eighth byte (phew!). + * @returns {number} The tag byte. + */ + +export function getTagByte(a: byte, b: byte, c: byte, d: byte, e: byte, f: byte, g: byte, h: byte): number { + // Yes, it's pretty. Don't touch it. + + return ( + (a === 0 ? 0 : 0b00000001) | + (b === 0 ? 0 : 0b00000010) | + (c === 0 ? 0 : 0b00000100) | + (d === 0 ? 0 : 0b00001000) | + (e === 0 ? 0 : 0b00010000) | + (f === 0 ? 0 : 0b00100000) | + (g === 0 ? 0 : 0b01000000) | + (h === 0 ? 0 : 0b10000000) + ); +} + +/** + * Efficiently calculate the length of a packed Cap'n Proto message. + * + * @export + * @param {ArrayBuffer} packed The packed message. + * @returns {number} The length of the unpacked message in bytes. + */ + +export function getUnpackedByteLength(packed: ArrayBuffer): number { + const p = new Uint8Array(packed); + let wordLength = 0; + let lastTag = 0x77; + + for (let i = 0; i < p.byteLength; ) { + const tag = p[i]; + + if (lastTag === PackedTag.ZERO) { + wordLength += tag; + + i++; + + lastTag = 0x77; + } else if (lastTag === PackedTag.SPAN) { + wordLength += tag; + + i += tag * 8 + 1; + + lastTag = 0x77; + } else { + wordLength++; + + i += getHammingWeight(tag) + 1; + + lastTag = tag; + } + } + + return wordLength * 8; +} + +/** + * Compute the number of zero bytes that occur in a given 64-bit word, provided as eight separate bytes. + * + * @param {byte} a The first byte. + * @param {byte} b The second byte. + * @param {byte} c The third byte. + * @param {byte} d The fourth byte. + * @param {byte} e The fifth byte. + * @param {byte} f The sixth byte. + * @param {byte} g The seventh byte. + * @param {byte} h The eighth byte (phew!). + * @returns {number} The number of these bytes that are zero. + */ + +export function getZeroByteCount(a: byte, b: byte, c: byte, d: byte, e: byte, f: byte, g: byte, h: byte): number { + return ( + (a === 0 ? 1 : 0) + + (b === 0 ? 1 : 0) + + (c === 0 ? 1 : 0) + + (d === 0 ? 1 : 0) + + (e === 0 ? 1 : 0) + + (f === 0 ? 1 : 0) + + (g === 0 ? 1 : 0) + + (h === 0 ? 1 : 0) + ); +} + +/** + * Pack a section of a Cap'n Proto message into a compressed format. This will efficiently compress zero bytes (which + * are common in idiomatic Cap'n Proto messages) into a compact form. + * + * For stream-framed messages this is called once for the frame header and once again for each segment in the message. + * + * The returned array buffer is trimmed to the exact size of the packed message with a single copy operation at the end. + * This should be decent on CPU time but does require quite a lot of memory (a normal array is filled up with each + * packed byte until the packing is complete). + * + * @export + * @param {ArrayBuffer} unpacked The message to pack. + * @param {number} [byteOffset] Starting byte offset to read bytes from, defaults to 0. + * @param {number} [byteLength] Total number of bytes to read, defaults to the remainder of the buffer contents. + * @returns {ArrayBuffer} A packed version of the message. + */ + +export function pack(unpacked: ArrayBuffer, byteOffset = 0, byteLength?: number): ArrayBuffer { + if (unpacked.byteLength % 8 !== 0) throw new Error(MSG_PACK_NOT_WORD_ALIGNED); + + const src = new Uint8Array(unpacked, byteOffset, byteLength); + + // TODO: Maybe we should do this with buffers? This costs more than 8x the final compressed size in temporary RAM. + + const dst: number[] = []; + + /* Just have to be sure it's neither ZERO nor SPAN. */ + + let lastTag = 0x77; + + /** This is where we need to remember to write the SPAN tag (0xff). */ + + let spanTagOffset = NaN; + + /** How many words have been copied during the current span. */ + + let spanWordLength = 0; + + /** + * When this hits zero, we've had PACK_SPAN_THRESHOLD zero bytes pass by and it's time to bail from the span. + */ + + let spanThreshold = PACK_SPAN_THRESHOLD; + + for (let srcByteOffset = 0; srcByteOffset < src.byteLength; srcByteOffset += 8) { + /** Read in the entire word. Yes, this feels silly but it's fast! */ + + const a = src[srcByteOffset]; + const b = src[srcByteOffset + 1]; + const c = src[srcByteOffset + 2]; + const d = src[srcByteOffset + 3]; + const e = src[srcByteOffset + 4]; + const f = src[srcByteOffset + 5]; + const g = src[srcByteOffset + 6]; + const h = src[srcByteOffset + 7]; + + const tag = getTagByte(a, b, c, d, e, f, g, h); + + /** If this is true we'll skip the normal word write logic after the switch statement. */ + + let skipWriteWord = true; + + switch (lastTag) { + case PackedTag.ZERO: + // We're writing a span of words with all zeroes in them. See if we need to bail out of the fast path. + + if (tag !== PackedTag.ZERO || spanWordLength >= 0xff) { + // There's a bit in there or we got too many zeroes. Damn, we need to bail. + + dst.push(spanWordLength); + spanWordLength = 0; + + skipWriteWord = false; + } else { + // Kay, let's quickly inc this and go. + + spanWordLength++; + } + + break; + + case PackedTag.SPAN: { + // We're writing a span of nonzero words. + + const zeroCount = getZeroByteCount(a, b, c, d, e, f, g, h); + + // See if we need to bail now. + + spanThreshold -= zeroCount; + + if (spanThreshold <= 0 || spanWordLength >= 0xff) { + // Alright, time to get packing again. Write the number of words we skipped to the beginning of the span. + + dst[spanTagOffset] = spanWordLength; + spanWordLength = 0; + + spanThreshold = PACK_SPAN_THRESHOLD; + + // We have to write this word normally. + + skipWriteWord = false; + } else { + // Just write this word verbatim. + + dst.push(a, b, c, d, e, f, g, h); + + spanWordLength++; + } + + break; + } + default: + // Didn't get a special tag last time, let's write this as normal. + + skipWriteWord = false; + + break; + } + + // A goto is fast, idk why people keep hatin'. + if (skipWriteWord) continue; + + dst.push(tag); + lastTag = tag; + + if (a !== 0) dst.push(a); + if (b !== 0) dst.push(b); + if (c !== 0) dst.push(c); + if (d !== 0) dst.push(d); + if (e !== 0) dst.push(e); + if (f !== 0) dst.push(f); + if (g !== 0) dst.push(g); + if (h !== 0) dst.push(h); + + // Record the span tag offset if needed, making sure to actually leave room for it. + + if (tag === PackedTag.SPAN) { + spanTagOffset = dst.length; + + dst.push(0); + } + } + + // We're done. If we were writing a span let's finish it. + + if (lastTag === PackedTag.ZERO) { + dst.push(spanWordLength); + } else if (lastTag === PackedTag.SPAN) { + dst[spanTagOffset] = spanWordLength; + } + + return new Uint8Array(dst).buffer; +} + +/** + * Unpack a compressed Cap'n Proto message into a new ArrayBuffer. + * + * Unlike the `pack` function, this is able to efficiently determine the exact size needed for the output buffer and + * runs considerably more efficiently. + * + * @export + * @param {ArrayBuffer} packed An array buffer containing the packed message. + * @returns {ArrayBuffer} The unpacked message. + */ + +export function unpack(packed: ArrayBuffer): ArrayBuffer { + // We have no choice but to read the packed buffer one byte at a time. + + const src = new Uint8Array(packed); + const dst = new Uint8Array(new ArrayBuffer(getUnpackedByteLength(packed))); + + /** The last tag byte that we've seen - it starts at a "neutral" value. */ + + let lastTag = 0x77; + + for (let srcByteOffset = 0, dstByteOffset = 0; srcByteOffset < src.byteLength; ) { + const tag = src[srcByteOffset]; + + if (lastTag === PackedTag.ZERO) { + // We have a span of zeroes. New array buffers are guaranteed to be initialized to zero so we just seek ahead. + + dstByteOffset += tag * 8; + + srcByteOffset++; + + lastTag = 0x77; + } else if (lastTag === PackedTag.SPAN) { + // We have a span of unpacked bytes. Copy them verbatim from the source buffer. + + const spanByteLength = tag * 8; + + dst.set(src.subarray(srcByteOffset + 1, srcByteOffset + 1 + spanByteLength), dstByteOffset); + + dstByteOffset += spanByteLength; + srcByteOffset += 1 + spanByteLength; + + lastTag = 0x77; + } else { + // Okay, a normal tag. Let's read past the tag and copy bytes that have a bit set in the tag. + + srcByteOffset++; + + for (let i = 1; i <= 0b10000000; i <<= 1) { + // We only need to actually touch `dst` if there's a nonzero byte (it's already initialized to zeroes). + + if ((tag & i) !== 0) dst[dstByteOffset] = src[srcByteOffset++]; + + dstByteOffset++; + } + + lastTag = tag; + } + } + + return dst.buffer; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.d.ts new file mode 100644 index 0000000..742faf1 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.d.ts @@ -0,0 +1,6 @@ +/** + * @author jdiaz5513 + */ +import { ListCtor } from "./list"; +import { Pointer } from "./pointer"; +export declare const AnyPointerList: ListCtor<Pointer>; diff --git a/node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.js b/node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.js new file mode 100644 index 0000000..cfc67c2 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.js @@ -0,0 +1,10 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.AnyPointerList = void 0; +const pointer_1 = require("./pointer"); +const pointer_list_1 = require("./pointer-list"); +exports.AnyPointerList = pointer_list_1.PointerList(pointer_1.Pointer); +//# sourceMappingURL=any-pointer-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.js.map new file mode 100644 index 0000000..3338c88 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"any-pointer-list.js","sourceRoot":"","sources":["any-pointer-list.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAGH,uCAAoC;AACpC,iDAA6C;AAEhC,QAAA,cAAc,GAAsB,0BAAW,CAAC,iBAAO,CAAC,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.ts b/node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.ts new file mode 100644 index 0000000..f9dc979 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.ts @@ -0,0 +1,9 @@ +/** + * @author jdiaz5513 + */ + +import { ListCtor } from "./list"; +import { Pointer } from "./pointer"; +import { PointerList } from "./pointer-list"; + +export const AnyPointerList: ListCtor<Pointer> = PointerList(Pointer); diff --git a/node_modules/capnp-ts/src/serialization/pointers/bool-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/bool-list.d.ts new file mode 100644 index 0000000..0a6548f --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/bool-list.d.ts @@ -0,0 +1,10 @@ +/** + * @author jdiaz5513 + */ +import { _ListCtor, List } from "./list"; +export declare class BoolList extends List<boolean> { + static readonly _capnp: _ListCtor; + get(index: number): boolean; + set(index: number, value: boolean): void; + toString(): string; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/bool-list.js b/node_modules/capnp-ts/src/serialization/pointers/bool-list.js new file mode 100644 index 0000000..e9ff3ca --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/bool-list.js @@ -0,0 +1,38 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.BoolList = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const list_element_size_1 = require("../list-element-size"); +const list_1 = require("./list"); +const pointer_1 = require("./pointer"); +const trace = debug_1.default("capnp:list:composite"); +trace("load"); +class BoolList extends list_1.List { + get(index) { + const bitMask = 1 << index % 8; + const byteOffset = index >>> 3; + const c = pointer_1.getContent(this); + const v = c.segment.getUint8(c.byteOffset + byteOffset); + return (v & bitMask) !== 0; + } + set(index, value) { + const bitMask = 1 << index % 8; + const c = pointer_1.getContent(this); + const byteOffset = c.byteOffset + (index >>> 3); + const v = c.segment.getUint8(byteOffset); + c.segment.setUint8(byteOffset, value ? v | bitMask : v & ~bitMask); + } + toString() { + return `Bool_${super.toString()}`; + } +} +exports.BoolList = BoolList; +BoolList._capnp = { + displayName: "List<boolean>", + size: list_element_size_1.ListElementSize.BIT +}; +//# sourceMappingURL=bool-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/bool-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/bool-list.js.map new file mode 100644 index 0000000..c280878 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/bool-list.js.map @@ -0,0 +1 @@ +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C,WAAW,EAAE,eAAyB;IACtC,IAAI,EAAE,mCAAe,CAAC,GAAG;CAC1B,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/bool-list.ts b/node_modules/capnp-ts/src/serialization/pointers/bool-list.ts new file mode 100644 index 0000000..26836bc --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/bool-list.ts @@ -0,0 +1,41 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { ListElementSize } from "../list-element-size"; +import { _ListCtor, List } from "./list"; +import { getContent } from "./pointer"; + +const trace = initTrace("capnp:list:composite"); +trace("load"); + +export class BoolList extends List<boolean> { + static readonly _capnp: _ListCtor = { + displayName: "List<boolean>" as string, + size: ListElementSize.BIT + }; + + get(index: number): boolean { + const bitMask = 1 << index % 8; + const byteOffset = index >>> 3; + const c = getContent(this); + const v = c.segment.getUint8(c.byteOffset + byteOffset); + + return (v & bitMask) !== 0; + } + + set(index: number, value: boolean): void { + const bitMask = 1 << index % 8; + const c = getContent(this); + const byteOffset = c.byteOffset + (index >>> 3); + const v = c.segment.getUint8(byteOffset); + + c.segment.setUint8(byteOffset, value ? v | bitMask : v & ~bitMask); + } + + toString(): string { + return `Bool_${super.toString()}`; + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/composite-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/composite-list.d.ts new file mode 100644 index 0000000..1031067 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/composite-list.d.ts @@ -0,0 +1,6 @@ +/** + * @author jdiaz5513 + */ +import { ListCtor } from "./list"; +import { Struct, StructCtor } from "./struct"; +export declare function CompositeList<T extends Struct>(CompositeClass: StructCtor<T>): ListCtor<T>; diff --git a/node_modules/capnp-ts/src/serialization/pointers/composite-list.js b/node_modules/capnp-ts/src/serialization/pointers/composite-list.js new file mode 100644 index 0000000..5e83117 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/composite-list.js @@ -0,0 +1,35 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.CompositeList = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const list_element_size_1 = require("../list-element-size"); +const list_1 = require("./list"); +const pointer_1 = require("./pointer"); +const trace = debug_1.default("capnp:list:composite"); +trace("load"); +function CompositeList(CompositeClass) { + var _a; + return _a = class extends list_1.List { + get(index) { + return new CompositeClass(this.segment, this.byteOffset, this._capnp.depthLimit - 1, index); + } + set(index, value) { + pointer_1.copyFrom(value, this.get(index)); + } + toString() { + return `Composite_${super.toString()},cls:${CompositeClass.toString()}`; + } + }, + _a._capnp = { + compositeSize: CompositeClass._capnp.size, + displayName: `List<${CompositeClass._capnp.displayName}>`, + size: list_element_size_1.ListElementSize.COMPOSITE, + }, + _a; +} +exports.CompositeList = CompositeList; +//# sourceMappingURL=composite-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/composite-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/composite-list.js.map new file mode 100644 index 0000000..359c5e6 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/composite-list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"composite-list.js","sourceRoot":"","sources":["composite-list.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,4DAAuD;AACvD,iCAAmD;AAEnD,uCAAqC;AAErC,MAAM,KAAK,GAAG,eAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,SAAgB,aAAa,CAAmB,cAA6B;;IAC3E,YAAO,KAAM,SAAQ,WAAO;YAO1B,GAAG,CAAC,KAAa;gBACf,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;YAC9F,CAAC;YAED,GAAG,CAAC,KAAa,EAAE,KAAQ;gBACzB,kBAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;YACnC,CAAC;YAED,QAAQ;gBACN,OAAO,aAAa,KAAK,CAAC,QAAQ,EAAE,QAAQ,cAAc,CAAC,QAAQ,EAAE,EAAE,CAAC;YAC1E,CAAC;SACF;QAjBiB,SAAM,GAAc;YAClC,aAAa,EAAE,cAAc,CAAC,MAAM,CAAC,IAAI;YACzC,WAAW,EAAE,QAAQ,cAAc,CAAC,MAAM,CAAC,WAAW,GAAG;YACzD,IAAI,EAAE,mCAAe,CAAC,SAAS;SAC/B;WAaF;AACJ,CAAC;AApBD,sCAoBC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/composite-list.ts b/node_modules/capnp-ts/src/serialization/pointers/composite-list.ts new file mode 100644 index 0000000..6338244 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/composite-list.ts @@ -0,0 +1,35 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { ListElementSize } from "../list-element-size"; +import { _ListCtor, List, ListCtor } from "./list"; +import { Struct, StructCtor } from "./struct"; +import { copyFrom } from "./pointer"; + +const trace = initTrace("capnp:list:composite"); +trace("load"); + +export function CompositeList<T extends Struct>(CompositeClass: StructCtor<T>): ListCtor<T> { + return class extends List<T> { + static readonly _capnp: _ListCtor = { + compositeSize: CompositeClass._capnp.size, + displayName: `List<${CompositeClass._capnp.displayName}>`, + size: ListElementSize.COMPOSITE, + }; + + get(index: number): T { + return new CompositeClass(this.segment, this.byteOffset, this._capnp.depthLimit - 1, index); + } + + set(index: number, value: T): void { + copyFrom(value, this.get(index)); + } + + toString(): string { + return `Composite_${super.toString()},cls:${CompositeClass.toString()}`; + } + }; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/data-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/data-list.d.ts new file mode 100644 index 0000000..f1381fa --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/data-list.d.ts @@ -0,0 +1,6 @@ +/** + * @author jdiaz5513 + */ +import { Data } from "./data"; +import { ListCtor } from "./list"; +export declare const DataList: ListCtor<Data>; diff --git a/node_modules/capnp-ts/src/serialization/pointers/data-list.js b/node_modules/capnp-ts/src/serialization/pointers/data-list.js new file mode 100644 index 0000000..62a66cb --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/data-list.js @@ -0,0 +1,10 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.DataList = void 0; +const data_1 = require("./data"); +const pointer_list_1 = require("./pointer-list"); +exports.DataList = pointer_list_1.PointerList(data_1.Data); +//# sourceMappingURL=data-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/data-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/data-list.js.map new file mode 100644 index 0000000..aac5762 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/data-list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"data-list.js","sourceRoot":"","sources":["data-list.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iCAA8B;AAE9B,iDAA6C;AAEhC,QAAA,QAAQ,GAAmB,0BAAW,CAAC,WAAI,CAAC,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/data-list.ts b/node_modules/capnp-ts/src/serialization/pointers/data-list.ts new file mode 100644 index 0000000..5115de7 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/data-list.ts @@ -0,0 +1,9 @@ +/** + * @author jdiaz5513 + */ + +import { Data } from "./data"; +import { ListCtor } from "./list"; +import { PointerList } from "./pointer-list"; + +export const DataList: ListCtor<Data> = PointerList(Data); diff --git a/node_modules/capnp-ts/src/serialization/pointers/data.d.ts b/node_modules/capnp-ts/src/serialization/pointers/data.d.ts new file mode 100644 index 0000000..0055412 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/data.d.ts @@ -0,0 +1,67 @@ +/** + * @author jdiaz5513 + */ +import { List } from "./list"; +import { Pointer } from "./pointer"; +/** + * A generic blob of bytes. Can be converted to a DataView or Uint8Array to access its contents using `toDataView()` and + * `toUint8Array()`. Use `copyBuffer()` to copy an entire buffer at once. + * + * @export + * @class Data + * @extends {List<number>} + */ +export declare class Data extends List<number> { + static fromPointer(pointer: Pointer): Data; + protected static _fromPointerUnchecked(pointer: Pointer): Data; + /** + * Copy the contents of `src` into this Data pointer. If `src` is smaller than the length of this pointer then the + * remaining bytes will be zeroed out. Extra bytes in `src` are ignored. + * + * @param {(ArrayBuffer | ArrayBufferView)} src The source buffer. + * @returns {void} + */ + copyBuffer(src: ArrayBuffer | ArrayBufferView): void; + /** + * Read a byte from the specified offset. + * + * @param {number} byteOffset The byte offset to read. + * @returns {number} The byte value. + */ + get(byteOffset: number): number; + /** + * Write a byte at the specified offset. + * + * @param {number} byteOffset The byte offset to set. + * @param {number} value The byte value to set. + * @returns {void} + */ + set(byteOffset: number, value: number): void; + /** + * Creates a **copy** of the underlying buffer data and returns it as an ArrayBuffer. + * + * To obtain a reference to the underlying buffer instead, use `toUint8Array()` or `toDataView()`. + * + * @returns {ArrayBuffer} A copy of this data buffer. + */ + toArrayBuffer(): ArrayBuffer; + /** + * Convert this Data pointer to a DataView representing the pointer's contents. + * + * WARNING: The DataView references memory from a message segment, so do not venture outside the bounds of the + * DataView or else BAD THINGS. + * + * @returns {DataView} A live reference to the underlying buffer. + */ + toDataView(): DataView; + toString(): string; + /** + * Convert this Data pointer to a Uint8Array representing the pointer's contents. + * + * WARNING: The Uint8Array references memory from a message segment, so do not venture outside the bounds of the + * Uint8Array or else BAD THINGS. + * + * @returns {DataView} A live reference to the underlying buffer. + */ + toUint8Array(): Uint8Array; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/data.js b/node_modules/capnp-ts/src/serialization/pointers/data.js new file mode 100644 index 0000000..6ea484d --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/data.js @@ -0,0 +1,118 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Data = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const list_element_size_1 = require("../list-element-size"); +const list_1 = require("./list"); +const pointer_1 = require("./pointer"); +const pointer_type_1 = require("./pointer-type"); +const trace = debug_1.default("capnp:data"); +trace("load"); +/** + * A generic blob of bytes. Can be converted to a DataView or Uint8Array to access its contents using `toDataView()` and + * `toUint8Array()`. Use `copyBuffer()` to copy an entire buffer at once. + * + * @export + * @class Data + * @extends {List<number>} + */ +class Data extends list_1.List { + static fromPointer(pointer) { + pointer_1.validate(pointer_type_1.PointerType.LIST, pointer, list_element_size_1.ListElementSize.BYTE); + return this._fromPointerUnchecked(pointer); + } + static _fromPointerUnchecked(pointer) { + return new this(pointer.segment, pointer.byteOffset, pointer._capnp.depthLimit); + } + /** + * Copy the contents of `src` into this Data pointer. If `src` is smaller than the length of this pointer then the + * remaining bytes will be zeroed out. Extra bytes in `src` are ignored. + * + * @param {(ArrayBuffer | ArrayBufferView)} src The source buffer. + * @returns {void} + */ + // TODO: Would be nice to have a way to zero-copy a buffer by allocating a new segment into the message with that + // buffer data. + copyBuffer(src) { + const c = pointer_1.getContent(this); + const dstLength = this.getLength(); + const srcLength = src.byteLength; + const i = src instanceof ArrayBuffer + ? new Uint8Array(src) + : new Uint8Array(src.buffer, src.byteOffset, Math.min(dstLength, srcLength)); + const o = new Uint8Array(c.segment.buffer, c.byteOffset, this.getLength()); + o.set(i); + if (dstLength > srcLength) { + trace("Zeroing out remaining %d bytes after copy into %s.", dstLength - srcLength, this); + o.fill(0, srcLength, dstLength); + } + else if (dstLength < srcLength) { + trace("Truncated %d bytes from source buffer while copying to %s.", srcLength - dstLength, this); + } + } + /** + * Read a byte from the specified offset. + * + * @param {number} byteOffset The byte offset to read. + * @returns {number} The byte value. + */ + get(byteOffset) { + const c = pointer_1.getContent(this); + return c.segment.getUint8(c.byteOffset + byteOffset); + } + /** + * Write a byte at the specified offset. + * + * @param {number} byteOffset The byte offset to set. + * @param {number} value The byte value to set. + * @returns {void} + */ + set(byteOffset, value) { + const c = pointer_1.getContent(this); + c.segment.setUint8(c.byteOffset + byteOffset, value); + } + /** + * Creates a **copy** of the underlying buffer data and returns it as an ArrayBuffer. + * + * To obtain a reference to the underlying buffer instead, use `toUint8Array()` or `toDataView()`. + * + * @returns {ArrayBuffer} A copy of this data buffer. + */ + toArrayBuffer() { + const c = pointer_1.getContent(this); + return c.segment.buffer.slice(c.byteOffset, c.byteOffset + this.getLength()); + } + /** + * Convert this Data pointer to a DataView representing the pointer's contents. + * + * WARNING: The DataView references memory from a message segment, so do not venture outside the bounds of the + * DataView or else BAD THINGS. + * + * @returns {DataView} A live reference to the underlying buffer. + */ + toDataView() { + const c = pointer_1.getContent(this); + return new DataView(c.segment.buffer, c.byteOffset, this.getLength()); + } + toString() { + return `Data_${super.toString()}`; + } + /** + * Convert this Data pointer to a Uint8Array representing the pointer's contents. + * + * WARNING: The Uint8Array references memory from a message segment, so do not venture outside the bounds of the + * Uint8Array or else BAD THINGS. + * + * @returns {DataView} A live reference to the underlying buffer. + */ + toUint8Array() { + const c = pointer_1.getContent(this); + return new Uint8Array(c.segment.buffer, c.byteOffset, this.getLength()); + } +} +exports.Data = Data; +//# sourceMappingURL=data.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/data.js.map b/node_modules/capnp-ts/src/serialization/pointers/data.js.map new file mode 100644 index 0000000..d7d2a80 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/data.js.map @@ -0,0 +1 @@ +{"version":3,"file":"data.js","sourceRoot":"","sources":["data.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,4DAAuD;AACvD,iCAA8B;AAC9B,uCAA0D;AAC1D,iDAA6C;AAE7C,MAAM,KA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C,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;IAC1E,CAAC;CACF;AAtID,oBAsIC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/data.ts b/node_modules/capnp-ts/src/serialization/pointers/data.ts new file mode 100644 index 0000000..bec7df1 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/data.ts @@ -0,0 +1,158 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { ListElementSize } from "../list-element-size"; +import { List } from "./list"; +import { Pointer, validate, getContent } from "./pointer"; +import { PointerType } from "./pointer-type"; + +const trace = initTrace("capnp:data"); +trace("load"); + +/** + * A generic blob of bytes. Can be converted to a DataView or Uint8Array to access its contents using `toDataView()` and + * `toUint8Array()`. Use `copyBuffer()` to copy an entire buffer at once. + * + * @export + * @class Data + * @extends {List<number>} + */ + +export class Data extends List<number> { + static fromPointer(pointer: Pointer): Data { + validate(PointerType.LIST, pointer, ListElementSize.BYTE); + + return this._fromPointerUnchecked(pointer); + } + + protected static _fromPointerUnchecked(pointer: Pointer): Data { + return new this( + pointer.segment, + pointer.byteOffset, + pointer._capnp.depthLimit + ); + } + + /** + * Copy the contents of `src` into this Data pointer. If `src` is smaller than the length of this pointer then the + * remaining bytes will be zeroed out. Extra bytes in `src` are ignored. + * + * @param {(ArrayBuffer | ArrayBufferView)} src The source buffer. + * @returns {void} + */ + + // TODO: Would be nice to have a way to zero-copy a buffer by allocating a new segment into the message with that + // buffer data. + + copyBuffer(src: ArrayBuffer | ArrayBufferView): void { + const c = getContent(this); + + const dstLength = this.getLength(); + const srcLength = src.byteLength; + + const i = + src instanceof ArrayBuffer + ? new Uint8Array(src) + : new Uint8Array( + src.buffer, + src.byteOffset, + Math.min(dstLength, srcLength) + ); + + const o = new Uint8Array(c.segment.buffer, c.byteOffset, this.getLength()); + + o.set(i); + + if (dstLength > srcLength) { + trace( + "Zeroing out remaining %d bytes after copy into %s.", + dstLength - srcLength, + this + ); + + o.fill(0, srcLength, dstLength); + } else if (dstLength < srcLength) { + trace( + "Truncated %d bytes from source buffer while copying to %s.", + srcLength - dstLength, + this + ); + } + } + + /** + * Read a byte from the specified offset. + * + * @param {number} byteOffset The byte offset to read. + * @returns {number} The byte value. + */ + + get(byteOffset: number): number { + const c = getContent(this); + return c.segment.getUint8(c.byteOffset + byteOffset); + } + + /** + * Write a byte at the specified offset. + * + * @param {number} byteOffset The byte offset to set. + * @param {number} value The byte value to set. + * @returns {void} + */ + + set(byteOffset: number, value: number): void { + const c = getContent(this); + c.segment.setUint8(c.byteOffset + byteOffset, value); + } + + /** + * Creates a **copy** of the underlying buffer data and returns it as an ArrayBuffer. + * + * To obtain a reference to the underlying buffer instead, use `toUint8Array()` or `toDataView()`. + * + * @returns {ArrayBuffer} A copy of this data buffer. + */ + + toArrayBuffer(): ArrayBuffer { + const c = getContent(this); + return c.segment.buffer.slice( + c.byteOffset, + c.byteOffset + this.getLength() + ); + } + + /** + * Convert this Data pointer to a DataView representing the pointer's contents. + * + * WARNING: The DataView references memory from a message segment, so do not venture outside the bounds of the + * DataView or else BAD THINGS. + * + * @returns {DataView} A live reference to the underlying buffer. + */ + + toDataView(): DataView { + const c = getContent(this); + return new DataView(c.segment.buffer, c.byteOffset, this.getLength()); + } + + toString(): string { + return `Data_${super.toString()}`; + } + + /** + * Convert this Data pointer to a Uint8Array representing the pointer's contents. + * + * WARNING: The Uint8Array references memory from a message segment, so do not venture outside the bounds of the + * Uint8Array or else BAD THINGS. + * + * @returns {DataView} A live reference to the underlying buffer. + */ + + toUint8Array(): Uint8Array { + const c = getContent(this); + return new Uint8Array(c.segment.buffer, c.byteOffset, this.getLength()); + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/float32-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/float32-list.d.ts new file mode 100644 index 0000000..b109a22 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/float32-list.d.ts @@ -0,0 +1,10 @@ +/** + * @author jdiaz5513 + */ +import { _ListCtor, List } from "./list"; +export declare class Float32List extends List<number> { + static readonly _capnp: _ListCtor; + get(index: number): number; + set(index: number, value: number): void; + toString(): string; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/float32-list.js b/node_modules/capnp-ts/src/serialization/pointers/float32-list.js new file mode 100644 index 0000000..8c33da1 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/float32-list.js @@ -0,0 +1,32 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Float32List = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const list_element_size_1 = require("../list-element-size"); +const list_1 = require("./list"); +const pointer_1 = require("./pointer"); +const trace = debug_1.default("capnp:list:composite"); +trace("load"); +class Float32List extends list_1.List { + get(index) { + const c = pointer_1.getContent(this); + return c.segment.getFloat32(c.byteOffset + index * 4); + } + set(index, value) { + const c = pointer_1.getContent(this); + c.segment.setFloat32(c.byteOffset + index * 4, value); + } + toString() { + return `Float32_${super.toString()}`; + } +} +exports.Float32List = Float32List; +Float32List._capnp = { + displayName: "List<Float32>", + size: list_element_size_1.ListElementSize.BYTE_4 +}; +//# sourceMappingURL=float32-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/float32-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/float32-list.js.map new file mode 100644 index 0000000..dd79ac8 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/float32-list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"float32-list.js","sourceRoot":"","sources":["float32-list.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,4DAAuD;AACvD,iCAAyC;AACzC,uCAAuC;AAEvC,MAAM,KAAK,GAAG,eAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,WAAY,SAAQ,WAAY;IAM3C,GAAG,CAAC,KAAa;QACf,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAE3B,OAAO,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,KAAa;QAC9B,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAE3B,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC;IAED,QAAQ;QACN,OAAO,WAAW,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;IACvC,CAAC;;AApBH,kCAqBC;AApBiB,kBAAM,GAAc;IAClC,WAAW,EAAE,eAAyB;IACtC,IAAI,EAAE,mCAAe,CAAC,MAAM;CAC7B,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/float32-list.ts b/node_modules/capnp-ts/src/serialization/pointers/float32-list.ts new file mode 100644 index 0000000..7de7f99 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/float32-list.ts @@ -0,0 +1,35 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { ListElementSize } from "../list-element-size"; +import { _ListCtor, List } from "./list"; +import { getContent } from "./pointer"; + +const trace = initTrace("capnp:list:composite"); +trace("load"); + +export class Float32List extends List<number> { + static readonly _capnp: _ListCtor = { + displayName: "List<Float32>" as string, + size: ListElementSize.BYTE_4 + }; + + get(index: number): number { + const c = getContent(this); + + return c.segment.getFloat32(c.byteOffset + index * 4); + } + + set(index: number, value: number): void { + const c = getContent(this); + + c.segment.setFloat32(c.byteOffset + index * 4, value); + } + + toString(): string { + return `Float32_${super.toString()}`; + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/float64-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/float64-list.d.ts new file mode 100644 index 0000000..877c0f5 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/float64-list.d.ts @@ -0,0 +1,10 @@ +/** + * @author jdiaz5513 + */ +import { _ListCtor, List } from "./list"; +export declare class Float64List extends List<number> { + static readonly _capnp: _ListCtor; + get(index: number): number; + set(index: number, value: number): void; + toString(): string; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/float64-list.js b/node_modules/capnp-ts/src/serialization/pointers/float64-list.js new file mode 100644 index 0000000..7f681e0 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/float64-list.js @@ -0,0 +1,32 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Float64List = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const list_element_size_1 = require("../list-element-size"); +const list_1 = require("./list"); +const pointer_1 = require("./pointer"); +const trace = debug_1.default("capnp:list:composite"); +trace("load"); +class Float64List extends list_1.List { + get(index) { + const c = pointer_1.getContent(this); + return c.segment.getFloat64(c.byteOffset + index * 8); + } + set(index, value) { + const c = pointer_1.getContent(this); + c.segment.setFloat64(c.byteOffset + index * 8, value); + } + toString() { + return `Float64_${super.toString()}`; + } +} +exports.Float64List = Float64List; +Float64List._capnp = { + displayName: "List<Float64>", + size: list_element_size_1.ListElementSize.BYTE_8 +}; +//# sourceMappingURL=float64-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/float64-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/float64-list.js.map new file mode 100644 index 0000000..f382c12 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/float64-list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"float64-list.js","sourceRoot":"","sources":["float64-list.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,4DAAuD;AACvD,iCAAyC;AACzC,uCAAuC;AAEvC,MAAM,KAAK,GAAG,eAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,WAAY,SAAQ,WAAY;IAM3C,GAAG,CAAC,KAAa;QACf,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAE3B,OAAO,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,KAAa;QAC9B,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAE3B,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC;IAED,QAAQ;QACN,OAAO,WAAW,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;IACvC,CAAC;;AApBH,kCAqBC;AApBiB,kBAAM,GAAc;IAClC,WAAW,EAAE,eAAyB;IACtC,IAAI,EAAE,mCAAe,CAAC,MAAM;CAC7B,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/float64-list.ts b/node_modules/capnp-ts/src/serialization/pointers/float64-list.ts new file mode 100644 index 0000000..3dfd4b2 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/float64-list.ts @@ -0,0 +1,35 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { ListElementSize } from "../list-element-size"; +import { _ListCtor, List } from "./list"; +import { getContent } from "./pointer"; + +const trace = initTrace("capnp:list:composite"); +trace("load"); + +export class Float64List extends List<number> { + static readonly _capnp: _ListCtor = { + displayName: "List<Float64>" as string, + size: ListElementSize.BYTE_8 + }; + + get(index: number): number { + const c = getContent(this); + + return c.segment.getFloat64(c.byteOffset + index * 8); + } + + set(index: number, value: number): void { + const c = getContent(this); + + c.segment.setFloat64(c.byteOffset + index * 8, value); + } + + toString(): string { + return `Float64_${super.toString()}`; + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/group.d.ts b/node_modules/capnp-ts/src/serialization/pointers/group.d.ts new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/group.d.ts diff --git a/node_modules/capnp-ts/src/serialization/pointers/group.js b/node_modules/capnp-ts/src/serialization/pointers/group.js new file mode 100644 index 0000000..4e1f4b0 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/group.js @@ -0,0 +1,2 @@ +"use strict"; +//# sourceMappingURL=group.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/group.js.map b/node_modules/capnp-ts/src/serialization/pointers/group.js.map new file mode 100644 index 0000000..60a2003 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/group.js.map @@ -0,0 +1 @@ +{"version":3,"file":"group.js","sourceRoot":"","sources":["group.ts"],"names":[],"mappings":""}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/group.ts b/node_modules/capnp-ts/src/serialization/pointers/group.ts new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/group.ts diff --git a/node_modules/capnp-ts/src/serialization/pointers/index.d.ts b/node_modules/capnp-ts/src/serialization/pointers/index.d.ts new file mode 100644 index 0000000..dc013aa --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/index.d.ts @@ -0,0 +1,30 @@ +/** + * @author jdiaz5513 + */ +export { AnyPointerList } from "./any-pointer-list"; +export { BoolList } from "./bool-list"; +export { CompositeList } from "./composite-list"; +export { Data } from "./data"; +export { DataList } from "./data-list"; +export { Float32List } from "./float32-list"; +export { Float64List } from "./float64-list"; +export { Int8List } from "./int8-list"; +export { Int16List } from "./int16-list"; +export { Int32List } from "./int32-list"; +export { Int64List } from "./int64-list"; +export { Interface } from "./interface"; +export { InterfaceList } from "./interface-list"; +export { List, ListCtor } from "./list"; +export { Orphan } from "./orphan"; +export { PointerList } from "./pointer-list"; +export { PointerType } from "./pointer-type"; +export { Pointer } from "./pointer"; +export { _StructCtor, Struct, StructCtor } from "./struct"; +export { Text } from "./text"; +export { TextList } from "./text-list"; +export { Uint8List } from "./uint8-list"; +export { Uint16List } from "./uint16-list"; +export { Uint32List } from "./uint32-list"; +export { Uint64List } from "./uint64-list"; +export { Void, VOID } from "./void"; +export { VoidList } from "./void-list"; diff --git a/node_modules/capnp-ts/src/serialization/pointers/index.js b/node_modules/capnp-ts/src/serialization/pointers/index.js new file mode 100644 index 0000000..b5902c9 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/index.js @@ -0,0 +1,62 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.VoidList = exports.VOID = exports.Void = exports.Uint64List = exports.Uint32List = exports.Uint16List = exports.Uint8List = exports.TextList = exports.Text = exports.Struct = exports.Pointer = exports.PointerType = exports.PointerList = exports.Orphan = exports.List = exports.InterfaceList = exports.Interface = exports.Int64List = exports.Int32List = exports.Int16List = exports.Int8List = exports.Float64List = exports.Float32List = exports.DataList = exports.Data = exports.CompositeList = exports.BoolList = exports.AnyPointerList = void 0; +var any_pointer_list_1 = require("./any-pointer-list"); +Object.defineProperty(exports, "AnyPointerList", { enumerable: true, get: function () { return any_pointer_list_1.AnyPointerList; } }); +var bool_list_1 = require("./bool-list"); +Object.defineProperty(exports, "BoolList", { enumerable: true, get: function () { return bool_list_1.BoolList; } }); +var composite_list_1 = require("./composite-list"); +Object.defineProperty(exports, "CompositeList", { enumerable: true, get: function () { return composite_list_1.CompositeList; } }); +var data_1 = require("./data"); +Object.defineProperty(exports, "Data", { enumerable: true, get: function () { return data_1.Data; } }); +var data_list_1 = require("./data-list"); +Object.defineProperty(exports, "DataList", { enumerable: true, get: function () { return data_list_1.DataList; } }); +var float32_list_1 = require("./float32-list"); +Object.defineProperty(exports, "Float32List", { enumerable: true, get: function () { return float32_list_1.Float32List; } }); +var float64_list_1 = require("./float64-list"); +Object.defineProperty(exports, "Float64List", { enumerable: true, get: function () { return float64_list_1.Float64List; } }); +var int8_list_1 = require("./int8-list"); +Object.defineProperty(exports, "Int8List", { enumerable: true, get: function () { return int8_list_1.Int8List; } }); +var int16_list_1 = require("./int16-list"); +Object.defineProperty(exports, "Int16List", { enumerable: true, get: function () { return int16_list_1.Int16List; } }); +var int32_list_1 = require("./int32-list"); +Object.defineProperty(exports, "Int32List", { enumerable: true, get: function () { return int32_list_1.Int32List; } }); +var int64_list_1 = require("./int64-list"); +Object.defineProperty(exports, "Int64List", { enumerable: true, get: function () { return int64_list_1.Int64List; } }); +var interface_1 = require("./interface"); +Object.defineProperty(exports, "Interface", { enumerable: true, get: function () { return interface_1.Interface; } }); +var interface_list_1 = require("./interface-list"); +Object.defineProperty(exports, "InterfaceList", { enumerable: true, get: function () { return interface_list_1.InterfaceList; } }); +var list_1 = require("./list"); +Object.defineProperty(exports, "List", { enumerable: true, get: function () { return list_1.List; } }); +var orphan_1 = require("./orphan"); +Object.defineProperty(exports, "Orphan", { enumerable: true, get: function () { return orphan_1.Orphan; } }); +var pointer_list_1 = require("./pointer-list"); +Object.defineProperty(exports, "PointerList", { enumerable: true, get: function () { return pointer_list_1.PointerList; } }); +var pointer_type_1 = require("./pointer-type"); +Object.defineProperty(exports, "PointerType", { enumerable: true, get: function () { return pointer_type_1.PointerType; } }); +var pointer_1 = require("./pointer"); +Object.defineProperty(exports, "Pointer", { enumerable: true, get: function () { return pointer_1.Pointer; } }); +var struct_1 = require("./struct"); +Object.defineProperty(exports, "Struct", { enumerable: true, get: function () { return struct_1.Struct; } }); +var text_1 = require("./text"); +Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return text_1.Text; } }); +var text_list_1 = require("./text-list"); +Object.defineProperty(exports, "TextList", { enumerable: true, get: function () { return text_list_1.TextList; } }); +var uint8_list_1 = require("./uint8-list"); +Object.defineProperty(exports, "Uint8List", { enumerable: true, get: function () { return uint8_list_1.Uint8List; } }); +var uint16_list_1 = require("./uint16-list"); +Object.defineProperty(exports, "Uint16List", { enumerable: true, get: function () { return uint16_list_1.Uint16List; } }); +var uint32_list_1 = require("./uint32-list"); +Object.defineProperty(exports, "Uint32List", { enumerable: true, get: function () { return uint32_list_1.Uint32List; } }); +var uint64_list_1 = require("./uint64-list"); +Object.defineProperty(exports, "Uint64List", { enumerable: true, get: function () { return uint64_list_1.Uint64List; } }); +var void_1 = require("./void"); +Object.defineProperty(exports, "Void", { enumerable: true, get: function () { return void_1.Void; } }); +Object.defineProperty(exports, "VOID", { enumerable: true, get: function () { return void_1.VOID; } }); +var void_list_1 = require("./void-list"); +Object.defineProperty(exports, "VoidList", { enumerable: true, get: function () { return void_list_1.VoidList; } }); +//# sourceMappingURL=index.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/index.js.map b/node_modules/capnp-ts/src/serialization/pointers/index.js.map new file mode 100644 index 0000000..959c7d6 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,uDAAoD;AAA3C,kHAAA,cAAc,OAAA;AACvB,yCAAuC;AAA9B,qGAAA,QAAQ,OAAA;AACjB,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,yCAAuC;AAA9B,qGAAA,QAAQ,OAAA;AACjB,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,yCAAuC;AAA9B,qGAAA,QAAQ,OAAA;AACjB,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAClB,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAClB,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAClB,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,+BAAwC;AAA/B,4FAAA,IAAI,OAAA;AACb,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,mCAA2D;AAArC,gGAAA,MAAM,OAAA;AAC5B,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,yCAAuC;AAA9B,qGAAA,QAAQ,OAAA;AACjB,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAClB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,+BAAoC;AAA3B,4FAAA,IAAI,OAAA;AAAE,4FAAA,IAAI,OAAA;AACnB,yCAAuC;AAA9B,qGAAA,QAAQ,OAAA"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/index.ts b/node_modules/capnp-ts/src/serialization/pointers/index.ts new file mode 100644 index 0000000..5a94ada --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/index.ts @@ -0,0 +1,31 @@ +/** + * @author jdiaz5513 + */ + +export { AnyPointerList } from "./any-pointer-list"; +export { BoolList } from "./bool-list"; +export { CompositeList } from "./composite-list"; +export { Data } from "./data"; +export { DataList } from "./data-list"; +export { Float32List } from "./float32-list"; +export { Float64List } from "./float64-list"; +export { Int8List } from "./int8-list"; +export { Int16List } from "./int16-list"; +export { Int32List } from "./int32-list"; +export { Int64List } from "./int64-list"; +export { Interface } from "./interface"; +export { InterfaceList } from "./interface-list"; +export { List, ListCtor } from "./list"; +export { Orphan } from "./orphan"; +export { PointerList } from "./pointer-list"; +export { PointerType } from "./pointer-type"; +export { Pointer } from "./pointer"; +export { _StructCtor, Struct, StructCtor } from "./struct"; +export { Text } from "./text"; +export { TextList } from "./text-list"; +export { Uint8List } from "./uint8-list"; +export { Uint16List } from "./uint16-list"; +export { Uint32List } from "./uint32-list"; +export { Uint64List } from "./uint64-list"; +export { Void, VOID } from "./void"; +export { VoidList } from "./void-list"; diff --git a/node_modules/capnp-ts/src/serialization/pointers/int16-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/int16-list.d.ts new file mode 100644 index 0000000..62d4ae8 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/int16-list.d.ts @@ -0,0 +1,10 @@ +/** + * @author jdiaz5513 + */ +import { _ListCtor, List } from "./list"; +export declare class Int16List extends List<number> { + static readonly _capnp: _ListCtor; + get(index: number): number; + set(index: number, value: number): void; + toString(): string; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/int16-list.js b/node_modules/capnp-ts/src/serialization/pointers/int16-list.js new file mode 100644 index 0000000..0922302 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/int16-list.js @@ -0,0 +1,32 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Int16List = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const list_element_size_1 = require("../list-element-size"); +const list_1 = require("./list"); +const pointer_1 = require("./pointer"); +const trace = debug_1.default("capnp:list:composite"); +trace("load"); +class Int16List extends list_1.List { + get(index) { + const c = pointer_1.getContent(this); + return c.segment.getInt16(c.byteOffset + index * 2); + } + set(index, value) { + const c = pointer_1.getContent(this); + c.segment.setInt16(c.byteOffset + index * 2, value); + } + toString() { + return `Int16_${super.toString()}`; + } +} +exports.Int16List = Int16List; +Int16List._capnp = { + displayName: "List<Int16>", + size: list_element_size_1.ListElementSize.BYTE_2 +}; +//# sourceMappingURL=int16-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/int16-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/int16-list.js.map new file mode 100644 index 0000000..e39e88f --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/int16-list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"int16-list.js","sourceRoot":"","sources":["int16-list.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,4DAAuD;AACvD,iCAAyC;AACzC,uCAAuC;AAEvC,MAAM,KAAK,GAAG,eAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,SAAU,SAAQ,WAAY;IAMzC,GAAG,CAAC,KAAa;QACf,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAE3B,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,KAAa;QAC9B,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAE3B,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IAED,QAAQ;QACN,OAAO,SAAS,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;IACrC,CAAC;;AApBH,8BAqBC;AApBiB,gBAAM,GAAc;IAClC,WAAW,EAAE,aAAuB;IACpC,IAAI,EAAE,mCAAe,CAAC,MAAM;CAC7B,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/int16-list.ts b/node_modules/capnp-ts/src/serialization/pointers/int16-list.ts new file mode 100644 index 0000000..45ec4a5 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/int16-list.ts @@ -0,0 +1,35 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { ListElementSize } from "../list-element-size"; +import { _ListCtor, List } from "./list"; +import { getContent } from "./pointer"; + +const trace = initTrace("capnp:list:composite"); +trace("load"); + +export class Int16List extends List<number> { + static readonly _capnp: _ListCtor = { + displayName: "List<Int16>" as string, + size: ListElementSize.BYTE_2 + }; + + get(index: number): number { + const c = getContent(this); + + return c.segment.getInt16(c.byteOffset + index * 2); + } + + set(index: number, value: number): void { + const c = getContent(this); + + c.segment.setInt16(c.byteOffset + index * 2, value); + } + + toString(): string { + return `Int16_${super.toString()}`; + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/int32-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/int32-list.d.ts new file mode 100644 index 0000000..5602410 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/int32-list.d.ts @@ -0,0 +1,10 @@ +/** + * @author jdiaz5513 + */ +import { _ListCtor, List } from "./list"; +export declare class Int32List extends List<number> { + static readonly _capnp: _ListCtor; + get(index: number): number; + set(index: number, value: number): void; + toString(): string; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/int32-list.js b/node_modules/capnp-ts/src/serialization/pointers/int32-list.js new file mode 100644 index 0000000..c41cdf0 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/int32-list.js @@ -0,0 +1,32 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Int32List = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const list_element_size_1 = require("../list-element-size"); +const list_1 = require("./list"); +const pointer_1 = require("./pointer"); +const trace = debug_1.default("capnp:list:composite"); +trace("load"); +class Int32List extends list_1.List { + get(index) { + const c = pointer_1.getContent(this); + return c.segment.getInt32(c.byteOffset + index * 4); + } + set(index, value) { + const c = pointer_1.getContent(this); + c.segment.setInt32(c.byteOffset + index * 4, value); + } + toString() { + return `Int32_${super.toString()}`; + } +} +exports.Int32List = Int32List; +Int32List._capnp = { + displayName: "List<Int32>", + size: list_element_size_1.ListElementSize.BYTE_4 +}; +//# sourceMappingURL=int32-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/int32-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/int32-list.js.map new file mode 100644 index 0000000..ce50721 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/int32-list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"int32-list.js","sourceRoot":"","sources":["int32-list.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,4DAAuD;AACvD,iCAAyC;AACzC,uCAAuC;AAEvC,MAAM,KAAK,GAAG,eAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,SAAU,SAAQ,WAAY;IAMzC,GAAG,CAAC,KAAa;QACf,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,KAAa;QAC9B,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IAED,QAAQ;QACN,OAAO,SAAS,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;IACrC,CAAC;;AAlBH,8BAmBC;AAlBiB,gBAAM,GAAc;IAClC,WAAW,EAAE,aAAuB;IACpC,IAAI,EAAE,mCAAe,CAAC,MAAM;CAC7B,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/int32-list.ts b/node_modules/capnp-ts/src/serialization/pointers/int32-list.ts new file mode 100644 index 0000000..8e65ad2 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/int32-list.ts @@ -0,0 +1,33 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { ListElementSize } from "../list-element-size"; +import { _ListCtor, List } from "./list"; +import { getContent } from "./pointer"; + +const trace = initTrace("capnp:list:composite"); +trace("load"); + +export class Int32List extends List<number> { + static readonly _capnp: _ListCtor = { + displayName: "List<Int32>" as string, + size: ListElementSize.BYTE_4 + }; + + get(index: number): number { + const c = getContent(this); + return c.segment.getInt32(c.byteOffset + index * 4); + } + + set(index: number, value: number): void { + const c = getContent(this); + c.segment.setInt32(c.byteOffset + index * 4, value); + } + + toString(): string { + return `Int32_${super.toString()}`; + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/int64-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/int64-list.d.ts new file mode 100644 index 0000000..e25d900 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/int64-list.d.ts @@ -0,0 +1,11 @@ +/** + * @author jdiaz5513 + */ +import { Int64 } from "../../types"; +import { _ListCtor, List } from "./list"; +export declare class Int64List extends List<Int64> { + static readonly _capnp: _ListCtor; + get(index: number): Int64; + set(index: number, value: Int64): void; + toString(): string; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/int64-list.js b/node_modules/capnp-ts/src/serialization/pointers/int64-list.js new file mode 100644 index 0000000..5578b27 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/int64-list.js @@ -0,0 +1,32 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Int64List = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const list_element_size_1 = require("../list-element-size"); +const list_1 = require("./list"); +const pointer_1 = require("./pointer"); +const trace = debug_1.default("capnp:list:composite"); +trace("load"); +class Int64List extends list_1.List { + get(index) { + const c = pointer_1.getContent(this); + return c.segment.getInt64(c.byteOffset + index * 8); + } + set(index, value) { + const c = pointer_1.getContent(this); + c.segment.setInt64(c.byteOffset + index * 8, value); + } + toString() { + return `Int64_${super.toString()}`; + } +} +exports.Int64List = Int64List; +Int64List._capnp = { + displayName: "List<Int64>", + size: list_element_size_1.ListElementSize.BYTE_8, +}; +//# sourceMappingURL=int64-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/int64-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/int64-list.js.map new file mode 100644 index 0000000..9b04f2f --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/int64-list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"int64-list.js","sourceRoot":"","sources":["int64-list.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAG9B,4DAAuD;AACvD,iCAAyC;AACzC,uCAAuC;AAEvC,MAAM,KAAK,GAAG,eAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,SAAU,SAAQ,WAAW;IAMxC,GAAG,CAAC,KAAa;QACf,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,KAAY;QAC7B,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IAED,QAAQ;QACN,OAAO,SAAS,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;IACrC,CAAC;;AAlBH,8BAmBC;AAlBiB,gBAAM,GAAc;IAClC,WAAW,EAAE,aAAuB;IACpC,IAAI,EAAE,mCAAe,CAAC,MAAM;CAC7B,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/int64-list.ts b/node_modules/capnp-ts/src/serialization/pointers/int64-list.ts new file mode 100644 index 0000000..6ad1236 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/int64-list.ts @@ -0,0 +1,34 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { Int64 } from "../../types"; +import { ListElementSize } from "../list-element-size"; +import { _ListCtor, List } from "./list"; +import { getContent } from "./pointer"; + +const trace = initTrace("capnp:list:composite"); +trace("load"); + +export class Int64List extends List<Int64> { + static readonly _capnp: _ListCtor = { + displayName: "List<Int64>" as string, + size: ListElementSize.BYTE_8, + }; + + get(index: number): Int64 { + const c = getContent(this); + return c.segment.getInt64(c.byteOffset + index * 8); + } + + set(index: number, value: Int64): void { + const c = getContent(this); + c.segment.setInt64(c.byteOffset + index * 8, value); + } + + toString(): string { + return `Int64_${super.toString()}`; + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/int8-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/int8-list.d.ts new file mode 100644 index 0000000..f35140c --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/int8-list.d.ts @@ -0,0 +1,10 @@ +/** + * @author jdiaz5513 + */ +import { _ListCtor, List } from "./list"; +export declare class Int8List extends List<number> { + static readonly _capnp: _ListCtor; + get(index: number): number; + set(index: number, value: number): void; + toString(): string; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/int8-list.js b/node_modules/capnp-ts/src/serialization/pointers/int8-list.js new file mode 100644 index 0000000..0da8ec5 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/int8-list.js @@ -0,0 +1,32 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Int8List = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const list_element_size_1 = require("../list-element-size"); +const list_1 = require("./list"); +const pointer_1 = require("./pointer"); +const trace = debug_1.default("capnp:list:composite"); +trace("load"); +class Int8List extends list_1.List { + get(index) { + const c = pointer_1.getContent(this); + return c.segment.getInt8(c.byteOffset + index); + } + set(index, value) { + const c = pointer_1.getContent(this); + c.segment.setInt8(c.byteOffset + index, value); + } + toString() { + return `Int8_${super.toString()}`; + } +} +exports.Int8List = Int8List; +Int8List._capnp = { + displayName: "List<Int8>", + size: list_element_size_1.ListElementSize.BYTE +}; +//# sourceMappingURL=int8-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/int8-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/int8-list.js.map new file mode 100644 index 0000000..42b05a5 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/int8-list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"int8-list.js","sourceRoot":"","sources":["int8-list.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,4DAAuD;AACvD,iCAAyC;AACzC,uCAAuC;AAEvC,MAAM,KAAK,GAAG,eAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,QAAS,SAAQ,WAAY;IAMxC,GAAG,CAAC,KAAa;QACf,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,CAAC,CAAC;IACjD,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,KAAa;QAC9B,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,EAAE,KAAK,CAAC,CAAC;IACjD,CAAC;IAED,QAAQ;QACN,OAAO,QAAQ,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;IACpC,CAAC;;AAlBH,4BAmBC;AAlBiB,eAAM,GAAc;IAClC,WAAW,EAAE,YAAsB;IACnC,IAAI,EAAE,mCAAe,CAAC,IAAI;CAC3B,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/int8-list.ts b/node_modules/capnp-ts/src/serialization/pointers/int8-list.ts new file mode 100644 index 0000000..ccf99eb --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/int8-list.ts @@ -0,0 +1,33 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { ListElementSize } from "../list-element-size"; +import { _ListCtor, List } from "./list"; +import { getContent } from "./pointer"; + +const trace = initTrace("capnp:list:composite"); +trace("load"); + +export class Int8List extends List<number> { + static readonly _capnp: _ListCtor = { + displayName: "List<Int8>" as string, + size: ListElementSize.BYTE + }; + + get(index: number): number { + const c = getContent(this); + return c.segment.getInt8(c.byteOffset + index); + } + + set(index: number, value: number): void { + const c = getContent(this); + c.segment.setInt8(c.byteOffset + index, value); + } + + toString(): string { + return `Int8_${super.toString()}`; + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/interface-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/interface-list.d.ts new file mode 100644 index 0000000..982bef3 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/interface-list.d.ts @@ -0,0 +1,6 @@ +/** + * @author jdiaz5513 + */ +import { Interface } from "./interface"; +import { ListCtor } from "./list"; +export declare const InterfaceList: ListCtor<Interface>; diff --git a/node_modules/capnp-ts/src/serialization/pointers/interface-list.js b/node_modules/capnp-ts/src/serialization/pointers/interface-list.js new file mode 100644 index 0000000..d607915 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/interface-list.js @@ -0,0 +1,10 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.InterfaceList = void 0; +const interface_1 = require("./interface"); +const pointer_list_1 = require("./pointer-list"); +exports.InterfaceList = pointer_list_1.PointerList(interface_1.Interface); +//# sourceMappingURL=interface-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/interface-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/interface-list.js.map new file mode 100644 index 0000000..b439f57 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/interface-list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"interface-list.js","sourceRoot":"","sources":["interface-list.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,2CAAwC;AAExC,iDAA6C;AAEhC,QAAA,aAAa,GAAwB,0BAAW,CAAC,qBAAS,CAAC,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/interface-list.ts b/node_modules/capnp-ts/src/serialization/pointers/interface-list.ts new file mode 100644 index 0000000..6dc35c1 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/interface-list.ts @@ -0,0 +1,9 @@ +/** + * @author jdiaz5513 + */ + +import { Interface } from "./interface"; +import { ListCtor } from "./list"; +import { PointerList } from "./pointer-list"; + +export const InterfaceList: ListCtor<Interface> = PointerList(Interface); diff --git a/node_modules/capnp-ts/src/serialization/pointers/interface.d.ts b/node_modules/capnp-ts/src/serialization/pointers/interface.d.ts new file mode 100644 index 0000000..89a3b72 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/interface.d.ts @@ -0,0 +1,8 @@ +/** + * @author jdiaz5513 + */ +import { Segment } from "../segment"; +import { Pointer } from "./pointer"; +export declare class Interface extends Pointer { + constructor(segment: Segment, byteOffset: number, depthLimit?: number); +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/interface.js b/node_modules/capnp-ts/src/serialization/pointers/interface.js new file mode 100644 index 0000000..d4607e9 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/interface.js @@ -0,0 +1,18 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Interface = void 0; +const constants_1 = require("../../constants"); +const errors_1 = require("../../errors"); +const util_1 = require("../../util"); +const pointer_1 = require("./pointer"); +class Interface extends pointer_1.Pointer { + constructor(segment, byteOffset, depthLimit = constants_1.MAX_DEPTH) { + super(segment, byteOffset, depthLimit); + throw new Error(util_1.format(errors_1.NOT_IMPLEMENTED, "new Interface")); + } +} +exports.Interface = Interface; +//# sourceMappingURL=interface.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/interface.js.map b/node_modules/capnp-ts/src/serialization/pointers/interface.js.map new file mode 100644 index 0000000..8d8c1d5 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/interface.js.map @@ -0,0 +1 @@ +{"version":3,"file":"interface.js","sourceRoot":"","sources":["interface.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,+CAA4C;AAC5C,yCAA+C;AAC/C,qCAAoC;AAEpC,uCAAoC;AAEpC,MAAa,SAAU,SAAQ,iBAAO;IACpC,YAAY,OAAgB,EAAE,UAAkB,EAAE,UAAU,GAAG,qBAAS;QACtE,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;QAEvC,MAAM,IAAI,KAAK,CAAC,aAAM,CAAC,wBAAe,EAAE,eAAe,CAAC,CAAC,CAAC;IAC5D,CAAC;CACF;AAND,8BAMC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/interface.ts b/node_modules/capnp-ts/src/serialization/pointers/interface.ts new file mode 100644 index 0000000..b283869 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/interface.ts @@ -0,0 +1,17 @@ +/** + * @author jdiaz5513 + */ + +import { MAX_DEPTH } from "../../constants"; +import { NOT_IMPLEMENTED } from "../../errors"; +import { format } from "../../util"; +import { Segment } from "../segment"; +import { Pointer } from "./pointer"; + +export class Interface extends Pointer { + constructor(segment: Segment, byteOffset: number, depthLimit = MAX_DEPTH) { + super(segment, byteOffset, depthLimit); + + throw new Error(format(NOT_IMPLEMENTED, "new Interface")); + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/list.d.ts new file mode 100644 index 0000000..8bd69fc --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/list.d.ts @@ -0,0 +1,76 @@ +/** + * @author jdiaz5513 + */ +import { ListElementSize } from "../list-element-size"; +import { ObjectSize } from "../object-size"; +import { Segment } from "../segment"; +import { Pointer } from "./pointer"; +export interface _ListCtor { + readonly compositeSize?: ObjectSize; + readonly displayName: string; + readonly size: ListElementSize; +} +export interface ListCtor<T> { + readonly _capnp: _ListCtor; + new (segment: Segment, byteOffset: number, depthLimit?: number): List<T>; +} +export declare type FilterCallback<T> = (this: void, value: T, index: number) => boolean; +export declare type IndexedCallback<T, U> = (this: void, value: T, index: number) => U; +export interface Group<T> { + [k: string]: T; +} +/** + * A generic list class. Implements Filterable, + */ +export declare class List<T> extends Pointer { + static readonly _capnp: _ListCtor; + static readonly get: typeof get; + static readonly initList: typeof initList; + static readonly set: typeof set; + static toString(): string; + all(callbackfn: FilterCallback<T>): boolean; + any(callbackfn: FilterCallback<T>): boolean; + ap<U>(callbackfns: Array<IndexedCallback<T, U>>): U[]; + concat(other: List<T>): T[]; + drop(n: number): T[]; + dropWhile(callbackfn: FilterCallback<T>): T[]; + empty(): T[]; + every(callbackfn: FilterCallback<T>): boolean; + filter(callbackfn: FilterCallback<T>): T[]; + find(callbackfn: FilterCallback<T>): T | undefined; + findIndex(callbackfn: FilterCallback<T>): number; + forEach(callbackfn: (this: void, value: T, index: number) => void): void; + get(_index: number): T; + /** + * Get the length of this list. + * + * @returns {number} The number of elements in this list. + */ + getLength(): number; + groupBy(callbackfn: IndexedCallback<T, string>): Group<T>; + intersperse(sep: T): T[]; + map<U>(callbackfn: IndexedCallback<T, U>): U[]; + reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number) => T): T; + reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number) => U, initialValue: U): U; + set(_index: number, _value: T): void; + slice(start?: number, end?: number): T[]; + some(callbackfn: FilterCallback<T>): boolean; + take(n: number): T[]; + takeWhile(callbackfn: FilterCallback<T>): T[]; + toArray(): T[]; + toString(): string; +} +/** + * Initialize the list with the given element size and length. This will allocate new space for the list, ideally in + * the same segment as this pointer. + * + * @param {ListElementSize} elementSize The size of each element in the list. + * @param {number} length The number of elements in the list. + * @param {List<T>} l The list to initialize. + * @param {ObjectSize} [compositeSize] The size of each element in a composite list. This value is required for + * composite lists. + * @returns {void} + */ +export declare function initList<T>(elementSize: ListElementSize, length: number, l: List<T>, compositeSize?: ObjectSize): void; +export declare function get<T>(_index: number, _l: List<T>): T; +export declare function set<T>(_index: number, _value: T, _l: List<T>): void; diff --git a/node_modules/capnp-ts/src/serialization/pointers/list.js b/node_modules/capnp-ts/src/serialization/pointers/list.js new file mode 100644 index 0000000..0e002cd --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/list.js @@ -0,0 +1,274 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.set = exports.get = exports.initList = exports.List = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const errors_1 = require("../../errors"); +const util_1 = require("../../util"); +const list_element_size_1 = require("../list-element-size"); +const object_size_1 = require("../object-size"); +const pointer_1 = require("./pointer"); +const trace = debug_1.default("capnp:list"); +trace("load"); +/** + * A generic list class. Implements Filterable, + */ +class List extends pointer_1.Pointer { + static toString() { + return this._capnp.displayName; + } + all(callbackfn) { + const length = this.getLength(); + for (let i = 0; i < length; i++) { + if (!callbackfn(this.get(i), i)) + return false; + } + return true; + } + any(callbackfn) { + const length = this.getLength(); + for (let i = 0; i < length; i++) { + if (callbackfn(this.get(i), i)) + return true; + } + return false; + } + ap(callbackfns) { + const length = this.getLength(); + const res = []; + for (let i = 0; i < length; i++) { + res.push(...callbackfns.map((f) => f(this.get(i), i))); + } + return res; + } + concat(other) { + const length = this.getLength(); + const otherLength = other.getLength(); + const res = new Array(length + otherLength); + for (let i = 0; i < length; i++) + res[i] = this.get(i); + for (let i = 0; i < otherLength; i++) + res[i + length] = other.get(i); + return res; + } + drop(n) { + const length = this.getLength(); + const res = new Array(length); + for (let i = n; i < length; i++) + res[i] = this.get(i); + return res; + } + dropWhile(callbackfn) { + const length = this.getLength(); + const res = []; + let drop = true; + for (let i = 0; i < length; i++) { + const v = this.get(i); + if (drop) + drop = callbackfn(v, i); + if (!drop) + res.push(v); + } + return res; + } + empty() { + return []; + } + every(callbackfn) { + return this.all(callbackfn); + } + filter(callbackfn) { + const length = this.getLength(); + const res = []; + for (let i = 0; i < length; i++) { + const value = this.get(i); + if (callbackfn(value, i)) + res.push(value); + } + return res; + } + find(callbackfn) { + const length = this.getLength(); + for (let i = 0; i < length; i++) { + const value = this.get(i); + if (callbackfn(value, i)) + return value; + } + return undefined; + } + findIndex(callbackfn) { + const length = this.getLength(); + for (let i = 0; i < length; i++) { + const value = this.get(i); + if (callbackfn(value, i)) + return i; + } + return -1; + } + forEach(callbackfn) { + const length = this.getLength(); + for (let i = 0; i < length; i++) + callbackfn(this.get(i), i); + } + get(_index) { + return get(_index, this); + } + /** + * Get the length of this list. + * + * @returns {number} The number of elements in this list. + */ + getLength() { + return pointer_1.getTargetListLength(this); + } + groupBy(callbackfn) { + const length = this.getLength(); + const res = {}; + for (let i = 0; i < length; i++) { + const v = this.get(i); + res[callbackfn(v, i)] = v; + } + return res; + } + intersperse(sep) { + const length = this.getLength(); + const res = new Array(length); + for (let i = 0; i < length; i++) { + if (i > 0) + res.push(sep); + res.push(this.get(i)); + } + return res; + } + map(callbackfn) { + const length = this.getLength(); + const res = new Array(length); + for (let i = 0; i < length; i++) + res[i] = callbackfn(this.get(i), i); + return res; + } + reduce(callbackfn, initialValue) { + let i = 0; + let res; + if (initialValue === undefined) { + res = this.get(0); + i++; + } + else { + res = initialValue; + } + for (; i < this.getLength(); i++) + res = callbackfn(res, this.get(i), i); + return res; + } + set(_index, _value) { + set(_index, _value, this); + } + slice(start = 0, end) { + const length = end ? Math.min(this.getLength(), end) : this.getLength(); + const res = new Array(length - start); + for (let i = start; i < length; i++) + res[i] = this.get(i); + return res; + } + some(callbackfn) { + return this.any(callbackfn); + } + take(n) { + const length = Math.min(this.getLength(), n); + const res = new Array(length); + for (let i = 0; i < length; i++) + res[i] = this.get(i); + return res; + } + takeWhile(callbackfn) { + const length = this.getLength(); + const res = []; + let take; + for (let i = 0; i < length; i++) { + const v = this.get(i); + take = callbackfn(v, i); + if (!take) + return res; + res.push(v); + } + return res; + } + toArray() { + return this.map(util_1.identity); + } + toString() { + return `List_${super.toString()}`; + } +} +exports.List = List; +List._capnp = { + displayName: "List<Generic>", + size: list_element_size_1.ListElementSize.VOID, +}; +List.get = get; +List.initList = initList; +List.set = set; +/** + * Initialize the list with the given element size and length. This will allocate new space for the list, ideally in + * the same segment as this pointer. + * + * @param {ListElementSize} elementSize The size of each element in the list. + * @param {number} length The number of elements in the list. + * @param {List<T>} l The list to initialize. + * @param {ObjectSize} [compositeSize] The size of each element in a composite list. This value is required for + * composite lists. + * @returns {void} + */ +function initList(elementSize, length, l, compositeSize) { + let c; + switch (elementSize) { + case list_element_size_1.ListElementSize.BIT: + c = l.segment.allocate(Math.ceil(length / 8)); + break; + case list_element_size_1.ListElementSize.BYTE: + case list_element_size_1.ListElementSize.BYTE_2: + case list_element_size_1.ListElementSize.BYTE_4: + case list_element_size_1.ListElementSize.BYTE_8: + case list_element_size_1.ListElementSize.POINTER: + c = l.segment.allocate(length * pointer_1.getListElementByteLength(elementSize)); + break; + case list_element_size_1.ListElementSize.COMPOSITE: { + if (compositeSize === undefined) { + throw new Error(util_1.format(errors_1.PTR_COMPOSITE_SIZE_UNDEFINED)); + } + compositeSize = object_size_1.padToWord(compositeSize); + const byteLength = object_size_1.getByteLength(compositeSize) * length; + // We need to allocate an extra 8 bytes for the tag word, then make sure we write the length to it. We advance + // the content pointer by 8 bytes so that it then points to the first list element as intended. Everything + // starts off zeroed out so these nested structs don't need to be initialized in any way. + c = l.segment.allocate(byteLength + 8); + pointer_1.setStructPointer(length, compositeSize, c); + trace("Wrote composite tag word %s for %s.", c, l); + break; + } + case list_element_size_1.ListElementSize.VOID: + // No need to allocate anything, we can write the list pointer right here. + pointer_1.setListPointer(0, elementSize, length, l); + return; + default: + throw new Error(util_1.format(errors_1.PTR_INVALID_LIST_SIZE, elementSize)); + } + const res = pointer_1.initPointer(c.segment, c.byteOffset, l); + pointer_1.setListPointer(res.offsetWords, elementSize, length, res.pointer, compositeSize); +} +exports.initList = initList; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function get(_index, _l) { + throw new TypeError(); +} +exports.get = get; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function set(_index, _value, _l) { + throw new TypeError(); +} +exports.set = set; +//# sourceMappingURL=list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/list.js.map b/node_modules/capnp-ts/src/serialization/pointers/list.js.map new file mode 100644 index 0000000..89bc461 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"list.js","sourceRoot":"","sources":["list.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,yCAAmF;AACnF,qCAA8C;AAC9C,4DAAuD;AACvD,gDAAsE;AAEtE,uCAOmB;AAEnB,MAAM,KAAK,GAAG,eAAS,CAAC,YAAY,CAAC,CAAC;AACtC,KAAK,CAAC,MAAM,CAAC,CAAC;AAqBd;;GAEG;AAEH,MAAa,IAAQ,SAAQ,iBAAO;IASlC,MAAM,CAAC,QAAQ;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;IACjC,CAAC;IAED,GAAG,CAAC,UAA6B;QAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAEhC,KAAK,IAAI,CAAC,GAAG,CA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,CAAC,qCAAqC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAEnD,MAAM;SACP;QACD,KAAK,mCAAe,CAAC,IAAI;YACvB,0EAA0E;YAE1E,wBAAc,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;YAE1C,OAAO;QAET;YACE,MAAM,IAAI,KAAK,CAAC,aAAM,CAAC,8BAAqB,EAAE,WAAW,CAAC,CAAC,CAAC;KAC/D;IAED,MAAM,GAAG,GAAG,qBAAW,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAEpD,wBAAc,CAAC,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;AACnF,CAAC;AA1DD,4BA0DC;AAED,6DAA6D;AAC7D,SAAgB,GAAG,CAAI,MAAc,EAAE,EAAW;IAChD,MAAM,IAAI,SAAS,EAAE,CAAC;AACxB,CAAC;AAFD,kBAEC;AAED,6DAA6D;AAC7D,SAAgB,GAAG,CAAI,MAAc,EAAE,MAAS,EAAE,EAAW;IAC3D,MAAM,IAAI,SAAS,EAAE,CAAC;AACxB,CAAC;AAFD,kBAEC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/list.ts b/node_modules/capnp-ts/src/serialization/pointers/list.ts new file mode 100644 index 0000000..1e4744b --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/list.ts @@ -0,0 +1,381 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { PTR_COMPOSITE_SIZE_UNDEFINED, PTR_INVALID_LIST_SIZE } from "../../errors"; +import { format, identity } from "../../util"; +import { ListElementSize } from "../list-element-size"; +import { ObjectSize, padToWord, getByteLength } from "../object-size"; +import { Segment } from "../segment"; +import { + Pointer, + getTargetListLength, + getListElementByteLength, + setStructPointer, + setListPointer, + initPointer, +} from "./pointer"; + +const trace = initTrace("capnp:list"); +trace("load"); + +export interface _ListCtor { + readonly compositeSize?: ObjectSize; + readonly displayName: string; + readonly size: ListElementSize; +} + +export interface ListCtor<T> { + readonly _capnp: _ListCtor; + + new (segment: Segment, byteOffset: number, depthLimit?: number): List<T>; +} + +export type FilterCallback<T> = (this: void, value: T, index: number) => boolean; +export type IndexedCallback<T, U> = (this: void, value: T, index: number) => U; + +export interface Group<T> { + [k: string]: T; +} + +/** + * A generic list class. Implements Filterable, + */ + +export class List<T> extends Pointer { + static readonly _capnp: _ListCtor = { + displayName: "List<Generic>" as string, + size: ListElementSize.VOID, + }; + static readonly get = get; + static readonly initList = initList; + static readonly set = set; + + static toString(): string { + return this._capnp.displayName; + } + + all(callbackfn: FilterCallback<T>): boolean { + const length = this.getLength(); + + for (let i = 0; i < length; i++) { + if (!callbackfn(this.get(i), i)) return false; + } + + return true; + } + + any(callbackfn: FilterCallback<T>): boolean { + const length = this.getLength(); + + for (let i = 0; i < length; i++) { + if (callbackfn(this.get(i), i)) return true; + } + + return false; + } + + ap<U>(callbackfns: Array<IndexedCallback<T, U>>): U[] { + const length = this.getLength(); + const res: U[] = []; + + for (let i = 0; i < length; i++) { + res.push(...callbackfns.map((f) => f(this.get(i), i))); + } + + return res; + } + + concat(other: List<T>): T[] { + const length = this.getLength(); + const otherLength = other.getLength(); + const res = new Array<T>(length + otherLength); + + for (let i = 0; i < length; i++) res[i] = this.get(i); + + for (let i = 0; i < otherLength; i++) res[i + length] = other.get(i); + + return res; + } + + drop(n: number): T[] { + const length = this.getLength(); + const res = new Array(length) as T[]; + + for (let i = n; i < length; i++) res[i] = this.get(i); + + return res; + } + + dropWhile(callbackfn: FilterCallback<T>): T[] { + const length = this.getLength(); + const res: T[] = []; + let drop = true; + + for (let i = 0; i < length; i++) { + const v = this.get(i); + + if (drop) drop = callbackfn(v, i); + + if (!drop) res.push(v); + } + + return res; + } + + empty(): T[] { + return [] as T[]; + } + + every(callbackfn: FilterCallback<T>): boolean { + return this.all(callbackfn); + } + + filter(callbackfn: FilterCallback<T>): T[] { + const length = this.getLength(); + const res: T[] = []; + + for (let i = 0; i < length; i++) { + const value = this.get(i); + + if (callbackfn(value, i)) res.push(value); + } + + return res; + } + + find(callbackfn: FilterCallback<T>): T | undefined { + const length = this.getLength(); + + for (let i = 0; i < length; i++) { + const value = this.get(i); + + if (callbackfn(value, i)) return value; + } + + return undefined; + } + + findIndex(callbackfn: FilterCallback<T>): number { + const length = this.getLength(); + + for (let i = 0; i < length; i++) { + const value = this.get(i); + + if (callbackfn(value, i)) return i; + } + + return -1; + } + + forEach(callbackfn: (this: void, value: T, index: number) => void): void { + const length = this.getLength(); + + for (let i = 0; i < length; i++) callbackfn(this.get(i), i); + } + + get(_index: number): T { + return get(_index, this); + } + + /** + * Get the length of this list. + * + * @returns {number} The number of elements in this list. + */ + + getLength(): number { + return getTargetListLength(this); + } + + groupBy(callbackfn: IndexedCallback<T, string>): Group<T> { + const length = this.getLength(); + const res: Group<T> = {}; + + for (let i = 0; i < length; i++) { + const v = this.get(i); + res[callbackfn(v, i)] = v; + } + + return res; + } + + intersperse(sep: T): T[] { + const length = this.getLength(); + const res = new Array(length) as T[]; + + for (let i = 0; i < length; i++) { + if (i > 0) res.push(sep); + + res.push(this.get(i)); + } + + return res; + } + + map<U>(callbackfn: IndexedCallback<T, U>): U[] { + const length = this.getLength(); + const res = new Array(length) as U[]; + + for (let i = 0; i < length; i++) res[i] = callbackfn(this.get(i), i); + + return res; + } + + reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number) => T): T; + reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number) => U, initialValue: U): U; + reduce<U>( + callbackfn: (previousValue: T | U, currentValue: T, currentIndex: number) => T | U, + initialValue?: U + ): T | U { + let i = 0; + let res: T | U; + + if (initialValue === undefined) { + res = this.get(0); + i++; + } else { + res = initialValue; + } + + for (; i < this.getLength(); i++) res = callbackfn(res, this.get(i), i); + + return res; + } + + set(_index: number, _value: T): void { + set(_index, _value, this); + } + + slice(start = 0, end?: number): T[] { + const length = end ? Math.min(this.getLength(), end) : this.getLength(); + const res = new Array(length - start) as T[]; + + for (let i = start; i < length; i++) res[i] = this.get(i); + + return res; + } + + some(callbackfn: FilterCallback<T>): boolean { + return this.any(callbackfn); + } + + take(n: number): T[] { + const length = Math.min(this.getLength(), n); + const res = new Array(length) as T[]; + + for (let i = 0; i < length; i++) res[i] = this.get(i); + + return res; + } + + takeWhile(callbackfn: FilterCallback<T>): T[] { + const length = this.getLength(); + const res: T[] = []; + let take; + + for (let i = 0; i < length; i++) { + const v = this.get(i); + + take = callbackfn(v, i); + + if (!take) return res; + + res.push(v); + } + + return res; + } + + toArray(): T[] { + return this.map(identity); + } + + toString(): string { + return `List_${super.toString()}`; + } +} + +/** + * Initialize the list with the given element size and length. This will allocate new space for the list, ideally in + * the same segment as this pointer. + * + * @param {ListElementSize} elementSize The size of each element in the list. + * @param {number} length The number of elements in the list. + * @param {List<T>} l The list to initialize. + * @param {ObjectSize} [compositeSize] The size of each element in a composite list. This value is required for + * composite lists. + * @returns {void} + */ + +export function initList<T>( + elementSize: ListElementSize, + length: number, + l: List<T>, + compositeSize?: ObjectSize +): void { + let c: Pointer; + + switch (elementSize) { + case ListElementSize.BIT: + c = l.segment.allocate(Math.ceil(length / 8)); + + break; + + case ListElementSize.BYTE: + case ListElementSize.BYTE_2: + case ListElementSize.BYTE_4: + case ListElementSize.BYTE_8: + case ListElementSize.POINTER: + c = l.segment.allocate(length * getListElementByteLength(elementSize)); + + break; + + case ListElementSize.COMPOSITE: { + if (compositeSize === undefined) { + throw new Error(format(PTR_COMPOSITE_SIZE_UNDEFINED)); + } + + compositeSize = padToWord(compositeSize); + + const byteLength = getByteLength(compositeSize) * length; + + // We need to allocate an extra 8 bytes for the tag word, then make sure we write the length to it. We advance + // the content pointer by 8 bytes so that it then points to the first list element as intended. Everything + // starts off zeroed out so these nested structs don't need to be initialized in any way. + + c = l.segment.allocate(byteLength + 8); + + setStructPointer(length, compositeSize, c); + + trace("Wrote composite tag word %s for %s.", c, l); + + break; + } + case ListElementSize.VOID: + // No need to allocate anything, we can write the list pointer right here. + + setListPointer(0, elementSize, length, l); + + return; + + default: + throw new Error(format(PTR_INVALID_LIST_SIZE, elementSize)); + } + + const res = initPointer(c.segment, c.byteOffset, l); + + setListPointer(res.offsetWords, elementSize, length, res.pointer, compositeSize); +} + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export function get<T>(_index: number, _l: List<T>): T { + throw new TypeError(); +} + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export function set<T>(_index: number, _value: T, _l: List<T>): void { + throw new TypeError(); +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/orphan.d.ts b/node_modules/capnp-ts/src/serialization/pointers/orphan.d.ts new file mode 100644 index 0000000..236305f --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/orphan.d.ts @@ -0,0 +1,38 @@ +import { ListElementSize } from "../list-element-size"; +import { ObjectSize } from "../object-size"; +import { Segment } from "../segment"; +import { Pointer } from "./pointer"; +import { PointerType } from "./pointer-type"; +export interface _Orphan { + capId: number; + elementSize: ListElementSize; + length: number; + size: ObjectSize; + type: PointerType; +} +/** + * An orphaned pointer. This object itself is technically a pointer to the original pointer's content, which was left + * untouched in its original message. The original pointer data is encoded as attributes on the Orphan object, ready to + * be reconstructed once another pointer is ready to adopt it. + * + * @export + * @class Orphan + * @extends {Pointer} + * @template T + */ +export declare class Orphan<T extends Pointer> { + /** If this member is not present then the orphan has already been adopted, or something went very wrong. */ + _capnp?: _Orphan; + byteOffset: number; + segment: Segment; + constructor(src: T); + /** + * Adopt (move) this orphan into the target pointer location. This will allocate far pointers in `dst` as needed. + * + * @param {T} dst The destination pointer. + * @returns {void} + */ + _moveTo(dst: T): void; + dispose(): void; + toString(): string; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/orphan.js b/node_modules/capnp-ts/src/serialization/pointers/orphan.js new file mode 100644 index 0000000..6641afa --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/orphan.js @@ -0,0 +1,120 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Orphan = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const errors_1 = require("../../errors"); +const util_1 = require("../../util"); +const list_element_size_1 = require("../list-element-size"); +const object_size_1 = require("../object-size"); +const pointer_1 = require("./pointer"); +const pointer_type_1 = require("./pointer-type"); +const trace = debug_1.default("capnp:orphan"); +trace("load"); +// Technically speaking this class doesn't need to be generic, but the extra type checking enforced by this helps to +// make sure you don't accidentally adopt a pointer of the wrong type. +/** + * An orphaned pointer. This object itself is technically a pointer to the original pointer's content, which was left + * untouched in its original message. The original pointer data is encoded as attributes on the Orphan object, ready to + * be reconstructed once another pointer is ready to adopt it. + * + * @export + * @class Orphan + * @extends {Pointer} + * @template T + */ +class Orphan { + constructor(src) { + const c = pointer_1.getContent(src); + this.segment = c.segment; + this.byteOffset = c.byteOffset; + this._capnp = {}; + // Read vital info from the src pointer so we can reconstruct it during adoption. + this._capnp.type = pointer_1.getTargetPointerType(src); + switch (this._capnp.type) { + case pointer_type_1.PointerType.STRUCT: + this._capnp.size = pointer_1.getTargetStructSize(src); + break; + case pointer_type_1.PointerType.LIST: + this._capnp.length = pointer_1.getTargetListLength(src); + this._capnp.elementSize = pointer_1.getTargetListElementSize(src); + if (this._capnp.elementSize === list_element_size_1.ListElementSize.COMPOSITE) { + this._capnp.size = pointer_1.getTargetCompositeListSize(src); + } + break; + case pointer_type_1.PointerType.OTHER: + this._capnp.capId = pointer_1.getCapabilityId(src); + break; + default: + // COVERAGE: Unreachable code. + /* istanbul ignore next */ + throw new Error(errors_1.PTR_INVALID_POINTER_TYPE); + } + // Zero out the source pointer (but not the contents!). + pointer_1.erasePointer(src); + } + /** + * Adopt (move) this orphan into the target pointer location. This will allocate far pointers in `dst` as needed. + * + * @param {T} dst The destination pointer. + * @returns {void} + */ + _moveTo(dst) { + if (this._capnp === undefined) { + throw new Error(util_1.format(errors_1.PTR_ALREADY_ADOPTED, this)); + } + // TODO: Implement copy semantics when this happens. + if (this.segment.message !== dst.segment.message) { + throw new Error(util_1.format(errors_1.PTR_ADOPT_WRONG_MESSAGE, this, dst)); + } + // Recursively wipe out the destination pointer first. + pointer_1.erase(dst); + const res = pointer_1.initPointer(this.segment, this.byteOffset, dst); + switch (this._capnp.type) { + case pointer_type_1.PointerType.STRUCT: + pointer_1.setStructPointer(res.offsetWords, this._capnp.size, res.pointer); + break; + case pointer_type_1.PointerType.LIST: { + let offsetWords = res.offsetWords; + if (this._capnp.elementSize === list_element_size_1.ListElementSize.COMPOSITE) { + offsetWords--; // The tag word gets skipped. + } + pointer_1.setListPointer(offsetWords, this._capnp.elementSize, this._capnp.length, res.pointer, this._capnp.size); + break; + } + case pointer_type_1.PointerType.OTHER: + pointer_1.setInterfacePointer(this._capnp.capId, res.pointer); + break; + /* istanbul ignore next */ + default: + throw new Error(errors_1.PTR_INVALID_POINTER_TYPE); + } + this._capnp = undefined; + } + dispose() { + // FIXME: Should this throw? + if (this._capnp === undefined) { + trace("not disposing an already disposed orphan", this); + return; + } + switch (this._capnp.type) { + case pointer_type_1.PointerType.STRUCT: + this.segment.fillZeroWords(this.byteOffset, object_size_1.getWordLength(this._capnp.size)); + break; + case pointer_type_1.PointerType.LIST: { + const byteLength = pointer_1.getListByteLength(this._capnp.elementSize, this._capnp.length, this._capnp.size); + this.segment.fillZeroWords(this.byteOffset, byteLength); + break; + } + default: + // Other pointer types don't actually have any content. + break; + } + this._capnp = undefined; + } + toString() { + return util_1.format("Orphan_%d@%a,type:%s", this.segment.id, this.byteOffset, this._capnp && this._capnp.type); + } +} +exports.Orphan = Orphan; +//# sourceMappingURL=orphan.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/orphan.js.map b/node_modules/capnp-ts/src/serialization/pointers/orphan.js.map new file mode 100644 index 0000000..668cece --- /dev/null +++ b/node_modules/capnp-ts/src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AI,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3G,CAAC;CACF;AAxID,wBAwIC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/orphan.ts b/node_modules/capnp-ts/src/serialization/pointers/orphan.ts new file mode 100644 index 0000000..76c480c --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/orphan.ts @@ -0,0 +1,188 @@ +import initTrace from "debug"; + +import { PTR_ADOPT_WRONG_MESSAGE, PTR_ALREADY_ADOPTED, PTR_INVALID_POINTER_TYPE } from "../../errors"; +import { format } from "../../util"; +import { ListElementSize } from "../list-element-size"; +import { ObjectSize, getWordLength } from "../object-size"; +import { Segment } from "../segment"; +import { + Pointer, + getTargetListLength, + getTargetStructSize, + getTargetPointerType, + getTargetListElementSize, + getTargetCompositeListSize, + getCapabilityId, + getContent, + erasePointer, + initPointer, + erase, + setStructPointer, + setListPointer, + setInterfacePointer, + getListByteLength, +} from "./pointer"; +import { PointerType } from "./pointer-type"; + +const trace = initTrace("capnp:orphan"); +trace("load"); + +export interface _Orphan { + capId: number; + elementSize: ListElementSize; + length: number; + size: ObjectSize; + type: PointerType; +} + +// Technically speaking this class doesn't need to be generic, but the extra type checking enforced by this helps to +// make sure you don't accidentally adopt a pointer of the wrong type. + +/** + * An orphaned pointer. This object itself is technically a pointer to the original pointer's content, which was left + * untouched in its original message. The original pointer data is encoded as attributes on the Orphan object, ready to + * be reconstructed once another pointer is ready to adopt it. + * + * @export + * @class Orphan + * @extends {Pointer} + * @template T + */ + +export class Orphan<T extends Pointer> { + /** If this member is not present then the orphan has already been adopted, or something went very wrong. */ + _capnp?: _Orphan; + + byteOffset: number; + segment: Segment; + + constructor(src: T) { + const c = getContent(src); + + this.segment = c.segment; + this.byteOffset = c.byteOffset; + + this._capnp = {} as _Orphan; + + // Read vital info from the src pointer so we can reconstruct it during adoption. + + this._capnp.type = getTargetPointerType(src); + + switch (this._capnp.type) { + case PointerType.STRUCT: + this._capnp.size = getTargetStructSize(src); + + break; + + case PointerType.LIST: + this._capnp.length = getTargetListLength(src); + this._capnp.elementSize = getTargetListElementSize(src); + + if (this._capnp.elementSize === ListElementSize.COMPOSITE) { + this._capnp.size = getTargetCompositeListSize(src); + } + + break; + + case PointerType.OTHER: + this._capnp.capId = getCapabilityId(src); + + break; + + default: + // COVERAGE: Unreachable code. + /* istanbul ignore next */ + throw new Error(PTR_INVALID_POINTER_TYPE); + } + + // Zero out the source pointer (but not the contents!). + + erasePointer(src); + } + + /** + * Adopt (move) this orphan into the target pointer location. This will allocate far pointers in `dst` as needed. + * + * @param {T} dst The destination pointer. + * @returns {void} + */ + + _moveTo(dst: T): void { + if (this._capnp === undefined) { + throw new Error(format(PTR_ALREADY_ADOPTED, this)); + } + + // TODO: Implement copy semantics when this happens. + if (this.segment.message !== dst.segment.message) { + throw new Error(format(PTR_ADOPT_WRONG_MESSAGE, this, dst)); + } + + // Recursively wipe out the destination pointer first. + + erase(dst); + + const res = initPointer(this.segment, this.byteOffset, dst); + + switch (this._capnp.type) { + case PointerType.STRUCT: + setStructPointer(res.offsetWords, this._capnp.size, res.pointer); + + break; + + case PointerType.LIST: { + let offsetWords = res.offsetWords; + + if (this._capnp.elementSize === ListElementSize.COMPOSITE) { + offsetWords--; // The tag word gets skipped. + } + + setListPointer(offsetWords, this._capnp.elementSize, this._capnp.length, res.pointer, this._capnp.size); + + break; + } + case PointerType.OTHER: + setInterfacePointer(this._capnp.capId, res.pointer); + + break; + + /* istanbul ignore next */ + default: + throw new Error(PTR_INVALID_POINTER_TYPE); + } + + this._capnp = undefined; + } + + dispose(): void { + // FIXME: Should this throw? + if (this._capnp === undefined) { + trace("not disposing an already disposed orphan", this); + + return; + } + + switch (this._capnp.type) { + case PointerType.STRUCT: + this.segment.fillZeroWords(this.byteOffset, getWordLength(this._capnp.size)); + + break; + + case PointerType.LIST: { + const byteLength = getListByteLength(this._capnp.elementSize, this._capnp.length, this._capnp.size); + this.segment.fillZeroWords(this.byteOffset, byteLength); + + break; + } + default: + // Other pointer types don't actually have any content. + + break; + } + + this._capnp = undefined; + } + + toString(): string { + return format("Orphan_%d@%a,type:%s", this.segment.id, this.byteOffset, this._capnp && this._capnp.type); + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/pointer-allocation-result.d.ts b/node_modules/capnp-ts/src/serialization/pointers/pointer-allocation-result.d.ts new file mode 100644 index 0000000..d004868 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/pointer-allocation-result.d.ts @@ -0,0 +1,18 @@ +/** + * @author jdiaz5513 + */ +import { Pointer } from "./pointer"; +/** + * This is used as the return value for `Pointer.prototype.initPointer`. Turns out using a class in V8 for multiple + * return values is faster than using an array or anonymous object. + * + * http://jsben.ch/#/zTdbD + * + * @export + * @class PointerAllocationResult + */ +export declare class PointerAllocationResult { + readonly offsetWords: number; + readonly pointer: Pointer; + constructor(pointer: Pointer, offsetWords: number); +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/pointer-allocation-result.js b/node_modules/capnp-ts/src/serialization/pointers/pointer-allocation-result.js new file mode 100644 index 0000000..7d5e928 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/pointer-allocation-result.js @@ -0,0 +1,27 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.PointerAllocationResult = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const trace = debug_1.default("capnp:pointer-allocation-result"); +trace("load"); +/** + * This is used as the return value for `Pointer.prototype.initPointer`. Turns out using a class in V8 for multiple + * return values is faster than using an array or anonymous object. + * + * http://jsben.ch/#/zTdbD + * + * @export + * @class PointerAllocationResult + */ +class PointerAllocationResult { + constructor(pointer, offsetWords) { + this.pointer = pointer; + this.offsetWords = offsetWords; + } +} +exports.PointerAllocationResult = PointerAllocationResult; +//# sourceMappingURL=pointer-allocation-result.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/pointer-allocation-result.js.map b/node_modules/capnp-ts/src/serialization/pointers/pointer-allocation-result.js.map new file mode 100644 index 0000000..fe7418f --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/pointer-allocation-result.js.map @@ -0,0 +1 @@ +{"version":3,"file":"pointer-allocation-result.js","sourceRoot":"","sources":["pointer-allocation-result.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAI9B,MAAM,KAAK,GAAG,eAAS,CAAC,iCAAiC,CAAC,CAAC;AAC3D,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd;;;;;;;;GAQG;AAEH,MAAa,uBAAuB;IAKlC,YAAY,OAAgB,EAAE,WAAmB;QAC/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;CACF;AATD,0DASC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/pointer-allocation-result.ts b/node_modules/capnp-ts/src/serialization/pointers/pointer-allocation-result.ts new file mode 100644 index 0000000..ffa436e --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/pointer-allocation-result.ts @@ -0,0 +1,31 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { Pointer } from "./pointer"; + +const trace = initTrace("capnp:pointer-allocation-result"); +trace("load"); + +/** + * This is used as the return value for `Pointer.prototype.initPointer`. Turns out using a class in V8 for multiple + * return values is faster than using an array or anonymous object. + * + * http://jsben.ch/#/zTdbD + * + * @export + * @class PointerAllocationResult + */ + +export class PointerAllocationResult { + readonly offsetWords: number; + + readonly pointer: Pointer; + + constructor(pointer: Pointer, offsetWords: number) { + this.pointer = pointer; + this.offsetWords = offsetWords; + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/pointer-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/pointer-list.d.ts new file mode 100644 index 0000000..5c1303b --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/pointer-list.d.ts @@ -0,0 +1,6 @@ +/** + * @author jdiaz5513 + */ +import { ListCtor } from "./list"; +import { Pointer, PointerCtor } from "./pointer"; +export declare function PointerList<T extends Pointer>(PointerClass: PointerCtor<T>): ListCtor<T>; diff --git a/node_modules/capnp-ts/src/serialization/pointers/pointer-list.js b/node_modules/capnp-ts/src/serialization/pointers/pointer-list.js new file mode 100644 index 0000000..39a10f7 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/pointer-list.js @@ -0,0 +1,35 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.PointerList = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const list_element_size_1 = require("../list-element-size"); +const list_1 = require("./list"); +const pointer_1 = require("./pointer"); +const trace = debug_1.default("capnp:list:composite"); +trace("load"); +function PointerList(PointerClass) { + var _a; + return _a = class extends list_1.List { + get(index) { + const c = pointer_1.getContent(this); + return new PointerClass(c.segment, c.byteOffset + index * 8, this._capnp.depthLimit - 1); + } + set(index, value) { + pointer_1.copyFrom(value, this.get(index)); + } + toString() { + return `Pointer_${super.toString()},cls:${PointerClass.toString()}`; + } + }, + _a._capnp = { + displayName: `List<${PointerClass._capnp.displayName}>`, + size: list_element_size_1.ListElementSize.POINTER, + }, + _a; +} +exports.PointerList = PointerList; +//# sourceMappingURL=pointer-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/pointer-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/pointer-list.js.map new file mode 100644 index 0000000..165aaba --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/pointer-list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"pointer-list.js","sourceRoot":"","sources":["pointer-list.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,4DAAuD;AACvD,iCAAmD;AACnD,uCAAuE;AAEvE,MAAM,KAAK,GAAG,eAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,SAAgB,WAAW,CAAoB,YAA4B;;IACzE,YAAO,KAAM,SAAQ,WAAO;YAM1B,GAAG,CAAC,KAAa;gBACf,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;gBAC3B,OAAO,IAAI,YAAY,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,UAAU,GAAG,KAAK,GAAG,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;YAC3F,CAAC;YAED,GAAG,CAAC,KAAa,EAAE,KAAQ;gBACzB,kBAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;YACnC,CAAC;YAED,QAAQ;gBACN,OAAO,WAAW,KAAK,CAAC,QAAQ,EAAE,QAAQ,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAC;YACtE,CAAC;SACF;QAjBiB,SAAM,GAAc;YAClC,WAAW,EAAE,QAAQ,YAAY,CAAC,MAAM,CAAC,WAAW,GAAG;YACvD,IAAI,EAAE,mCAAe,CAAC,OAAO;SAC7B;WAcF;AACJ,CAAC;AApBD,kCAoBC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/pointer-list.ts b/node_modules/capnp-ts/src/serialization/pointers/pointer-list.ts new file mode 100644 index 0000000..d71f8b1 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/pointer-list.ts @@ -0,0 +1,34 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { ListElementSize } from "../list-element-size"; +import { _ListCtor, List, ListCtor } from "./list"; +import { Pointer, PointerCtor, getContent, copyFrom } from "./pointer"; + +const trace = initTrace("capnp:list:composite"); +trace("load"); + +export function PointerList<T extends Pointer>(PointerClass: PointerCtor<T>): ListCtor<T> { + return class extends List<T> { + static readonly _capnp: _ListCtor = { + displayName: `List<${PointerClass._capnp.displayName}>`, + size: ListElementSize.POINTER, + }; + + get(index: number): T { + const c = getContent(this); + return new PointerClass(c.segment, c.byteOffset + index * 8, this._capnp.depthLimit - 1); + } + + set(index: number, value: T): void { + copyFrom(value, this.get(index)); + } + + toString(): string { + return `Pointer_${super.toString()},cls:${PointerClass.toString()}`; + } + }; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/pointer-type.d.ts b/node_modules/capnp-ts/src/serialization/pointers/pointer-type.d.ts new file mode 100644 index 0000000..f8b3c4c --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/pointer-type.d.ts @@ -0,0 +1,9 @@ +/** + * @author jdiaz5513 + */ +export declare enum PointerType { + STRUCT = 0, + LIST = 1, + FAR = 2, + OTHER = 3 +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/pointer-type.js b/node_modules/capnp-ts/src/serialization/pointers/pointer-type.js new file mode 100644 index 0000000..c81c2fc --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/pointer-type.js @@ -0,0 +1,14 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.PointerType = void 0; +var PointerType; +(function (PointerType) { + PointerType[PointerType["STRUCT"] = 0] = "STRUCT"; + PointerType[PointerType["LIST"] = 1] = "LIST"; + PointerType[PointerType["FAR"] = 2] = "FAR"; + PointerType[PointerType["OTHER"] = 3] = "OTHER"; +})(PointerType = exports.PointerType || (exports.PointerType = {})); +//# sourceMappingURL=pointer-type.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/pointer-type.js.map b/node_modules/capnp-ts/src/serialization/pointers/pointer-type.js.map new file mode 100644 index 0000000..02591b4 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/pointer-type.js.map @@ -0,0 +1 @@ +{"version":3,"file":"pointer-type.js","sourceRoot":"","sources":["pointer-type.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,iDAAU,CAAA;IACV,6CAAQ,CAAA;IACR,2CAAO,CAAA;IACP,+CAAS,CAAA;AACX,CAAC,EALW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAKtB"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/pointer-type.ts b/node_modules/capnp-ts/src/serialization/pointers/pointer-type.ts new file mode 100644 index 0000000..ad8f91d --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/pointer-type.ts @@ -0,0 +1,10 @@ +/** + * @author jdiaz5513 + */ + +export enum PointerType { + STRUCT = 0, + LIST = 1, + FAR = 2, + OTHER = 3 +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/pointer.d.ts b/node_modules/capnp-ts/src/serialization/pointers/pointer.d.ts new file mode 100644 index 0000000..9199148 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/pointer.d.ts @@ -0,0 +1,362 @@ +/** + * @author jdiaz5513 + */ +import { ListElementSize } from "../list-element-size"; +import { ObjectSize } from "../object-size"; +import { Segment } from "../segment"; +import { Orphan } from "./orphan"; +import { PointerAllocationResult } from "./pointer-allocation-result"; +import { PointerType } from "./pointer-type"; +import { Message } from "../message"; +export interface _PointerCtor { + readonly displayName: string; +} +export interface PointerCtor<T extends Pointer> { + readonly _capnp: _PointerCtor; + new (segment: Segment, byteOffset: number, depthLimit?: number): T; +} +export interface _Pointer { + compositeIndex?: number; + compositeList: boolean; + /** + * A number that is decremented as nested pointers are traversed. When this hits zero errors will be thrown. + */ + depthLimit: number; +} +/** + * A pointer referencing a single byte location in a segment. This is typically used for Cap'n Proto pointers, but is + * also sometimes used to reference an offset to a pointer's content or tag words. + * + * @export + * @class Pointer + */ +export declare class Pointer { + static readonly adopt: typeof adopt; + static readonly copyFrom: typeof copyFrom; + static readonly disown: typeof disown; + static readonly dump: typeof dump; + static readonly isNull: typeof isNull; + static readonly _capnp: _PointerCtor; + readonly _capnp: _Pointer; + /** Offset, in bytes, from the start of the segment to the beginning of this pointer. */ + byteOffset: number; + /** + * The starting segment for this pointer's data. In the case of a far pointer, the actual content this pointer is + * referencing will be in another segment within the same message. + */ + segment: Segment; + constructor(segment: Segment, byteOffset: number, depthLimit?: number); + toString(): string; +} +/** + * Adopt an orphaned pointer, making the pointer point to the orphaned content without copying it. + * + * @param {Orphan<Pointer>} src The orphan to adopt. + * @param {Pointer} p The the pointer to adopt into. + * @returns {void} + */ +export declare function adopt<T extends Pointer>(src: Orphan<T>, p: T): void; +/** + * Convert a pointer to an Orphan, zeroing out the pointer and leaving its content untouched. If the content is no + * longer needed, call `disown()` on the orphaned pointer to erase the contents as well. + * + * Call `adopt()` on the orphan with the new target pointer location to move it back into the message; the orphan + * object is then invalidated after adoption (can only adopt once!). + * + * @param {T} p The pointer to turn into an Orphan. + * @returns {Orphan<T>} An orphaned pointer. + */ +export declare function disown<T extends Pointer>(p: T): Orphan<T>; +export declare function dump(p: Pointer): string; +/** + * Get the total number of bytes required to hold a list of the provided size with the given length, rounded up to the + * nearest word. + * + * @param {ListElementSize} elementSize A number describing the size of the list elements. + * @param {number} length The length of the list. + * @param {ObjectSize} [compositeSize] The size of each element in a composite list; required if + * `elementSize === ListElementSize.COMPOSITE`. + * @returns {number} The number of bytes required to hold an element of that size, or `NaN` if that is undefined. + */ +export declare function getListByteLength(elementSize: ListElementSize, length: number, compositeSize?: ObjectSize): number; +/** + * Get the number of bytes required to hold a list element of the provided size. `COMPOSITE` elements do not have a + * fixed size, and `BIT` elements are packed into exactly a single bit, so these both return `NaN`. + * + * @param {ListElementSize} elementSize A number describing the size of the list elements. + * @returns {number} The number of bytes required to hold an element of that size, or `NaN` if that is undefined. + */ +export declare function getListElementByteLength(elementSize: ListElementSize): number; +/** + * Add an offset to the pointer's offset and return a new Pointer for that address. + * + * @param {number} offset The number of bytes to add to the offset. + * @param {Pointer} p The pointer to add from. + * @returns {Pointer} A new pointer to the address. + */ +export declare function add(offset: number, p: Pointer): Pointer; +/** + * Replace a pointer with a deep copy of the pointer at `src` and all of its contents. + * + * @param {Pointer} src The pointer to copy. + * @param {Pointer} p The pointer to copy into. + * @returns {void} + */ +export declare function copyFrom(src: Pointer, p: Pointer): void; +/** + * Recursively erase a pointer, any far pointers/landing pads/tag words, and the content it points to. + * + * Note that this will leave "holes" of zeroes in the message, since the space cannot be reclaimed. With packing this + * will have a negligible effect on the final message size. + * + * FIXME: This may need protection against infinite recursion... + * + * @param {Pointer} p The pointer to erase. + * @returns {void} + */ +export declare function erase(p: Pointer): void; +/** + * Set the pointer (and far pointer landing pads, if applicable) to zero. Does not touch the pointer's content. + * + * @param {Pointer} p The pointer to erase. + * @returns {void} + */ +export declare function erasePointer(p: Pointer): void; +/** + * Interpret the pointer as a far pointer, returning its target segment and offset. + * + * @param {Pointer} p The pointer to read from. + * @returns {Pointer} A pointer to the far target. + */ +export declare function followFar(p: Pointer): Pointer; +/** + * If the pointer address references a far pointer, follow it to the location where the actual pointer data is written. + * Otherwise, returns the pointer unmodified. + * + * @param {Pointer} p The pointer to read from. + * @returns {Pointer} A new pointer representing the target location, or `p` if it is not a far pointer. + */ +export declare function followFars(p: Pointer): Pointer; +export declare function getCapabilityId(p: Pointer): number; +/** + * Obtain the location of the pointer's content, following far pointers as needed. + * If the pointer is a struct pointer and `compositeIndex` is set, it will be offset by a multiple of the struct's size. + * + * @param {Pointer} p The pointer to read from. + * @param {boolean} [ignoreCompositeIndex] If true, will not follow the composite struct pointer's composite index and + * instead return a pointer to the parent list's contents (also the beginning of the first struct). + * @returns {Pointer} A pointer to the beginning of the pointer's content. + */ +export declare function getContent(p: Pointer, ignoreCompositeIndex?: boolean): Pointer; +/** + * Read the target segment ID from a far pointer. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The target segment ID. + */ +export declare function getFarSegmentId(p: Pointer): number; +/** + * Get a number indicating the size of the list's elements. + * + * @param {Pointer} p The pointer to read from. + * @returns {ListElementSize} The size of the list's elements. + */ +export declare function getListElementSize(p: Pointer): ListElementSize; +/** + * Get the number of elements in a list pointer. For composite lists, it instead represents the total number of words in + * the list (not counting the tag word). + * + * This method does **not** attempt to distinguish between composite and non-composite lists. To get the correct + * length for composite lists use `getTargetListLength()` instead. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The length of the list, or total number of words for composite lists. + */ +export declare function getListLength(p: Pointer): number; +/** + * Get the offset (in words) from the end of a pointer to the start of its content. For struct pointers, this is the + * beginning of the data section, and for list pointers it is the location of the first element. The value should + * always be zero for interface pointers. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The offset, in words, from the end of the pointer to the start of the data section. + */ +export declare function getOffsetWords(p: Pointer): number; +/** + * Look up the pointer's type. + * + * @param {Pointer} p The pointer to read from. + * @returns {PointerType} The type of pointer. + */ +export declare function getPointerType(p: Pointer): PointerType; +/** + * Read the number of data words from this struct pointer. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The number of data words in the struct. + */ +export declare function getStructDataWords(p: Pointer): number; +/** + * Read the number of pointers contained in this struct pointer. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The number of pointers in this struct. + */ +export declare function getStructPointerLength(p: Pointer): number; +/** + * Get an object describing this struct pointer's size. + * + * @param {Pointer} p The pointer to read from. + * @returns {ObjectSize} The size of the struct. + */ +export declare function getStructSize(p: Pointer): ObjectSize; +/** + * Get a pointer to this pointer's composite list tag word, following far pointers as needed. + * + * @param {Pointer} p The pointer to read from. + * @returns {Pointer} A pointer to the list's composite tag word. + */ +export declare function getTargetCompositeListTag(p: Pointer): Pointer; +/** + * Get the object size for the target composite list, following far pointers as needed. + * + * @param {Pointer} p The pointer to read from. + * @returns {ObjectSize} An object describing the size of each struct in the list. + */ +export declare function getTargetCompositeListSize(p: Pointer): ObjectSize; +/** + * Get the size of the list elements referenced by this pointer, following far pointers if necessary. + * + * @param {Pointer} p The pointer to read from. + * @returns {ListElementSize} The size of the elements in the list. + */ +export declare function getTargetListElementSize(p: Pointer): ListElementSize; +/** + * Get the length of the list referenced by this pointer, following far pointers if necessary. If the list is a + * composite list, it will look up the tag word and read the length from there. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The number of elements in the list. + */ +export declare function getTargetListLength(p: Pointer): number; +/** + * Get the type of a pointer, following far pointers if necessary. For non-far pointers this is equivalent to calling + * `getPointerType()`. + * + * The target of a far pointer can never be another far pointer, and this method will throw if such a situation is + * encountered. + * + * @param {Pointer} p The pointer to read from. + * @returns {PointerType} The type of pointer referenced by this pointer. + */ +export declare function getTargetPointerType(p: Pointer): PointerType; +/** + * Get the size of the struct referenced by a pointer, following far pointers if necessary. + * + * @param {Pointer} p The poiner to read from. + * @returns {ObjectSize} The size of the struct referenced by this pointer. + */ +export declare function getTargetStructSize(p: Pointer): ObjectSize; +/** + * Initialize a pointer to point at the data in the content segment. If the content segment is not the same as the + * pointer's segment, this will allocate and write far pointers as needed. Nothing is written otherwise. + * + * The return value includes a pointer to write the pointer's actual data to (the eventual far target), and the offset + * value (in words) to use for that pointer. In the case of double-far pointers this offset will always be zero. + * + * @param {Segment} contentSegment The segment containing this pointer's content. + * @param {number} contentOffset The offset within the content segment for the beginning of this pointer's content. + * @param {Pointer} p The pointer to initialize. + * @returns {PointerAllocationResult} An object containing a pointer (where the pointer data should be written), and + * the value to use as the offset for that pointer. + */ +export declare function initPointer(contentSegment: Segment, contentOffset: number, p: Pointer): PointerAllocationResult; +/** + * Check if the pointer is a double-far pointer. + * + * @param {Pointer} p The pointer to read from. + * @returns {boolean} `true` if it is a double-far pointer, `false` otherwise. + */ +export declare function isDoubleFar(p: Pointer): boolean; +/** + * Quickly check to see if the pointer is "null". A "null" pointer is a zero word, equivalent to an empty struct + * pointer. + * + * @param {Pointer} p The pointer to read from. + * @returns {boolean} `true` if the pointer is "null". + */ +export declare function isNull(p: Pointer): boolean; +/** + * Relocate a pointer to the given destination, ensuring that it points to the same content. This will create far + * pointers as needed if the content is in a different segment than the destination. After the relocation the source + * pointer will be erased and is no longer valid. + * + * @param {Pointer} dst The desired location for the `src` pointer. Any existing contents will be erased before + * relocating! + * @param {Pointer} src The pointer to relocate. + * @returns {void} + */ +export declare function relocateTo(dst: Pointer, src: Pointer): void; +/** + * Write a far pointer. + * + * @param {boolean} doubleFar Set to `true` if this is a double far pointer. + * @param {number} offsetWords The offset, in words, to the target pointer. + * @param {number} segmentId The segment the target pointer is located in. + * @param {Pointer} p The pointer to write to. + * @returns {void} + */ +export declare function setFarPointer(doubleFar: boolean, offsetWords: number, segmentId: number, p: Pointer): void; +/** + * Write a raw interface pointer. + * + * @param {number} capId The capability ID. + * @param {Pointer} p The pointer to write to. + * @returns {void} + */ +export declare function setInterfacePointer(capId: number, p: Pointer): void; +/** + * Write a raw list pointer. + * + * @param {number} offsetWords The number of words from the end of this pointer to the beginning of the list content. + * @param {ListElementSize} size The size of each element in the list. + * @param {number} length The number of elements in the list. + * @param {Pointer} p The pointer to write to. + * @param {ObjectSize} [compositeSize] For composite lists this describes the size of each element in this list. This + * is required for composite lists. + * @returns {void} + */ +export declare function setListPointer(offsetWords: number, size: ListElementSize, length: number, p: Pointer, compositeSize?: ObjectSize): void; +/** + * Write a raw struct pointer. + * + * @param {number} offsetWords The number of words from the end of this pointer to the beginning of the struct's data + * section. + * @param {ObjectSize} size An object describing the size of the struct. + * @param {Pointer} p The pointer to write to. + * @returns {void} + */ +export declare function setStructPointer(offsetWords: number, size: ObjectSize, p: Pointer): void; +/** + * Read some bits off a pointer to make sure it has the right pointer data. + * + * @param {PointerType} pointerType The expected pointer type. + * @param {Pointer} p The pointer to validate. + * @param {ListElementSize} [elementSize] For list pointers, the expected element size. Leave this + * undefined for struct pointers. + * @returns {void} + */ +export declare function validate(pointerType: PointerType, p: Pointer, elementSize?: ListElementSize): void; +export declare function copyFromList(src: Pointer, dst: Pointer): void; +export declare function copyFromStruct(src: Pointer, dst: Pointer): void; +/** + * Track the allocation of a new Pointer object. + * + * This will decrement an internal counter tracking how many bytes have been traversed in the message so far. After + * a certain limit, this method will throw an error in order to prevent a certain class of DoS attacks. + * + * @param {Message} message The message the pointer belongs to. + * @param {Pointer} p The pointer being allocated. + * @returns {void} + */ +export declare function trackPointerAllocation(message: Message, p: Pointer): void; diff --git a/node_modules/capnp-ts/src/serialization/pointers/pointer.js b/node_modules/capnp-ts/src/serialization/pointers/pointer.js new file mode 100644 index 0000000..711bfbc --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/pointer.js @@ -0,0 +1,795 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.trackPointerAllocation = exports.copyFromStruct = exports.copyFromList = exports.validate = exports.setStructPointer = exports.setListPointer = exports.setInterfacePointer = exports.setFarPointer = exports.relocateTo = exports.isNull = exports.isDoubleFar = exports.initPointer = exports.getTargetStructSize = exports.getTargetPointerType = exports.getTargetListLength = exports.getTargetListElementSize = exports.getTargetCompositeListSize = exports.getTargetCompositeListTag = exports.getStructSize = exports.getStructPointerLength = exports.getStructDataWords = exports.getPointerType = exports.getOffsetWords = exports.getListLength = exports.getListElementSize = exports.getFarSegmentId = exports.getContent = exports.getCapabilityId = exports.followFars = exports.followFar = exports.erasePointer = exports.erase = exports.copyFrom = exports.add = exports.getListElementByteLength = exports.getListByteLength = exports.dump = exports.disown = exports.adopt = exports.Pointer = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const constants_1 = require("../../constants"); +const util_1 = require("../../util"); +const list_element_size_1 = require("../list-element-size"); +const object_size_1 = require("../object-size"); +const orphan_1 = require("./orphan"); +const pointer_allocation_result_1 = require("./pointer-allocation-result"); +const pointer_type_1 = require("./pointer-type"); +const errors_1 = require("../../errors"); +const trace = debug_1.default("capnp:pointer"); +trace("load"); +/** + * A pointer referencing a single byte location in a segment. This is typically used for Cap'n Proto pointers, but is + * also sometimes used to reference an offset to a pointer's content or tag words. + * + * @export + * @class Pointer + */ +class Pointer { + constructor(segment, byteOffset, depthLimit = constants_1.MAX_DEPTH) { + this._capnp = { compositeList: false, depthLimit }; + this.segment = segment; + this.byteOffset = byteOffset; + if (depthLimit === 0) { + throw new Error(util_1.format(errors_1.PTR_DEPTH_LIMIT_EXCEEDED, this)); + } + // Make sure we keep track of all pointer allocations; there's a limit per message (prevent DoS). + trackPointerAllocation(segment.message, this); + // NOTE: It's okay to have a pointer to the end of the segment; you'll see this when creating pointers to the + // beginning of the content of a newly-allocated composite list with zero elements. Unlike other language + // implementations buffer over/underflows are not a big issue since all buffer access is bounds checked in native + // code anyway. + if (byteOffset < 0 || byteOffset > segment.byteLength) { + throw new Error(util_1.format(errors_1.PTR_OFFSET_OUT_OF_BOUNDS, byteOffset)); + } + trace("new %s", this); + } + toString() { + return util_1.format("Pointer_%d@%a,%s,limit:%x", this.segment.id, this.byteOffset, dump(this), this._capnp.depthLimit); + } +} +exports.Pointer = Pointer; +Pointer.adopt = adopt; +Pointer.copyFrom = copyFrom; +Pointer.disown = disown; +Pointer.dump = dump; +Pointer.isNull = isNull; +Pointer._capnp = { + displayName: "Pointer", +}; +/** + * Adopt an orphaned pointer, making the pointer point to the orphaned content without copying it. + * + * @param {Orphan<Pointer>} src The orphan to adopt. + * @param {Pointer} p The the pointer to adopt into. + * @returns {void} + */ +function adopt(src, p) { + src._moveTo(p); +} +exports.adopt = adopt; +/** + * Convert a pointer to an Orphan, zeroing out the pointer and leaving its content untouched. If the content is no + * longer needed, call `disown()` on the orphaned pointer to erase the contents as well. + * + * Call `adopt()` on the orphan with the new target pointer location to move it back into the message; the orphan + * object is then invalidated after adoption (can only adopt once!). + * + * @param {T} p The pointer to turn into an Orphan. + * @returns {Orphan<T>} An orphaned pointer. + */ +function disown(p) { + return new orphan_1.Orphan(p); +} +exports.disown = disown; +function dump(p) { + return util_1.bufferToHex(p.segment.buffer.slice(p.byteOffset, p.byteOffset + 8)); +} +exports.dump = dump; +/** + * Get the total number of bytes required to hold a list of the provided size with the given length, rounded up to the + * nearest word. + * + * @param {ListElementSize} elementSize A number describing the size of the list elements. + * @param {number} length The length of the list. + * @param {ObjectSize} [compositeSize] The size of each element in a composite list; required if + * `elementSize === ListElementSize.COMPOSITE`. + * @returns {number} The number of bytes required to hold an element of that size, or `NaN` if that is undefined. + */ +function getListByteLength(elementSize, length, compositeSize) { + switch (elementSize) { + case list_element_size_1.ListElementSize.BIT: + return util_1.padToWord((length + 7) >>> 3); + case list_element_size_1.ListElementSize.BYTE: + case list_element_size_1.ListElementSize.BYTE_2: + case list_element_size_1.ListElementSize.BYTE_4: + case list_element_size_1.ListElementSize.BYTE_8: + case list_element_size_1.ListElementSize.POINTER: + case list_element_size_1.ListElementSize.VOID: + return util_1.padToWord(getListElementByteLength(elementSize) * length); + /* istanbul ignore next */ + case list_element_size_1.ListElementSize.COMPOSITE: + if (compositeSize === undefined) { + throw new Error(util_1.format(errors_1.PTR_INVALID_LIST_SIZE, NaN)); + } + return length * util_1.padToWord(object_size_1.getByteLength(compositeSize)); + /* istanbul ignore next */ + default: + throw new Error(errors_1.PTR_INVALID_LIST_SIZE); + } +} +exports.getListByteLength = getListByteLength; +/** + * Get the number of bytes required to hold a list element of the provided size. `COMPOSITE` elements do not have a + * fixed size, and `BIT` elements are packed into exactly a single bit, so these both return `NaN`. + * + * @param {ListElementSize} elementSize A number describing the size of the list elements. + * @returns {number} The number of bytes required to hold an element of that size, or `NaN` if that is undefined. + */ +function getListElementByteLength(elementSize) { + switch (elementSize) { + /* istanbul ignore next */ + case list_element_size_1.ListElementSize.BIT: + return NaN; + case list_element_size_1.ListElementSize.BYTE: + return 1; + case list_element_size_1.ListElementSize.BYTE_2: + return 2; + case list_element_size_1.ListElementSize.BYTE_4: + return 4; + case list_element_size_1.ListElementSize.BYTE_8: + case list_element_size_1.ListElementSize.POINTER: + return 8; + /* istanbul ignore next */ + case list_element_size_1.ListElementSize.COMPOSITE: + // Caller has to figure it out based on the tag word. + return NaN; + /* istanbul ignore next */ + case list_element_size_1.ListElementSize.VOID: + return 0; + /* istanbul ignore next */ + default: + throw new Error(util_1.format(errors_1.PTR_INVALID_LIST_SIZE, elementSize)); + } +} +exports.getListElementByteLength = getListElementByteLength; +/** + * Add an offset to the pointer's offset and return a new Pointer for that address. + * + * @param {number} offset The number of bytes to add to the offset. + * @param {Pointer} p The pointer to add from. + * @returns {Pointer} A new pointer to the address. + */ +function add(offset, p) { + return new Pointer(p.segment, p.byteOffset + offset, p._capnp.depthLimit); +} +exports.add = add; +/** + * Replace a pointer with a deep copy of the pointer at `src` and all of its contents. + * + * @param {Pointer} src The pointer to copy. + * @param {Pointer} p The pointer to copy into. + * @returns {void} + */ +function copyFrom(src, p) { + // If the pointer is the same then this is a noop. + if (p.segment === src.segment && p.byteOffset === src.byteOffset) { + trace("ignoring copy operation from identical pointer %s", src); + return; + } + // Make sure we erase this pointer's contents before moving on. If src is null, that's all we do. + erase(p); // noop if null + if (isNull(src)) + return; + switch (getTargetPointerType(src)) { + case pointer_type_1.PointerType.STRUCT: + copyFromStruct(src, p); + break; + case pointer_type_1.PointerType.LIST: + copyFromList(src, p); + break; + /* istanbul ignore next */ + default: + throw new Error(util_1.format(errors_1.PTR_INVALID_POINTER_TYPE, getTargetPointerType(p))); + } +} +exports.copyFrom = copyFrom; +/** + * Recursively erase a pointer, any far pointers/landing pads/tag words, and the content it points to. + * + * Note that this will leave "holes" of zeroes in the message, since the space cannot be reclaimed. With packing this + * will have a negligible effect on the final message size. + * + * FIXME: This may need protection against infinite recursion... + * + * @param {Pointer} p The pointer to erase. + * @returns {void} + */ +function erase(p) { + if (isNull(p)) + return; + // First deal with the contents. + let c; + switch (getTargetPointerType(p)) { + case pointer_type_1.PointerType.STRUCT: { + const size = getTargetStructSize(p); + c = getContent(p); + // Wipe the data section. + c.segment.fillZeroWords(c.byteOffset, size.dataByteLength / 8); + // Iterate over all the pointers and nuke them. + for (let i = 0; i < size.pointerLength; i++) { + erase(add(i * 8, c)); + } + break; + } + case pointer_type_1.PointerType.LIST: { + const elementSize = getTargetListElementSize(p); + const length = getTargetListLength(p); + let contentWords = util_1.padToWord(length * getListElementByteLength(elementSize)); + c = getContent(p); + if (elementSize === list_element_size_1.ListElementSize.POINTER) { + for (let i = 0; i < length; i++) { + erase(new Pointer(c.segment, c.byteOffset + i * 8, p._capnp.depthLimit - 1)); + } + // Calling erase on each pointer takes care of the content, nothing left to do here. + break; + } + else if (elementSize === list_element_size_1.ListElementSize.COMPOSITE) { + // Read some stuff from the tag word. + const tag = add(-8, c); + const compositeSize = getStructSize(tag); + const compositeByteLength = object_size_1.getByteLength(compositeSize); + contentWords = getOffsetWords(tag); + // Kill the tag word. + c.segment.setWordZero(c.byteOffset - 8); + // Recursively erase each pointer. + for (let i = 0; i < length; i++) { + for (let j = 0; j < compositeSize.pointerLength; j++) { + erase(new Pointer(c.segment, c.byteOffset + i * compositeByteLength + j * 8, p._capnp.depthLimit - 1)); + } + } + } + c.segment.fillZeroWords(c.byteOffset, contentWords); + break; + } + case pointer_type_1.PointerType.OTHER: + // No content. + break; + default: + throw new Error(util_1.format(errors_1.PTR_INVALID_POINTER_TYPE, getTargetPointerType(p))); + } + erasePointer(p); +} +exports.erase = erase; +/** + * Set the pointer (and far pointer landing pads, if applicable) to zero. Does not touch the pointer's content. + * + * @param {Pointer} p The pointer to erase. + * @returns {void} + */ +function erasePointer(p) { + if (getPointerType(p) === pointer_type_1.PointerType.FAR) { + const landingPad = followFar(p); + if (isDoubleFar(p)) { + // Kill the double-far tag word. + landingPad.segment.setWordZero(landingPad.byteOffset + 8); + } + // Kill the landing pad. + landingPad.segment.setWordZero(landingPad.byteOffset); + } + // Finally! Kill the pointer itself... + p.segment.setWordZero(p.byteOffset); +} +exports.erasePointer = erasePointer; +/** + * Interpret the pointer as a far pointer, returning its target segment and offset. + * + * @param {Pointer} p The pointer to read from. + * @returns {Pointer} A pointer to the far target. + */ +function followFar(p) { + const targetSegment = p.segment.message.getSegment(p.segment.getUint32(p.byteOffset + 4)); + const targetWordOffset = p.segment.getUint32(p.byteOffset) >>> 3; + return new Pointer(targetSegment, targetWordOffset * 8, p._capnp.depthLimit - 1); +} +exports.followFar = followFar; +/** + * If the pointer address references a far pointer, follow it to the location where the actual pointer data is written. + * Otherwise, returns the pointer unmodified. + * + * @param {Pointer} p The pointer to read from. + * @returns {Pointer} A new pointer representing the target location, or `p` if it is not a far pointer. + */ +function followFars(p) { + if (getPointerType(p) === pointer_type_1.PointerType.FAR) { + const landingPad = followFar(p); + if (isDoubleFar(p)) + landingPad.byteOffset += 8; + return landingPad; + } + return p; +} +exports.followFars = followFars; +function getCapabilityId(p) { + return p.segment.getUint32(p.byteOffset + 4); +} +exports.getCapabilityId = getCapabilityId; +function isCompositeList(p) { + return getTargetPointerType(p) === pointer_type_1.PointerType.LIST && getTargetListElementSize(p) === list_element_size_1.ListElementSize.COMPOSITE; +} +/** + * Obtain the location of the pointer's content, following far pointers as needed. + * If the pointer is a struct pointer and `compositeIndex` is set, it will be offset by a multiple of the struct's size. + * + * @param {Pointer} p The pointer to read from. + * @param {boolean} [ignoreCompositeIndex] If true, will not follow the composite struct pointer's composite index and + * instead return a pointer to the parent list's contents (also the beginning of the first struct). + * @returns {Pointer} A pointer to the beginning of the pointer's content. + */ +function getContent(p, ignoreCompositeIndex) { + let c; + if (isDoubleFar(p)) { + const landingPad = followFar(p); + c = new Pointer(p.segment.message.getSegment(getFarSegmentId(landingPad)), getOffsetWords(landingPad) * 8); + } + else { + const target = followFars(p); + c = new Pointer(target.segment, target.byteOffset + 8 + getOffsetWords(target) * 8); + } + if (isCompositeList(p)) + c.byteOffset += 8; + if (!ignoreCompositeIndex && p._capnp.compositeIndex !== undefined) { + // Seek backwards by one word so we can read the struct size off the tag word. + c.byteOffset -= 8; + // Seek ahead by `compositeIndex` multiples of the struct's total size. + c.byteOffset += 8 + p._capnp.compositeIndex * object_size_1.getByteLength(object_size_1.padToWord(getStructSize(c))); + } + return c; +} +exports.getContent = getContent; +/** + * Read the target segment ID from a far pointer. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The target segment ID. + */ +function getFarSegmentId(p) { + return p.segment.getUint32(p.byteOffset + 4); +} +exports.getFarSegmentId = getFarSegmentId; +/** + * Get a number indicating the size of the list's elements. + * + * @param {Pointer} p The pointer to read from. + * @returns {ListElementSize} The size of the list's elements. + */ +function getListElementSize(p) { + return p.segment.getUint32(p.byteOffset + 4) & constants_1.LIST_SIZE_MASK; +} +exports.getListElementSize = getListElementSize; +/** + * Get the number of elements in a list pointer. For composite lists, it instead represents the total number of words in + * the list (not counting the tag word). + * + * This method does **not** attempt to distinguish between composite and non-composite lists. To get the correct + * length for composite lists use `getTargetListLength()` instead. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The length of the list, or total number of words for composite lists. + */ +function getListLength(p) { + return p.segment.getUint32(p.byteOffset + 4) >>> 3; +} +exports.getListLength = getListLength; +/** + * Get the offset (in words) from the end of a pointer to the start of its content. For struct pointers, this is the + * beginning of the data section, and for list pointers it is the location of the first element. The value should + * always be zero for interface pointers. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The offset, in words, from the end of the pointer to the start of the data section. + */ +function getOffsetWords(p) { + const o = p.segment.getInt32(p.byteOffset); + // Far pointers only have 29 offset bits. + return o & 2 ? o >> 3 : o >> 2; +} +exports.getOffsetWords = getOffsetWords; +/** + * Look up the pointer's type. + * + * @param {Pointer} p The pointer to read from. + * @returns {PointerType} The type of pointer. + */ +function getPointerType(p) { + return p.segment.getUint32(p.byteOffset) & constants_1.POINTER_TYPE_MASK; +} +exports.getPointerType = getPointerType; +/** + * Read the number of data words from this struct pointer. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The number of data words in the struct. + */ +function getStructDataWords(p) { + return p.segment.getUint16(p.byteOffset + 4); +} +exports.getStructDataWords = getStructDataWords; +/** + * Read the number of pointers contained in this struct pointer. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The number of pointers in this struct. + */ +function getStructPointerLength(p) { + return p.segment.getUint16(p.byteOffset + 6); +} +exports.getStructPointerLength = getStructPointerLength; +/** + * Get an object describing this struct pointer's size. + * + * @param {Pointer} p The pointer to read from. + * @returns {ObjectSize} The size of the struct. + */ +function getStructSize(p) { + return new object_size_1.ObjectSize(getStructDataWords(p) * 8, getStructPointerLength(p)); +} +exports.getStructSize = getStructSize; +/** + * Get a pointer to this pointer's composite list tag word, following far pointers as needed. + * + * @param {Pointer} p The pointer to read from. + * @returns {Pointer} A pointer to the list's composite tag word. + */ +function getTargetCompositeListTag(p) { + const c = getContent(p); + // The composite list tag is always one word before the content. + c.byteOffset -= 8; + return c; +} +exports.getTargetCompositeListTag = getTargetCompositeListTag; +/** + * Get the object size for the target composite list, following far pointers as needed. + * + * @param {Pointer} p The pointer to read from. + * @returns {ObjectSize} An object describing the size of each struct in the list. + */ +function getTargetCompositeListSize(p) { + return getStructSize(getTargetCompositeListTag(p)); +} +exports.getTargetCompositeListSize = getTargetCompositeListSize; +/** + * Get the size of the list elements referenced by this pointer, following far pointers if necessary. + * + * @param {Pointer} p The pointer to read from. + * @returns {ListElementSize} The size of the elements in the list. + */ +function getTargetListElementSize(p) { + return getListElementSize(followFars(p)); +} +exports.getTargetListElementSize = getTargetListElementSize; +/** + * Get the length of the list referenced by this pointer, following far pointers if necessary. If the list is a + * composite list, it will look up the tag word and read the length from there. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The number of elements in the list. + */ +function getTargetListLength(p) { + const t = followFars(p); + if (getListElementSize(t) === list_element_size_1.ListElementSize.COMPOSITE) { + // The content is prefixed by a tag word; it's a struct pointer whose offset contains the list's length. + return getOffsetWords(getTargetCompositeListTag(p)); + } + return getListLength(t); +} +exports.getTargetListLength = getTargetListLength; +/** + * Get the type of a pointer, following far pointers if necessary. For non-far pointers this is equivalent to calling + * `getPointerType()`. + * + * The target of a far pointer can never be another far pointer, and this method will throw if such a situation is + * encountered. + * + * @param {Pointer} p The pointer to read from. + * @returns {PointerType} The type of pointer referenced by this pointer. + */ +function getTargetPointerType(p) { + const t = getPointerType(followFars(p)); + if (t === pointer_type_1.PointerType.FAR) + throw new Error(util_1.format(errors_1.PTR_INVALID_FAR_TARGET, p)); + return t; +} +exports.getTargetPointerType = getTargetPointerType; +/** + * Get the size of the struct referenced by a pointer, following far pointers if necessary. + * + * @param {Pointer} p The poiner to read from. + * @returns {ObjectSize} The size of the struct referenced by this pointer. + */ +function getTargetStructSize(p) { + return getStructSize(followFars(p)); +} +exports.getTargetStructSize = getTargetStructSize; +/** + * Initialize a pointer to point at the data in the content segment. If the content segment is not the same as the + * pointer's segment, this will allocate and write far pointers as needed. Nothing is written otherwise. + * + * The return value includes a pointer to write the pointer's actual data to (the eventual far target), and the offset + * value (in words) to use for that pointer. In the case of double-far pointers this offset will always be zero. + * + * @param {Segment} contentSegment The segment containing this pointer's content. + * @param {number} contentOffset The offset within the content segment for the beginning of this pointer's content. + * @param {Pointer} p The pointer to initialize. + * @returns {PointerAllocationResult} An object containing a pointer (where the pointer data should be written), and + * the value to use as the offset for that pointer. + */ +function initPointer(contentSegment, contentOffset, p) { + if (p.segment !== contentSegment) { + // Need a far pointer. + trace("Initializing far pointer %s -> %s.", p, contentSegment); + if (!contentSegment.hasCapacity(8)) { + // GAH! Not enough space in the content segment for a landing pad so we need a double far pointer. + const landingPad = p.segment.allocate(16); + trace("GAH! Initializing double-far pointer in %s from %s -> %s.", p, contentSegment, landingPad); + setFarPointer(true, landingPad.byteOffset / 8, landingPad.segment.id, p); + setFarPointer(false, contentOffset / 8, contentSegment.id, landingPad); + landingPad.byteOffset += 8; + return new pointer_allocation_result_1.PointerAllocationResult(landingPad, 0); + } + // Allocate a far pointer landing pad in the target segment. + const landingPad = contentSegment.allocate(8); + if (landingPad.segment.id !== contentSegment.id) { + throw new Error(errors_1.INVARIANT_UNREACHABLE_CODE); + } + setFarPointer(false, landingPad.byteOffset / 8, landingPad.segment.id, p); + return new pointer_allocation_result_1.PointerAllocationResult(landingPad, (contentOffset - landingPad.byteOffset - 8) / 8); + } + trace("Initializing intra-segment pointer %s -> %a.", p, contentOffset); + return new pointer_allocation_result_1.PointerAllocationResult(p, (contentOffset - p.byteOffset - 8) / 8); +} +exports.initPointer = initPointer; +/** + * Check if the pointer is a double-far pointer. + * + * @param {Pointer} p The pointer to read from. + * @returns {boolean} `true` if it is a double-far pointer, `false` otherwise. + */ +function isDoubleFar(p) { + return getPointerType(p) === pointer_type_1.PointerType.FAR && (p.segment.getUint32(p.byteOffset) & constants_1.POINTER_DOUBLE_FAR_MASK) !== 0; +} +exports.isDoubleFar = isDoubleFar; +/** + * Quickly check to see if the pointer is "null". A "null" pointer is a zero word, equivalent to an empty struct + * pointer. + * + * @param {Pointer} p The pointer to read from. + * @returns {boolean} `true` if the pointer is "null". + */ +function isNull(p) { + return p.segment.isWordZero(p.byteOffset); +} +exports.isNull = isNull; +/** + * Relocate a pointer to the given destination, ensuring that it points to the same content. This will create far + * pointers as needed if the content is in a different segment than the destination. After the relocation the source + * pointer will be erased and is no longer valid. + * + * @param {Pointer} dst The desired location for the `src` pointer. Any existing contents will be erased before + * relocating! + * @param {Pointer} src The pointer to relocate. + * @returns {void} + */ +function relocateTo(dst, src) { + const t = followFars(src); + const lo = t.segment.getUint8(t.byteOffset) & 0x03; // discard the offset + const hi = t.segment.getUint32(t.byteOffset + 4); + // Make sure anything dst was pointing to is wiped out. + erase(dst); + const res = initPointer(t.segment, t.byteOffset + 8 + getOffsetWords(t) * 8, dst); + // Keep the low 2 bits and write the new offset. + res.pointer.segment.setUint32(res.pointer.byteOffset, lo | (res.offsetWords << 2)); + // Keep the high 32 bits intact. + res.pointer.segment.setUint32(res.pointer.byteOffset + 4, hi); + erasePointer(src); +} +exports.relocateTo = relocateTo; +/** + * Write a far pointer. + * + * @param {boolean} doubleFar Set to `true` if this is a double far pointer. + * @param {number} offsetWords The offset, in words, to the target pointer. + * @param {number} segmentId The segment the target pointer is located in. + * @param {Pointer} p The pointer to write to. + * @returns {void} + */ +function setFarPointer(doubleFar, offsetWords, segmentId, p) { + const A = pointer_type_1.PointerType.FAR; + const B = doubleFar ? 1 : 0; + const C = offsetWords; + const D = segmentId; + p.segment.setUint32(p.byteOffset, A | (B << 2) | (C << 3)); + p.segment.setUint32(p.byteOffset + 4, D); +} +exports.setFarPointer = setFarPointer; +/** + * Write a raw interface pointer. + * + * @param {number} capId The capability ID. + * @param {Pointer} p The pointer to write to. + * @returns {void} + */ +function setInterfacePointer(capId, p) { + p.segment.setUint32(p.byteOffset, pointer_type_1.PointerType.OTHER); + p.segment.setUint32(p.byteOffset + 4, capId); +} +exports.setInterfacePointer = setInterfacePointer; +/** + * Write a raw list pointer. + * + * @param {number} offsetWords The number of words from the end of this pointer to the beginning of the list content. + * @param {ListElementSize} size The size of each element in the list. + * @param {number} length The number of elements in the list. + * @param {Pointer} p The pointer to write to. + * @param {ObjectSize} [compositeSize] For composite lists this describes the size of each element in this list. This + * is required for composite lists. + * @returns {void} + */ +function setListPointer(offsetWords, size, length, p, compositeSize) { + const A = pointer_type_1.PointerType.LIST; + const B = offsetWords; + const C = size; + let D = length; + if (size === list_element_size_1.ListElementSize.COMPOSITE) { + if (compositeSize === undefined) { + throw new TypeError(errors_1.TYPE_COMPOSITE_SIZE_UNDEFINED); + } + D *= object_size_1.getWordLength(compositeSize); + } + p.segment.setUint32(p.byteOffset, A | (B << 2)); + p.segment.setUint32(p.byteOffset + 4, C | (D << 3)); +} +exports.setListPointer = setListPointer; +/** + * Write a raw struct pointer. + * + * @param {number} offsetWords The number of words from the end of this pointer to the beginning of the struct's data + * section. + * @param {ObjectSize} size An object describing the size of the struct. + * @param {Pointer} p The pointer to write to. + * @returns {void} + */ +function setStructPointer(offsetWords, size, p) { + const A = pointer_type_1.PointerType.STRUCT; + const B = offsetWords; + const C = object_size_1.getDataWordLength(size); + const D = size.pointerLength; + p.segment.setUint32(p.byteOffset, A | (B << 2)); + p.segment.setUint16(p.byteOffset + 4, C); + p.segment.setUint16(p.byteOffset + 6, D); +} +exports.setStructPointer = setStructPointer; +/** + * Read some bits off a pointer to make sure it has the right pointer data. + * + * @param {PointerType} pointerType The expected pointer type. + * @param {Pointer} p The pointer to validate. + * @param {ListElementSize} [elementSize] For list pointers, the expected element size. Leave this + * undefined for struct pointers. + * @returns {void} + */ +function validate(pointerType, p, elementSize) { + if (isNull(p)) + return; + const t = followFars(p); + // Check the pointer type. + const A = t.segment.getUint32(t.byteOffset) & constants_1.POINTER_TYPE_MASK; + if (A !== pointerType) { + throw new Error(util_1.format(errors_1.PTR_WRONG_POINTER_TYPE, p, pointerType)); + } + // Check the list element size, if provided. + if (elementSize !== undefined) { + const C = t.segment.getUint32(t.byteOffset + 4) & constants_1.LIST_SIZE_MASK; + if (C !== elementSize) { + throw new Error(util_1.format(errors_1.PTR_WRONG_LIST_TYPE, p, list_element_size_1.ListElementSize[elementSize])); + } + } +} +exports.validate = validate; +function copyFromList(src, dst) { + if (dst._capnp.depthLimit <= 0) + throw new Error(errors_1.PTR_DEPTH_LIMIT_EXCEEDED); + const srcContent = getContent(src); + const srcElementSize = getTargetListElementSize(src); + const srcLength = getTargetListLength(src); + let srcCompositeSize; + let srcStructByteLength; + let dstContent; + if (srcElementSize === list_element_size_1.ListElementSize.POINTER) { + dstContent = dst.segment.allocate(srcLength << 3); + // Recursively copy each pointer in the list. + for (let i = 0; i < srcLength; i++) { + const srcPtr = new Pointer(srcContent.segment, srcContent.byteOffset + (i << 3), src._capnp.depthLimit - 1); + const dstPtr = new Pointer(dstContent.segment, dstContent.byteOffset + (i << 3), dst._capnp.depthLimit - 1); + copyFrom(srcPtr, dstPtr); + } + } + else if (srcElementSize === list_element_size_1.ListElementSize.COMPOSITE) { + srcCompositeSize = object_size_1.padToWord(getTargetCompositeListSize(src)); + srcStructByteLength = object_size_1.getByteLength(srcCompositeSize); + dstContent = dst.segment.allocate(object_size_1.getByteLength(srcCompositeSize) * srcLength + 8); + // Copy the tag word. + dstContent.segment.copyWord(dstContent.byteOffset, srcContent.segment, srcContent.byteOffset - 8); + // Copy the entire contents, including all pointers. This should be more efficient than making `srcLength` + // copies to skip the pointer sections, and we're about to rewrite all those pointers anyway. + // PERF: Skip this step if the composite struct only contains pointers. + if (srcCompositeSize.dataByteLength > 0) { + const wordLength = object_size_1.getWordLength(srcCompositeSize) * srcLength; + dstContent.segment.copyWords(dstContent.byteOffset + 8, srcContent.segment, srcContent.byteOffset, wordLength); + } + // Recursively copy all the pointers in each struct. + for (let i = 0; i < srcLength; i++) { + for (let j = 0; j < srcCompositeSize.pointerLength; j++) { + const offset = i * srcStructByteLength + srcCompositeSize.dataByteLength + (j << 3); + const srcPtr = new Pointer(srcContent.segment, srcContent.byteOffset + offset, src._capnp.depthLimit - 1); + const dstPtr = new Pointer(dstContent.segment, dstContent.byteOffset + offset + 8, dst._capnp.depthLimit - 1); + copyFrom(srcPtr, dstPtr); + } + } + } + else { + const byteLength = util_1.padToWord(srcElementSize === list_element_size_1.ListElementSize.BIT + ? (srcLength + 7) >>> 3 + : getListElementByteLength(srcElementSize) * srcLength); + const wordLength = byteLength >>> 3; + dstContent = dst.segment.allocate(byteLength); + // Copy all of the list contents word-by-word. + dstContent.segment.copyWords(dstContent.byteOffset, srcContent.segment, srcContent.byteOffset, wordLength); + } + // Initialize the list pointer. + const res = initPointer(dstContent.segment, dstContent.byteOffset, dst); + setListPointer(res.offsetWords, srcElementSize, srcLength, res.pointer, srcCompositeSize); +} +exports.copyFromList = copyFromList; +function copyFromStruct(src, dst) { + if (dst._capnp.depthLimit <= 0) + throw new Error(errors_1.PTR_DEPTH_LIMIT_EXCEEDED); + const srcContent = getContent(src); + const srcSize = getTargetStructSize(src); + const srcDataWordLength = object_size_1.getDataWordLength(srcSize); + // Allocate space for the destination content. + const dstContent = dst.segment.allocate(object_size_1.getByteLength(srcSize)); + // Copy the data section. + dstContent.segment.copyWords(dstContent.byteOffset, srcContent.segment, srcContent.byteOffset, srcDataWordLength); + // Copy the pointer section. + for (let i = 0; i < srcSize.pointerLength; i++) { + const offset = srcSize.dataByteLength + i * 8; + const srcPtr = new Pointer(srcContent.segment, srcContent.byteOffset + offset, src._capnp.depthLimit - 1); + const dstPtr = new Pointer(dstContent.segment, dstContent.byteOffset + offset, dst._capnp.depthLimit - 1); + copyFrom(srcPtr, dstPtr); + } + // Don't touch dst if it's already initialized as a composite list pointer. With composite struct pointers there's + // no pointer to copy here and we've already copied the contents. + if (dst._capnp.compositeList) + return; + // Initialize the struct pointer. + const res = initPointer(dstContent.segment, dstContent.byteOffset, dst); + setStructPointer(res.offsetWords, srcSize, res.pointer); +} +exports.copyFromStruct = copyFromStruct; +/** + * Track the allocation of a new Pointer object. + * + * This will decrement an internal counter tracking how many bytes have been traversed in the message so far. After + * a certain limit, this method will throw an error in order to prevent a certain class of DoS attacks. + * + * @param {Message} message The message the pointer belongs to. + * @param {Pointer} p The pointer being allocated. + * @returns {void} + */ +function trackPointerAllocation(message, p) { + message._capnp.traversalLimit -= 8; + if (message._capnp.traversalLimit <= 0) { + throw new Error(util_1.format(errors_1.PTR_TRAVERSAL_LIMIT_EXCEEDED, p)); + } +} +exports.trackPointerAllocation = trackPointerAllocation; +//# sourceMappingURL=pointer.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/pointer.js.map b/node_modules/capnp-ts/src/serialization/pointers/pointer.js.map new file mode 100644 index 0000000..5a0bd3e --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/pointer.js.map @@ -0,0 +1 @@ +{"version":3,"file":"pointer.js","sourceRoot":"","sources":["pointer.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,+CAAwG;AACxG,qCAA4D;AAC5D,4DAAuD;AACvD,gDAMwB;AAExB,qCAAkC;AAClC,2EAAsE;AACtE,iDAA6C;AAE7C,yCAWsB;AAEtB,MAAM,KAAK,GAAG,eAAS,CAAC,eAAe,CAAC,CAAC;AACzC,KAAK,CAAC,MAAM,CAAC,CAAC;AAwBd;;;;;;GAMG;AAEH,MAAa,OAAO;IAwBlB,YAAY,OAAgB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,CAAC,aAAa;QAAE,OAAO;IAErC,iCAAiC;IAEjC,MAAM,GAAG,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IACxE,gBAAgB,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;AAC1D,CAAC;AAnCD,wCAmCC;AAED;;;;;;;;;GASG;AAEH,SAAgB,sBAAsB,CAAC,OAAgB,EAAE,CAAU;IACjE,OAAO,CAAC,MAAM,CAAC,cAAc,IAAI,CAAC,CAAC;IAEnC,IAAI,OAAO,CAAC,MAAM,CAAC,cAAc,IAAI,CAAC,EAAE;QACtC,MAAM,IAAI,KAAK,CAAC,aAAM,CAAC,qCAA4B,EAAE,CAAC,CAAC,CAAC,CAAC;KAC1D;AACH,CAAC;AAND,wDAMC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/pointer.ts b/node_modules/capnp-ts/src/serialization/pointers/pointer.ts new file mode 100644 index 0000000..891382e --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/pointer.ts @@ -0,0 +1,1018 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { LIST_SIZE_MASK, MAX_DEPTH, POINTER_DOUBLE_FAR_MASK, POINTER_TYPE_MASK } from "../../constants"; +import { bufferToHex, format, padToWord } from "../../util"; +import { ListElementSize } from "../list-element-size"; +import { + ObjectSize, + getByteLength, + padToWord as padObjectToWord, + getWordLength, + getDataWordLength, +} from "../object-size"; +import { Segment } from "../segment"; +import { Orphan } from "./orphan"; +import { PointerAllocationResult } from "./pointer-allocation-result"; +import { PointerType } from "./pointer-type"; +import { Message } from "../message"; +import { + PTR_TRAVERSAL_LIMIT_EXCEEDED, + PTR_DEPTH_LIMIT_EXCEEDED, + PTR_OFFSET_OUT_OF_BOUNDS, + PTR_INVALID_LIST_SIZE, + PTR_INVALID_POINTER_TYPE, + PTR_INVALID_FAR_TARGET, + TYPE_COMPOSITE_SIZE_UNDEFINED, + PTR_WRONG_POINTER_TYPE, + PTR_WRONG_LIST_TYPE, + INVARIANT_UNREACHABLE_CODE, +} from "../../errors"; + +const trace = initTrace("capnp:pointer"); +trace("load"); + +export interface _PointerCtor { + readonly displayName: string; +} + +export interface PointerCtor<T extends Pointer> { + readonly _capnp: _PointerCtor; + + new (segment: Segment, byteOffset: number, depthLimit?: number): T; +} + +export interface _Pointer { + compositeIndex?: number; + + compositeList: boolean; + + /** + * A number that is decremented as nested pointers are traversed. When this hits zero errors will be thrown. + */ + + depthLimit: number; +} + +/** + * A pointer referencing a single byte location in a segment. This is typically used for Cap'n Proto pointers, but is + * also sometimes used to reference an offset to a pointer's content or tag words. + * + * @export + * @class Pointer + */ + +export class Pointer { + static readonly adopt = adopt; + static readonly copyFrom = copyFrom; + static readonly disown = disown; + static readonly dump = dump; + static readonly isNull = isNull; + + static readonly _capnp: _PointerCtor = { + displayName: "Pointer" as string, + }; + + readonly _capnp: _Pointer; + + /** Offset, in bytes, from the start of the segment to the beginning of this pointer. */ + + byteOffset: number; + + /** + * The starting segment for this pointer's data. In the case of a far pointer, the actual content this pointer is + * referencing will be in another segment within the same message. + */ + + segment: Segment; + + constructor(segment: Segment, byteOffset: number, depthLimit = MAX_DEPTH) { + this._capnp = { compositeList: false, depthLimit }; + this.segment = segment; + this.byteOffset = byteOffset; + + if (depthLimit === 0) { + throw new Error(format(PTR_DEPTH_LIMIT_EXCEEDED, this)); + } + + // Make sure we keep track of all pointer allocations; there's a limit per message (prevent DoS). + + trackPointerAllocation(segment.message, this); + + // NOTE: It's okay to have a pointer to the end of the segment; you'll see this when creating pointers to the + // beginning of the content of a newly-allocated composite list with zero elements. Unlike other language + // implementations buffer over/underflows are not a big issue since all buffer access is bounds checked in native + // code anyway. + + if (byteOffset < 0 || byteOffset > segment.byteLength) { + throw new Error(format(PTR_OFFSET_OUT_OF_BOUNDS, byteOffset)); + } + + trace("new %s", this); + } + + toString(): string { + return format("Pointer_%d@%a,%s,limit:%x", this.segment.id, this.byteOffset, dump(this), this._capnp.depthLimit); + } +} + +/** + * Adopt an orphaned pointer, making the pointer point to the orphaned content without copying it. + * + * @param {Orphan<Pointer>} src The orphan to adopt. + * @param {Pointer} p The the pointer to adopt into. + * @returns {void} + */ + +export function adopt<T extends Pointer>(src: Orphan<T>, p: T): void { + src._moveTo(p); +} + +/** + * Convert a pointer to an Orphan, zeroing out the pointer and leaving its content untouched. If the content is no + * longer needed, call `disown()` on the orphaned pointer to erase the contents as well. + * + * Call `adopt()` on the orphan with the new target pointer location to move it back into the message; the orphan + * object is then invalidated after adoption (can only adopt once!). + * + * @param {T} p The pointer to turn into an Orphan. + * @returns {Orphan<T>} An orphaned pointer. + */ + +export function disown<T extends Pointer>(p: T): Orphan<T> { + return new Orphan(p); +} + +export function dump(p: Pointer): string { + return bufferToHex(p.segment.buffer.slice(p.byteOffset, p.byteOffset + 8)); +} + +/** + * Get the total number of bytes required to hold a list of the provided size with the given length, rounded up to the + * nearest word. + * + * @param {ListElementSize} elementSize A number describing the size of the list elements. + * @param {number} length The length of the list. + * @param {ObjectSize} [compositeSize] The size of each element in a composite list; required if + * `elementSize === ListElementSize.COMPOSITE`. + * @returns {number} The number of bytes required to hold an element of that size, or `NaN` if that is undefined. + */ + +export function getListByteLength(elementSize: ListElementSize, length: number, compositeSize?: ObjectSize): number { + switch (elementSize) { + case ListElementSize.BIT: + return padToWord((length + 7) >>> 3); + + case ListElementSize.BYTE: + case ListElementSize.BYTE_2: + case ListElementSize.BYTE_4: + case ListElementSize.BYTE_8: + case ListElementSize.POINTER: + case ListElementSize.VOID: + return padToWord(getListElementByteLength(elementSize) * length); + + /* istanbul ignore next */ + case ListElementSize.COMPOSITE: + if (compositeSize === undefined) { + throw new Error(format(PTR_INVALID_LIST_SIZE, NaN)); + } + + return length * padToWord(getByteLength(compositeSize)); + + /* istanbul ignore next */ + default: + throw new Error(PTR_INVALID_LIST_SIZE); + } +} + +/** + * Get the number of bytes required to hold a list element of the provided size. `COMPOSITE` elements do not have a + * fixed size, and `BIT` elements are packed into exactly a single bit, so these both return `NaN`. + * + * @param {ListElementSize} elementSize A number describing the size of the list elements. + * @returns {number} The number of bytes required to hold an element of that size, or `NaN` if that is undefined. + */ + +export function getListElementByteLength(elementSize: ListElementSize): number { + switch (elementSize) { + /* istanbul ignore next */ + case ListElementSize.BIT: + return NaN; + + case ListElementSize.BYTE: + return 1; + + case ListElementSize.BYTE_2: + return 2; + + case ListElementSize.BYTE_4: + return 4; + + case ListElementSize.BYTE_8: + case ListElementSize.POINTER: + return 8; + + /* istanbul ignore next */ + case ListElementSize.COMPOSITE: + // Caller has to figure it out based on the tag word. + + return NaN; + + /* istanbul ignore next */ + case ListElementSize.VOID: + return 0; + + /* istanbul ignore next */ + default: + throw new Error(format(PTR_INVALID_LIST_SIZE, elementSize)); + } +} + +/** + * Add an offset to the pointer's offset and return a new Pointer for that address. + * + * @param {number} offset The number of bytes to add to the offset. + * @param {Pointer} p The pointer to add from. + * @returns {Pointer} A new pointer to the address. + */ + +export function add(offset: number, p: Pointer): Pointer { + return new Pointer(p.segment, p.byteOffset + offset, p._capnp.depthLimit); +} + +/** + * Replace a pointer with a deep copy of the pointer at `src` and all of its contents. + * + * @param {Pointer} src The pointer to copy. + * @param {Pointer} p The pointer to copy into. + * @returns {void} + */ + +export function copyFrom(src: Pointer, p: Pointer): void { + // If the pointer is the same then this is a noop. + + if (p.segment === src.segment && p.byteOffset === src.byteOffset) { + trace("ignoring copy operation from identical pointer %s", src); + + return; + } + + // Make sure we erase this pointer's contents before moving on. If src is null, that's all we do. + + erase(p); // noop if null + + if (isNull(src)) return; + + switch (getTargetPointerType(src)) { + case PointerType.STRUCT: + copyFromStruct(src, p); + + break; + + case PointerType.LIST: + copyFromList(src, p); + + break; + + /* istanbul ignore next */ + default: + throw new Error(format(PTR_INVALID_POINTER_TYPE, getTargetPointerType(p))); + } +} + +/** + * Recursively erase a pointer, any far pointers/landing pads/tag words, and the content it points to. + * + * Note that this will leave "holes" of zeroes in the message, since the space cannot be reclaimed. With packing this + * will have a negligible effect on the final message size. + * + * FIXME: This may need protection against infinite recursion... + * + * @param {Pointer} p The pointer to erase. + * @returns {void} + */ + +export function erase(p: Pointer): void { + if (isNull(p)) return; + + // First deal with the contents. + + let c: Pointer; + + switch (getTargetPointerType(p)) { + case PointerType.STRUCT: { + const size = getTargetStructSize(p); + c = getContent(p); + + // Wipe the data section. + + c.segment.fillZeroWords(c.byteOffset, size.dataByteLength / 8); + + // Iterate over all the pointers and nuke them. + + for (let i = 0; i < size.pointerLength; i++) { + erase(add(i * 8, c)); + } + + break; + } + case PointerType.LIST: { + const elementSize = getTargetListElementSize(p); + const length = getTargetListLength(p); + let contentWords = padToWord(length * getListElementByteLength(elementSize)); + c = getContent(p); + + if (elementSize === ListElementSize.POINTER) { + for (let i = 0; i < length; i++) { + erase(new Pointer(c.segment, c.byteOffset + i * 8, p._capnp.depthLimit - 1)); + } + + // Calling erase on each pointer takes care of the content, nothing left to do here. + + break; + } else if (elementSize === ListElementSize.COMPOSITE) { + // Read some stuff from the tag word. + const tag = add(-8, c); + const compositeSize = getStructSize(tag); + const compositeByteLength = getByteLength(compositeSize); + contentWords = getOffsetWords(tag); + + // Kill the tag word. + c.segment.setWordZero(c.byteOffset - 8); + + // Recursively erase each pointer. + for (let i = 0; i < length; i++) { + for (let j = 0; j < compositeSize.pointerLength; j++) { + erase(new Pointer(c.segment, c.byteOffset + i * compositeByteLength + j * 8, p._capnp.depthLimit - 1)); + } + } + } + + c.segment.fillZeroWords(c.byteOffset, contentWords); + + break; + } + case PointerType.OTHER: + // No content. + + break; + + default: + throw new Error(format(PTR_INVALID_POINTER_TYPE, getTargetPointerType(p))); + } + + erasePointer(p); +} + +/** + * Set the pointer (and far pointer landing pads, if applicable) to zero. Does not touch the pointer's content. + * + * @param {Pointer} p The pointer to erase. + * @returns {void} + */ + +export function erasePointer(p: Pointer): void { + if (getPointerType(p) === PointerType.FAR) { + const landingPad = followFar(p); + + if (isDoubleFar(p)) { + // Kill the double-far tag word. + + landingPad.segment.setWordZero(landingPad.byteOffset + 8); + } + + // Kill the landing pad. + + landingPad.segment.setWordZero(landingPad.byteOffset); + } + + // Finally! Kill the pointer itself... + + p.segment.setWordZero(p.byteOffset); +} + +/** + * Interpret the pointer as a far pointer, returning its target segment and offset. + * + * @param {Pointer} p The pointer to read from. + * @returns {Pointer} A pointer to the far target. + */ + +export function followFar(p: Pointer): Pointer { + const targetSegment = p.segment.message.getSegment(p.segment.getUint32(p.byteOffset + 4)); + const targetWordOffset = p.segment.getUint32(p.byteOffset) >>> 3; + + return new Pointer(targetSegment, targetWordOffset * 8, p._capnp.depthLimit - 1); +} + +/** + * If the pointer address references a far pointer, follow it to the location where the actual pointer data is written. + * Otherwise, returns the pointer unmodified. + * + * @param {Pointer} p The pointer to read from. + * @returns {Pointer} A new pointer representing the target location, or `p` if it is not a far pointer. + */ + +export function followFars(p: Pointer): Pointer { + if (getPointerType(p) === PointerType.FAR) { + const landingPad = followFar(p); + + if (isDoubleFar(p)) landingPad.byteOffset += 8; + + return landingPad; + } + + return p; +} + +export function getCapabilityId(p: Pointer): number { + return p.segment.getUint32(p.byteOffset + 4); +} + +function isCompositeList(p: Pointer): boolean { + return getTargetPointerType(p) === PointerType.LIST && getTargetListElementSize(p) === ListElementSize.COMPOSITE; +} + +/** + * Obtain the location of the pointer's content, following far pointers as needed. + * If the pointer is a struct pointer and `compositeIndex` is set, it will be offset by a multiple of the struct's size. + * + * @param {Pointer} p The pointer to read from. + * @param {boolean} [ignoreCompositeIndex] If true, will not follow the composite struct pointer's composite index and + * instead return a pointer to the parent list's contents (also the beginning of the first struct). + * @returns {Pointer} A pointer to the beginning of the pointer's content. + */ + +export function getContent(p: Pointer, ignoreCompositeIndex?: boolean): Pointer { + let c: Pointer; + + if (isDoubleFar(p)) { + const landingPad = followFar(p); + c = new Pointer(p.segment.message.getSegment(getFarSegmentId(landingPad)), getOffsetWords(landingPad) * 8); + } else { + const target = followFars(p); + c = new Pointer(target.segment, target.byteOffset + 8 + getOffsetWords(target) * 8); + } + + if (isCompositeList(p)) c.byteOffset += 8; + + if (!ignoreCompositeIndex && p._capnp.compositeIndex !== undefined) { + // Seek backwards by one word so we can read the struct size off the tag word. + + c.byteOffset -= 8; + + // Seek ahead by `compositeIndex` multiples of the struct's total size. + + c.byteOffset += 8 + p._capnp.compositeIndex * getByteLength(padObjectToWord(getStructSize(c))); + } + + return c; +} + +/** + * Read the target segment ID from a far pointer. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The target segment ID. + */ + +export function getFarSegmentId(p: Pointer): number { + return p.segment.getUint32(p.byteOffset + 4); +} + +/** + * Get a number indicating the size of the list's elements. + * + * @param {Pointer} p The pointer to read from. + * @returns {ListElementSize} The size of the list's elements. + */ + +export function getListElementSize(p: Pointer): ListElementSize { + return p.segment.getUint32(p.byteOffset + 4) & LIST_SIZE_MASK; +} + +/** + * Get the number of elements in a list pointer. For composite lists, it instead represents the total number of words in + * the list (not counting the tag word). + * + * This method does **not** attempt to distinguish between composite and non-composite lists. To get the correct + * length for composite lists use `getTargetListLength()` instead. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The length of the list, or total number of words for composite lists. + */ + +export function getListLength(p: Pointer): number { + return p.segment.getUint32(p.byteOffset + 4) >>> 3; +} + +/** + * Get the offset (in words) from the end of a pointer to the start of its content. For struct pointers, this is the + * beginning of the data section, and for list pointers it is the location of the first element. The value should + * always be zero for interface pointers. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The offset, in words, from the end of the pointer to the start of the data section. + */ + +export function getOffsetWords(p: Pointer): number { + const o = p.segment.getInt32(p.byteOffset); + + // Far pointers only have 29 offset bits. + return o & 2 ? o >> 3 : o >> 2; +} + +/** + * Look up the pointer's type. + * + * @param {Pointer} p The pointer to read from. + * @returns {PointerType} The type of pointer. + */ + +export function getPointerType(p: Pointer): PointerType { + return p.segment.getUint32(p.byteOffset) & POINTER_TYPE_MASK; +} + +/** + * Read the number of data words from this struct pointer. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The number of data words in the struct. + */ + +export function getStructDataWords(p: Pointer): number { + return p.segment.getUint16(p.byteOffset + 4); +} + +/** + * Read the number of pointers contained in this struct pointer. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The number of pointers in this struct. + */ + +export function getStructPointerLength(p: Pointer): number { + return p.segment.getUint16(p.byteOffset + 6); +} + +/** + * Get an object describing this struct pointer's size. + * + * @param {Pointer} p The pointer to read from. + * @returns {ObjectSize} The size of the struct. + */ + +export function getStructSize(p: Pointer): ObjectSize { + return new ObjectSize(getStructDataWords(p) * 8, getStructPointerLength(p)); +} + +/** + * Get a pointer to this pointer's composite list tag word, following far pointers as needed. + * + * @param {Pointer} p The pointer to read from. + * @returns {Pointer} A pointer to the list's composite tag word. + */ + +export function getTargetCompositeListTag(p: Pointer): Pointer { + const c = getContent(p); + + // The composite list tag is always one word before the content. + + c.byteOffset -= 8; + + return c; +} + +/** + * Get the object size for the target composite list, following far pointers as needed. + * + * @param {Pointer} p The pointer to read from. + * @returns {ObjectSize} An object describing the size of each struct in the list. + */ + +export function getTargetCompositeListSize(p: Pointer): ObjectSize { + return getStructSize(getTargetCompositeListTag(p)); +} + +/** + * Get the size of the list elements referenced by this pointer, following far pointers if necessary. + * + * @param {Pointer} p The pointer to read from. + * @returns {ListElementSize} The size of the elements in the list. + */ + +export function getTargetListElementSize(p: Pointer): ListElementSize { + return getListElementSize(followFars(p)); +} + +/** + * Get the length of the list referenced by this pointer, following far pointers if necessary. If the list is a + * composite list, it will look up the tag word and read the length from there. + * + * @param {Pointer} p The pointer to read from. + * @returns {number} The number of elements in the list. + */ + +export function getTargetListLength(p: Pointer): number { + const t = followFars(p); + + if (getListElementSize(t) === ListElementSize.COMPOSITE) { + // The content is prefixed by a tag word; it's a struct pointer whose offset contains the list's length. + + return getOffsetWords(getTargetCompositeListTag(p)); + } + + return getListLength(t); +} + +/** + * Get the type of a pointer, following far pointers if necessary. For non-far pointers this is equivalent to calling + * `getPointerType()`. + * + * The target of a far pointer can never be another far pointer, and this method will throw if such a situation is + * encountered. + * + * @param {Pointer} p The pointer to read from. + * @returns {PointerType} The type of pointer referenced by this pointer. + */ + +export function getTargetPointerType(p: Pointer): PointerType { + const t = getPointerType(followFars(p)); + + if (t === PointerType.FAR) throw new Error(format(PTR_INVALID_FAR_TARGET, p)); + + return t; +} + +/** + * Get the size of the struct referenced by a pointer, following far pointers if necessary. + * + * @param {Pointer} p The poiner to read from. + * @returns {ObjectSize} The size of the struct referenced by this pointer. + */ + +export function getTargetStructSize(p: Pointer): ObjectSize { + return getStructSize(followFars(p)); +} + +/** + * Initialize a pointer to point at the data in the content segment. If the content segment is not the same as the + * pointer's segment, this will allocate and write far pointers as needed. Nothing is written otherwise. + * + * The return value includes a pointer to write the pointer's actual data to (the eventual far target), and the offset + * value (in words) to use for that pointer. In the case of double-far pointers this offset will always be zero. + * + * @param {Segment} contentSegment The segment containing this pointer's content. + * @param {number} contentOffset The offset within the content segment for the beginning of this pointer's content. + * @param {Pointer} p The pointer to initialize. + * @returns {PointerAllocationResult} An object containing a pointer (where the pointer data should be written), and + * the value to use as the offset for that pointer. + */ + +export function initPointer(contentSegment: Segment, contentOffset: number, p: Pointer): PointerAllocationResult { + if (p.segment !== contentSegment) { + // Need a far pointer. + + trace("Initializing far pointer %s -> %s.", p, contentSegment); + + if (!contentSegment.hasCapacity(8)) { + // GAH! Not enough space in the content segment for a landing pad so we need a double far pointer. + + const landingPad = p.segment.allocate(16); + + trace("GAH! Initializing double-far pointer in %s from %s -> %s.", p, contentSegment, landingPad); + + setFarPointer(true, landingPad.byteOffset / 8, landingPad.segment.id, p); + setFarPointer(false, contentOffset / 8, contentSegment.id, landingPad); + + landingPad.byteOffset += 8; + + return new PointerAllocationResult(landingPad, 0); + } + + // Allocate a far pointer landing pad in the target segment. + + const landingPad = contentSegment.allocate(8); + + if (landingPad.segment.id !== contentSegment.id) { + throw new Error(INVARIANT_UNREACHABLE_CODE); + } + + setFarPointer(false, landingPad.byteOffset / 8, landingPad.segment.id, p); + + return new PointerAllocationResult(landingPad, (contentOffset - landingPad.byteOffset - 8) / 8); + } + + trace("Initializing intra-segment pointer %s -> %a.", p, contentOffset); + + return new PointerAllocationResult(p, (contentOffset - p.byteOffset - 8) / 8); +} + +/** + * Check if the pointer is a double-far pointer. + * + * @param {Pointer} p The pointer to read from. + * @returns {boolean} `true` if it is a double-far pointer, `false` otherwise. + */ + +export function isDoubleFar(p: Pointer): boolean { + return getPointerType(p) === PointerType.FAR && (p.segment.getUint32(p.byteOffset) & POINTER_DOUBLE_FAR_MASK) !== 0; +} + +/** + * Quickly check to see if the pointer is "null". A "null" pointer is a zero word, equivalent to an empty struct + * pointer. + * + * @param {Pointer} p The pointer to read from. + * @returns {boolean} `true` if the pointer is "null". + */ + +export function isNull(p: Pointer): boolean { + return p.segment.isWordZero(p.byteOffset); +} + +/** + * Relocate a pointer to the given destination, ensuring that it points to the same content. This will create far + * pointers as needed if the content is in a different segment than the destination. After the relocation the source + * pointer will be erased and is no longer valid. + * + * @param {Pointer} dst The desired location for the `src` pointer. Any existing contents will be erased before + * relocating! + * @param {Pointer} src The pointer to relocate. + * @returns {void} + */ + +export function relocateTo(dst: Pointer, src: Pointer): void { + const t = followFars(src); + const lo = t.segment.getUint8(t.byteOffset) & 0x03; // discard the offset + const hi = t.segment.getUint32(t.byteOffset + 4); + + // Make sure anything dst was pointing to is wiped out. + erase(dst); + + const res = initPointer(t.segment, t.byteOffset + 8 + getOffsetWords(t) * 8, dst); + + // Keep the low 2 bits and write the new offset. + res.pointer.segment.setUint32(res.pointer.byteOffset, lo | (res.offsetWords << 2)); + // Keep the high 32 bits intact. + res.pointer.segment.setUint32(res.pointer.byteOffset + 4, hi); + + erasePointer(src); +} + +/** + * Write a far pointer. + * + * @param {boolean} doubleFar Set to `true` if this is a double far pointer. + * @param {number} offsetWords The offset, in words, to the target pointer. + * @param {number} segmentId The segment the target pointer is located in. + * @param {Pointer} p The pointer to write to. + * @returns {void} + */ + +export function setFarPointer(doubleFar: boolean, offsetWords: number, segmentId: number, p: Pointer): void { + const A = PointerType.FAR; + const B = doubleFar ? 1 : 0; + const C = offsetWords; + const D = segmentId; + + p.segment.setUint32(p.byteOffset, A | (B << 2) | (C << 3)); + p.segment.setUint32(p.byteOffset + 4, D); +} + +/** + * Write a raw interface pointer. + * + * @param {number} capId The capability ID. + * @param {Pointer} p The pointer to write to. + * @returns {void} + */ + +export function setInterfacePointer(capId: number, p: Pointer): void { + p.segment.setUint32(p.byteOffset, PointerType.OTHER); + p.segment.setUint32(p.byteOffset + 4, capId); +} + +/** + * Write a raw list pointer. + * + * @param {number} offsetWords The number of words from the end of this pointer to the beginning of the list content. + * @param {ListElementSize} size The size of each element in the list. + * @param {number} length The number of elements in the list. + * @param {Pointer} p The pointer to write to. + * @param {ObjectSize} [compositeSize] For composite lists this describes the size of each element in this list. This + * is required for composite lists. + * @returns {void} + */ + +export function setListPointer( + offsetWords: number, + size: ListElementSize, + length: number, + p: Pointer, + compositeSize?: ObjectSize +): void { + const A = PointerType.LIST; + const B = offsetWords; + const C = size; + let D = length; + + if (size === ListElementSize.COMPOSITE) { + if (compositeSize === undefined) { + throw new TypeError(TYPE_COMPOSITE_SIZE_UNDEFINED); + } + + D *= getWordLength(compositeSize); + } + + p.segment.setUint32(p.byteOffset, A | (B << 2)); + p.segment.setUint32(p.byteOffset + 4, C | (D << 3)); +} + +/** + * Write a raw struct pointer. + * + * @param {number} offsetWords The number of words from the end of this pointer to the beginning of the struct's data + * section. + * @param {ObjectSize} size An object describing the size of the struct. + * @param {Pointer} p The pointer to write to. + * @returns {void} + */ + +export function setStructPointer(offsetWords: number, size: ObjectSize, p: Pointer): void { + const A = PointerType.STRUCT; + const B = offsetWords; + const C = getDataWordLength(size); + const D = size.pointerLength; + + p.segment.setUint32(p.byteOffset, A | (B << 2)); + p.segment.setUint16(p.byteOffset + 4, C); + p.segment.setUint16(p.byteOffset + 6, D); +} + +/** + * Read some bits off a pointer to make sure it has the right pointer data. + * + * @param {PointerType} pointerType The expected pointer type. + * @param {Pointer} p The pointer to validate. + * @param {ListElementSize} [elementSize] For list pointers, the expected element size. Leave this + * undefined for struct pointers. + * @returns {void} + */ + +export function validate(pointerType: PointerType, p: Pointer, elementSize?: ListElementSize): void { + if (isNull(p)) return; + + const t = followFars(p); + + // Check the pointer type. + + const A = t.segment.getUint32(t.byteOffset) & POINTER_TYPE_MASK; + + if (A !== pointerType) { + throw new Error(format(PTR_WRONG_POINTER_TYPE, p, pointerType)); + } + + // Check the list element size, if provided. + + if (elementSize !== undefined) { + const C = t.segment.getUint32(t.byteOffset + 4) & LIST_SIZE_MASK; + + if (C !== elementSize) { + throw new Error(format(PTR_WRONG_LIST_TYPE, p, ListElementSize[elementSize])); + } + } +} + +export function copyFromList(src: Pointer, dst: Pointer): void { + if (dst._capnp.depthLimit <= 0) throw new Error(PTR_DEPTH_LIMIT_EXCEEDED); + + const srcContent = getContent(src); + const srcElementSize = getTargetListElementSize(src); + const srcLength = getTargetListLength(src); + let srcCompositeSize; + let srcStructByteLength; + let dstContent; + + if (srcElementSize === ListElementSize.POINTER) { + dstContent = dst.segment.allocate(srcLength << 3); + + // Recursively copy each pointer in the list. + + for (let i = 0; i < srcLength; i++) { + const srcPtr = new Pointer(srcContent.segment, srcContent.byteOffset + (i << 3), src._capnp.depthLimit - 1); + const dstPtr = new Pointer(dstContent.segment, dstContent.byteOffset + (i << 3), dst._capnp.depthLimit - 1); + + copyFrom(srcPtr, dstPtr); + } + } else if (srcElementSize === ListElementSize.COMPOSITE) { + srcCompositeSize = padObjectToWord(getTargetCompositeListSize(src)); + srcStructByteLength = getByteLength(srcCompositeSize); + + dstContent = dst.segment.allocate(getByteLength(srcCompositeSize) * srcLength + 8); + + // Copy the tag word. + + dstContent.segment.copyWord(dstContent.byteOffset, srcContent.segment, srcContent.byteOffset - 8); + + // Copy the entire contents, including all pointers. This should be more efficient than making `srcLength` + // copies to skip the pointer sections, and we're about to rewrite all those pointers anyway. + + // PERF: Skip this step if the composite struct only contains pointers. + if (srcCompositeSize.dataByteLength > 0) { + const wordLength = getWordLength(srcCompositeSize) * srcLength; + + dstContent.segment.copyWords(dstContent.byteOffset + 8, srcContent.segment, srcContent.byteOffset, wordLength); + } + + // Recursively copy all the pointers in each struct. + + for (let i = 0; i < srcLength; i++) { + for (let j = 0; j < srcCompositeSize.pointerLength; j++) { + const offset = i * srcStructByteLength + srcCompositeSize.dataByteLength + (j << 3); + + const srcPtr = new Pointer(srcContent.segment, srcContent.byteOffset + offset, src._capnp.depthLimit - 1); + const dstPtr = new Pointer(dstContent.segment, dstContent.byteOffset + offset + 8, dst._capnp.depthLimit - 1); + + copyFrom(srcPtr, dstPtr); + } + } + } else { + const byteLength = padToWord( + srcElementSize === ListElementSize.BIT + ? (srcLength + 7) >>> 3 + : getListElementByteLength(srcElementSize) * srcLength + ); + const wordLength = byteLength >>> 3; + + dstContent = dst.segment.allocate(byteLength); + + // Copy all of the list contents word-by-word. + + dstContent.segment.copyWords(dstContent.byteOffset, srcContent.segment, srcContent.byteOffset, wordLength); + } + + // Initialize the list pointer. + + const res = initPointer(dstContent.segment, dstContent.byteOffset, dst); + setListPointer(res.offsetWords, srcElementSize, srcLength, res.pointer, srcCompositeSize); +} + +export function copyFromStruct(src: Pointer, dst: Pointer): void { + if (dst._capnp.depthLimit <= 0) throw new Error(PTR_DEPTH_LIMIT_EXCEEDED); + + const srcContent = getContent(src); + const srcSize = getTargetStructSize(src); + const srcDataWordLength = getDataWordLength(srcSize); + + // Allocate space for the destination content. + + const dstContent = dst.segment.allocate(getByteLength(srcSize)); + + // Copy the data section. + + dstContent.segment.copyWords(dstContent.byteOffset, srcContent.segment, srcContent.byteOffset, srcDataWordLength); + + // Copy the pointer section. + + for (let i = 0; i < srcSize.pointerLength; i++) { + const offset = srcSize.dataByteLength + i * 8; + + const srcPtr = new Pointer(srcContent.segment, srcContent.byteOffset + offset, src._capnp.depthLimit - 1); + const dstPtr = new Pointer(dstContent.segment, dstContent.byteOffset + offset, dst._capnp.depthLimit - 1); + + copyFrom(srcPtr, dstPtr); + } + + // Don't touch dst if it's already initialized as a composite list pointer. With composite struct pointers there's + // no pointer to copy here and we've already copied the contents. + + if (dst._capnp.compositeList) return; + + // Initialize the struct pointer. + + const res = initPointer(dstContent.segment, dstContent.byteOffset, dst); + setStructPointer(res.offsetWords, srcSize, res.pointer); +} + +/** + * Track the allocation of a new Pointer object. + * + * This will decrement an internal counter tracking how many bytes have been traversed in the message so far. After + * a certain limit, this method will throw an error in order to prevent a certain class of DoS attacks. + * + * @param {Message} message The message the pointer belongs to. + * @param {Pointer} p The pointer being allocated. + * @returns {void} + */ + +export function trackPointerAllocation(message: Message, p: Pointer): void { + message._capnp.traversalLimit -= 8; + + if (message._capnp.traversalLimit <= 0) { + throw new Error(format(PTR_TRAVERSAL_LIMIT_EXCEEDED, p)); + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/struct.d.ts b/node_modules/capnp-ts/src/serialization/pointers/struct.d.ts new file mode 100644 index 0000000..5e6ef92 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/struct.d.ts @@ -0,0 +1,349 @@ +/** + * @author jdiaz5513 + */ +import { Int64, Uint64 } from "../../types/index"; +import { ObjectSize } from "../object-size"; +import { Segment } from "../segment"; +import { Data } from "./data"; +import { List, ListCtor } from "./list"; +import { Orphan } from "./orphan"; +import { _Pointer, _PointerCtor, Pointer, PointerCtor } from "./pointer"; +export interface _StructCtor extends _PointerCtor { + readonly id: string; + readonly size: ObjectSize; +} +export interface StructCtor<T extends Struct> { + readonly _capnp: _StructCtor; + new (segment: Segment, byteOffset: number, depthLimit?: number, compositeIndex?: number): T; +} +export interface _Struct extends _Pointer { + compositeIndex?: number; +} +export declare class Struct extends Pointer { + static readonly _capnp: { + displayName: string; + }; + static readonly getAs: typeof getAs; + static readonly getBit: typeof getBit; + static readonly getData: typeof getData; + static readonly getFloat32: typeof getFloat32; + static readonly getFloat64: typeof getFloat64; + static readonly getUint8: typeof getUint8; + static readonly getUint16: typeof getUint16; + static readonly getUint32: typeof getUint32; + static readonly getUint64: typeof getUint64; + static readonly getInt8: typeof getInt8; + static readonly getInt16: typeof getInt16; + static readonly getInt32: typeof getInt32; + static readonly getInt64: typeof getInt64; + static readonly getList: typeof getList; + static readonly getPointer: typeof getPointer; + static readonly getPointerAs: typeof getPointerAs; + static readonly getStruct: typeof getStruct; + static readonly getText: typeof getText; + static readonly initData: typeof initData; + static readonly initList: typeof initList; + static readonly initStruct: typeof initStruct; + static readonly initStructAt: typeof initStructAt; + static readonly setBit: typeof setBit; + static readonly setFloat32: typeof setFloat32; + static readonly setFloat64: typeof setFloat64; + static readonly setUint8: typeof setUint8; + static readonly setUint16: typeof setUint16; + static readonly setUint32: typeof setUint32; + static readonly setUint64: typeof setUint64; + static readonly setInt8: typeof setInt8; + static readonly setInt16: typeof setInt16; + static readonly setInt32: typeof setInt32; + static readonly setInt64: typeof setInt64; + static readonly setText: typeof setText; + static readonly testWhich: typeof testWhich; + readonly _capnp: _Struct; + /** + * Create a new pointer to a struct. + * + * @constructor {Struct} + * @param {Segment} segment The segment the pointer resides in. + * @param {number} byteOffset The offset from the beginning of the segment to the beginning of the pointer data. + * @param {any} [depthLimit=MAX_DEPTH] The nesting depth limit for this object. + * @param {number} [compositeIndex] If set, then this pointer is actually a reference to a composite list + * (`this._getPointerTargetType() === PointerType.LIST`), and this number is used as the index of the struct within + * the list. It is not valid to call `initStruct()` on a composite struct – the struct contents are initialized when + * the list pointer is initialized. + */ + constructor(segment: Segment, byteOffset: number, depthLimit?: number, compositeIndex?: number); + static toString(): string; + toString(): string; +} +/** + * Initialize a struct with the provided object size. This will allocate new space for the struct contents, ideally in + * the same segment as this pointer. + * + * @param {ObjectSize} size An object describing the size of the struct's data and pointer sections. + * @param {Struct} s The struct to initialize. + * @returns {void} + */ +export declare function initStruct(size: ObjectSize, s: Struct): void; +export declare function initStructAt<T extends Struct>(index: number, StructClass: StructCtor<T>, p: Pointer): T; +/** + * Make a shallow copy of a struct's contents and update the pointer to point to the new content. The data and pointer + * sections will be resized to the provided size. + * + * WARNING: This method can cause data loss if `dstSize` is smaller than the original size! + * + * @param {ObjectSize} dstSize The desired size for the struct contents. + * @param {Struct} s The struct to resize. + * @returns {void} + */ +export declare function resize(dstSize: ObjectSize, s: Struct): void; +export declare function adopt<T extends Struct>(src: Orphan<T>, s: Struct): void; +export declare function disown<T extends Struct>(s: Struct): Orphan<T>; +/** + * Convert a struct to a struct of the provided class. Particularly useful when casting to nested group types. + * + * @protected + * @template T + * @param {StructCtor<T>} StructClass The struct class to convert to. Not particularly useful if `Struct`. + * @param {Struct} s The struct to convert. + * @returns {T} A new instance of the desired struct class pointing to the same location. + */ +export declare function getAs<T extends Struct>(StructClass: StructCtor<T>, s: Struct): T; +/** + * Read a boolean (bit) value out of a struct. + * + * @protected + * @param {number} bitOffset The offset in **bits** from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {boolean} The value. + */ +export declare function getBit(bitOffset: number, s: Struct, defaultMask?: DataView): boolean; +export declare function getData(index: number, s: Struct, defaultValue?: Pointer): Data; +export declare function getDataSection(s: Struct): Pointer; +/** + * Read a float32 value out of a struct. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +export declare function getFloat32(byteOffset: number, s: Struct, defaultMask?: DataView): number; +/** + * Read a float64 value out of this segment. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +export declare function getFloat64(byteOffset: number, s: Struct, defaultMask?: DataView): number; +/** + * Read an int16 value out of this segment. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +export declare function getInt16(byteOffset: number, s: Struct, defaultMask?: DataView): number; +/** + * Read an int32 value out of this segment. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +export declare function getInt32(byteOffset: number, s: Struct, defaultMask?: DataView): number; +/** + * Read an int64 value out of this segment. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +export declare function getInt64(byteOffset: number, s: Struct, defaultMask?: DataView): Int64; +/** + * Read an int8 value out of this segment. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +export declare function getInt8(byteOffset: number, s: Struct, defaultMask?: DataView): number; +export declare function getList<T>(index: number, ListClass: ListCtor<T>, s: Struct, defaultValue?: Pointer): List<T>; +export declare function getPointer(index: number, s: Struct): Pointer; +export declare function getPointerAs<T extends Pointer>(index: number, PointerClass: PointerCtor<T>, s: Struct): T; +export declare function getPointerSection(s: Struct): Pointer; +export declare function getSize(s: Struct): ObjectSize; +export declare function getStruct<T extends Struct>(index: number, StructClass: StructCtor<T>, s: Struct, defaultValue?: Pointer): T; +export declare function getText(index: number, s: Struct, defaultValue?: string): string; +/** + * Read an uint16 value out of a struct.. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +export declare function getUint16(byteOffset: number, s: Struct, defaultMask?: DataView): number; +/** + * Read an uint32 value out of a struct. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +export declare function getUint32(byteOffset: number, s: Struct, defaultMask?: DataView): number; +/** + * Read an uint64 value out of a struct. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +export declare function getUint64(byteOffset: number, s: Struct, defaultMask?: DataView): Uint64; +/** + * Read an uint8 value out of a struct. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +export declare function getUint8(byteOffset: number, s: Struct, defaultMask?: DataView): number; +export declare function getVoid(): void; +export declare function initData(index: number, length: number, s: Struct): Data; +export declare function initList<T>(index: number, ListClass: ListCtor<T>, length: number, s: Struct): List<T>; +/** + * Write a boolean (bit) value to the struct. + * + * @protected + * @param {number} bitOffset The offset in **bits** from the start of the data section. + * @param {boolean} value The value to write (writes a 0 for `false`, 1 for `true`). + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +export declare function setBit(bitOffset: number, value: boolean, s: Struct, defaultMask?: DataView): void; +/** + * Write a primitive float32 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +export declare function setFloat32(byteOffset: number, value: number, s: Struct, defaultMask?: DataView): void; +/** + * Write a primitive float64 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +export declare function setFloat64(byteOffset: number, value: number, s: Struct, defaultMask?: DataView): void; +/** + * Write a primitive int16 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +export declare function setInt16(byteOffset: number, value: number, s: Struct, defaultMask?: DataView): void; +/** + * Write a primitive int32 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +export declare function setInt32(byteOffset: number, value: number, s: Struct, defaultMask?: DataView): void; +/** + * Write a primitive int64 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +export declare function setInt64(byteOffset: number, value: Int64, s: Struct, defaultMask?: DataView): void; +/** + * Write a primitive int8 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +export declare function setInt8(byteOffset: number, value: number, s: Struct, defaultMask?: DataView): void; +export declare function setPointer(index: number, value: Pointer, s: Struct): void; +export declare function setText(index: number, value: string, s: Struct): void; +/** + * Write a primitive uint16 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +export declare function setUint16(byteOffset: number, value: number, s: Struct, defaultMask?: DataView): void; +/** + * Write a primitive uint32 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +export declare function setUint32(byteOffset: number, value: number, s: Struct, defaultMask?: DataView): void; +/** + * Write a primitive uint64 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +export declare function setUint64(byteOffset: number, value: Uint64, s: Struct, defaultMask?: DataView): void; +/** + * Write a primitive uint8 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +export declare function setUint8(byteOffset: number, value: number, s: Struct, defaultMask?: DataView): void; +export declare function setVoid(): void; +export declare function testWhich(name: string, found: number, wanted: number, s: Struct): void; +export declare function checkDataBounds(byteOffset: number, byteLength: number, s: Struct): void; +export declare function checkPointerBounds(index: number, s: Struct): void; diff --git a/node_modules/capnp-ts/src/serialization/pointers/struct.js b/node_modules/capnp-ts/src/serialization/pointers/struct.js new file mode 100644 index 0000000..bc14e52 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/struct.js @@ -0,0 +1,839 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.checkPointerBounds = exports.checkDataBounds = exports.testWhich = exports.setVoid = exports.setUint8 = exports.setUint64 = exports.setUint32 = exports.setUint16 = exports.setText = exports.setPointer = exports.setInt8 = exports.setInt64 = exports.setInt32 = exports.setInt16 = exports.setFloat64 = exports.setFloat32 = exports.setBit = exports.initList = exports.initData = exports.getVoid = exports.getUint8 = exports.getUint64 = exports.getUint32 = exports.getUint16 = exports.getText = exports.getStruct = exports.getSize = exports.getPointerSection = exports.getPointerAs = exports.getPointer = exports.getList = exports.getInt8 = exports.getInt64 = exports.getInt32 = exports.getInt16 = exports.getFloat64 = exports.getFloat32 = exports.getDataSection = exports.getData = exports.getBit = exports.getAs = exports.disown = exports.adopt = exports.resize = exports.initStructAt = exports.initStruct = exports.Struct = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const constants_1 = require("../../constants"); +const index_1 = require("../../types/index"); +const util_1 = require("../../util"); +const list_element_size_1 = require("../list-element-size"); +const object_size_1 = require("../object-size"); +const data_1 = require("./data"); +const list_1 = require("./list"); +const pointer_1 = require("./pointer"); +const pointer_type_1 = require("./pointer-type"); +const text_1 = require("./text"); +const errors_1 = require("../../errors"); +const trace = debug_1.default("capnp:struct"); +trace("load"); +// Used to apply bit masks (default values). +const TMP_WORD = new DataView(new ArrayBuffer(8)); +class Struct extends pointer_1.Pointer { + /** + * Create a new pointer to a struct. + * + * @constructor {Struct} + * @param {Segment} segment The segment the pointer resides in. + * @param {number} byteOffset The offset from the beginning of the segment to the beginning of the pointer data. + * @param {any} [depthLimit=MAX_DEPTH] The nesting depth limit for this object. + * @param {number} [compositeIndex] If set, then this pointer is actually a reference to a composite list + * (`this._getPointerTargetType() === PointerType.LIST`), and this number is used as the index of the struct within + * the list. It is not valid to call `initStruct()` on a composite struct – the struct contents are initialized when + * the list pointer is initialized. + */ + constructor(segment, byteOffset, depthLimit = constants_1.MAX_DEPTH, compositeIndex) { + super(segment, byteOffset, depthLimit); + this._capnp.compositeIndex = compositeIndex; + this._capnp.compositeList = compositeIndex !== undefined; + } + static toString() { + return this._capnp.displayName; + } + toString() { + return (`Struct_${super.toString()}` + + `${this._capnp.compositeIndex === undefined ? "" : `,ci:${this._capnp.compositeIndex}`}`); + } +} +exports.Struct = Struct; +Struct._capnp = { + displayName: "Struct", +}; +Struct.getAs = getAs; +Struct.getBit = getBit; +Struct.getData = getData; +Struct.getFloat32 = getFloat32; +Struct.getFloat64 = getFloat64; +Struct.getUint8 = getUint8; +Struct.getUint16 = getUint16; +Struct.getUint32 = getUint32; +Struct.getUint64 = getUint64; +Struct.getInt8 = getInt8; +Struct.getInt16 = getInt16; +Struct.getInt32 = getInt32; +Struct.getInt64 = getInt64; +Struct.getList = getList; +Struct.getPointer = getPointer; +Struct.getPointerAs = getPointerAs; +Struct.getStruct = getStruct; +Struct.getText = getText; +Struct.initData = initData; +Struct.initList = initList; +Struct.initStruct = initStruct; +Struct.initStructAt = initStructAt; +Struct.setBit = setBit; +Struct.setFloat32 = setFloat32; +Struct.setFloat64 = setFloat64; +Struct.setUint8 = setUint8; +Struct.setUint16 = setUint16; +Struct.setUint32 = setUint32; +Struct.setUint64 = setUint64; +Struct.setInt8 = setInt8; +Struct.setInt16 = setInt16; +Struct.setInt32 = setInt32; +Struct.setInt64 = setInt64; +Struct.setText = setText; +Struct.testWhich = testWhich; +/** + * Initialize a struct with the provided object size. This will allocate new space for the struct contents, ideally in + * the same segment as this pointer. + * + * @param {ObjectSize} size An object describing the size of the struct's data and pointer sections. + * @param {Struct} s The struct to initialize. + * @returns {void} + */ +function initStruct(size, s) { + if (s._capnp.compositeIndex !== undefined) { + throw new Error(util_1.format(errors_1.PTR_INIT_COMPOSITE_STRUCT, s)); + } + // Make sure to clear existing contents before overwriting the pointer data (erase is a noop if already empty). + pointer_1.erase(s); + const c = s.segment.allocate(object_size_1.getByteLength(size)); + const res = pointer_1.initPointer(c.segment, c.byteOffset, s); + pointer_1.setStructPointer(res.offsetWords, size, res.pointer); +} +exports.initStruct = initStruct; +function initStructAt(index, StructClass, p) { + const s = getPointerAs(index, StructClass, p); + initStruct(StructClass._capnp.size, s); + return s; +} +exports.initStructAt = initStructAt; +/** + * Make a shallow copy of a struct's contents and update the pointer to point to the new content. The data and pointer + * sections will be resized to the provided size. + * + * WARNING: This method can cause data loss if `dstSize` is smaller than the original size! + * + * @param {ObjectSize} dstSize The desired size for the struct contents. + * @param {Struct} s The struct to resize. + * @returns {void} + */ +function resize(dstSize, s) { + const srcSize = getSize(s); + const srcContent = pointer_1.getContent(s); + const dstContent = s.segment.allocate(object_size_1.getByteLength(dstSize)); + // Only copy the data section for now. The pointer section will need to be rewritten. + dstContent.segment.copyWords(dstContent.byteOffset, srcContent.segment, srcContent.byteOffset, Math.min(object_size_1.getDataWordLength(srcSize), object_size_1.getDataWordLength(dstSize))); + const res = pointer_1.initPointer(dstContent.segment, dstContent.byteOffset, s); + pointer_1.setStructPointer(res.offsetWords, dstSize, res.pointer); + // Iterate through the new pointer section and update the offsets so they point to the right place. This is a bit + // more complicated than it appears due to the fact that the original pointers could have been far pointers, and + // the new pointers might need to be allocated as far pointers if the segment is full. + for (let i = 0; i < Math.min(srcSize.pointerLength, dstSize.pointerLength); i++) { + const srcPtr = new pointer_1.Pointer(srcContent.segment, srcContent.byteOffset + srcSize.dataByteLength + i * 8); + if (pointer_1.isNull(srcPtr)) { + // If source pointer is null, leave the destination pointer as default null. + continue; + } + const srcPtrTarget = pointer_1.followFars(srcPtr); + const srcPtrContent = pointer_1.getContent(srcPtr); + const dstPtr = new pointer_1.Pointer(dstContent.segment, dstContent.byteOffset + dstSize.dataByteLength + i * 8); + // For composite lists the offset needs to point to the tag word, not the first element which is what getContent + // returns. + if (pointer_1.getTargetPointerType(srcPtr) === pointer_type_1.PointerType.LIST && + pointer_1.getTargetListElementSize(srcPtr) === list_element_size_1.ListElementSize.COMPOSITE) { + srcPtrContent.byteOffset -= 8; + } + const r = pointer_1.initPointer(srcPtrContent.segment, srcPtrContent.byteOffset, dstPtr); + // Read the old pointer data, but discard the original offset. + const a = srcPtrTarget.segment.getUint8(srcPtrTarget.byteOffset) & 0x03; + const b = srcPtrTarget.segment.getUint32(srcPtrTarget.byteOffset + 4); + r.pointer.segment.setUint32(r.pointer.byteOffset, a | (r.offsetWords << 2)); + r.pointer.segment.setUint32(r.pointer.byteOffset + 4, b); + } + // Zero out the old data and pointer sections. + srcContent.segment.fillZeroWords(srcContent.byteOffset, object_size_1.getWordLength(srcSize)); +} +exports.resize = resize; +function adopt(src, s) { + if (s._capnp.compositeIndex !== undefined) { + throw new Error(util_1.format(errors_1.PTR_ADOPT_COMPOSITE_STRUCT, s)); + } + pointer_1.Pointer.adopt(src, s); +} +exports.adopt = adopt; +function disown(s) { + if (s._capnp.compositeIndex !== undefined) { + throw new Error(util_1.format(errors_1.PTR_DISOWN_COMPOSITE_STRUCT, s)); + } + return pointer_1.Pointer.disown(s); +} +exports.disown = disown; +/** + * Convert a struct to a struct of the provided class. Particularly useful when casting to nested group types. + * + * @protected + * @template T + * @param {StructCtor<T>} StructClass The struct class to convert to. Not particularly useful if `Struct`. + * @param {Struct} s The struct to convert. + * @returns {T} A new instance of the desired struct class pointing to the same location. + */ +function getAs(StructClass, s) { + return new StructClass(s.segment, s.byteOffset, s._capnp.depthLimit, s._capnp.compositeIndex); +} +exports.getAs = getAs; +/** + * Read a boolean (bit) value out of a struct. + * + * @protected + * @param {number} bitOffset The offset in **bits** from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {boolean} The value. + */ +function getBit(bitOffset, s, defaultMask) { + const byteOffset = Math.floor(bitOffset / 8); + const bitMask = 1 << bitOffset % 8; + checkDataBounds(byteOffset, 1, s); + const ds = getDataSection(s); + const v = ds.segment.getUint8(ds.byteOffset + byteOffset); + if (defaultMask === undefined) + return (v & bitMask) !== 0; + const defaultValue = defaultMask.getUint8(0); + return ((v ^ defaultValue) & bitMask) !== 0; +} +exports.getBit = getBit; +function getData(index, s, defaultValue) { + checkPointerBounds(index, s); + const ps = getPointerSection(s); + ps.byteOffset += index * 8; + const l = new data_1.Data(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1); + if (pointer_1.isNull(l)) { + if (defaultValue) { + pointer_1.Pointer.copyFrom(defaultValue, l); + } + else { + list_1.List.initList(list_element_size_1.ListElementSize.BYTE, 0, l); + } + } + return l; +} +exports.getData = getData; +function getDataSection(s) { + return pointer_1.getContent(s); +} +exports.getDataSection = getDataSection; +/** + * Read a float32 value out of a struct. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +function getFloat32(byteOffset, s, defaultMask) { + checkDataBounds(byteOffset, 4, s); + const ds = getDataSection(s); + if (defaultMask === undefined) { + return ds.segment.getFloat32(ds.byteOffset + byteOffset); + } + const v = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true); + TMP_WORD.setUint32(0, v, constants_1.NATIVE_LITTLE_ENDIAN); + return TMP_WORD.getFloat32(0, constants_1.NATIVE_LITTLE_ENDIAN); +} +exports.getFloat32 = getFloat32; +/** + * Read a float64 value out of this segment. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +function getFloat64(byteOffset, s, defaultMask) { + checkDataBounds(byteOffset, 8, s); + const ds = getDataSection(s); + if (defaultMask !== undefined) { + const lo = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true); + const hi = ds.segment.getUint32(ds.byteOffset + byteOffset + 4) ^ defaultMask.getUint32(4, true); + TMP_WORD.setUint32(0, lo, constants_1.NATIVE_LITTLE_ENDIAN); + TMP_WORD.setUint32(4, hi, constants_1.NATIVE_LITTLE_ENDIAN); + return TMP_WORD.getFloat64(0, constants_1.NATIVE_LITTLE_ENDIAN); + } + return ds.segment.getFloat64(ds.byteOffset + byteOffset); +} +exports.getFloat64 = getFloat64; +/** + * Read an int16 value out of this segment. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +function getInt16(byteOffset, s, defaultMask) { + checkDataBounds(byteOffset, 2, s); + const ds = getDataSection(s); + if (defaultMask === undefined) { + return ds.segment.getInt16(ds.byteOffset + byteOffset); + } + const v = ds.segment.getUint16(ds.byteOffset + byteOffset) ^ defaultMask.getUint16(0, true); + TMP_WORD.setUint16(0, v, constants_1.NATIVE_LITTLE_ENDIAN); + return TMP_WORD.getInt16(0, constants_1.NATIVE_LITTLE_ENDIAN); +} +exports.getInt16 = getInt16; +/** + * Read an int32 value out of this segment. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +function getInt32(byteOffset, s, defaultMask) { + checkDataBounds(byteOffset, 4, s); + const ds = getDataSection(s); + if (defaultMask === undefined) { + return ds.segment.getInt32(ds.byteOffset + byteOffset); + } + const v = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint16(0, true); + TMP_WORD.setUint32(0, v, constants_1.NATIVE_LITTLE_ENDIAN); + return TMP_WORD.getInt32(0, constants_1.NATIVE_LITTLE_ENDIAN); +} +exports.getInt32 = getInt32; +/** + * Read an int64 value out of this segment. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +function getInt64(byteOffset, s, defaultMask) { + checkDataBounds(byteOffset, 8, s); + const ds = getDataSection(s); + if (defaultMask === undefined) { + return ds.segment.getInt64(ds.byteOffset + byteOffset); + } + const lo = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true); + const hi = ds.segment.getUint32(ds.byteOffset + byteOffset + 4) ^ defaultMask.getUint32(4, true); + TMP_WORD.setUint32(0, lo, constants_1.NATIVE_LITTLE_ENDIAN); + TMP_WORD.setUint32(4, hi, constants_1.NATIVE_LITTLE_ENDIAN); + return new index_1.Int64(new Uint8Array(TMP_WORD.buffer.slice(0))); +} +exports.getInt64 = getInt64; +/** + * Read an int8 value out of this segment. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +function getInt8(byteOffset, s, defaultMask) { + checkDataBounds(byteOffset, 1, s); + const ds = getDataSection(s); + if (defaultMask === undefined) { + return ds.segment.getInt8(ds.byteOffset + byteOffset); + } + const v = ds.segment.getUint8(ds.byteOffset + byteOffset) ^ defaultMask.getUint8(0); + TMP_WORD.setUint8(0, v); + return TMP_WORD.getInt8(0); +} +exports.getInt8 = getInt8; +function getList(index, ListClass, s, defaultValue) { + checkPointerBounds(index, s); + const ps = getPointerSection(s); + ps.byteOffset += index * 8; + const l = new ListClass(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1); + if (pointer_1.isNull(l)) { + if (defaultValue) { + pointer_1.Pointer.copyFrom(defaultValue, l); + } + else { + list_1.List.initList(ListClass._capnp.size, 0, l, ListClass._capnp.compositeSize); + } + } + else if (ListClass._capnp.compositeSize !== undefined) { + // If this is a composite list we need to be sure the composite elements are big enough to hold everything as + // specified in the schema. If the new schema has added fields we'll need to "resize" (shallow-copy) the list so + // it has room for the new fields. + const srcSize = pointer_1.getTargetCompositeListSize(l); + const dstSize = ListClass._capnp.compositeSize; + if (dstSize.dataByteLength > srcSize.dataByteLength || dstSize.pointerLength > srcSize.pointerLength) { + const srcContent = pointer_1.getContent(l); + const srcLength = pointer_1.getTargetListLength(l); + trace("resizing composite list %s due to protocol upgrade, new size: %d", l, object_size_1.getByteLength(dstSize) * srcLength); + // Allocate an extra 8 bytes for the tag. + const dstContent = l.segment.allocate(object_size_1.getByteLength(dstSize) * srcLength + 8); + const res = pointer_1.initPointer(dstContent.segment, dstContent.byteOffset, l); + pointer_1.setListPointer(res.offsetWords, ListClass._capnp.size, srcLength, res.pointer, dstSize); + // Write the new tag word. + pointer_1.setStructPointer(srcLength, dstSize, dstContent); + // Seek ahead past the tag word before copying the content. + dstContent.byteOffset += 8; + for (let i = 0; i < srcLength; i++) { + const srcElementOffset = srcContent.byteOffset + i * object_size_1.getByteLength(srcSize); + const dstElementOffset = dstContent.byteOffset + i * object_size_1.getByteLength(dstSize); + // Copy the data section. + dstContent.segment.copyWords(dstElementOffset, srcContent.segment, srcElementOffset, object_size_1.getWordLength(srcSize)); + // Iterate through the pointers and update the offsets so they point to the right place. + for (let j = 0; j < srcSize.pointerLength; j++) { + const srcPtr = new pointer_1.Pointer(srcContent.segment, srcElementOffset + srcSize.dataByteLength + j * 8); + const dstPtr = new pointer_1.Pointer(dstContent.segment, dstElementOffset + dstSize.dataByteLength + j * 8); + const srcPtrTarget = pointer_1.followFars(srcPtr); + const srcPtrContent = pointer_1.getContent(srcPtr); + if (pointer_1.getTargetPointerType(srcPtr) === pointer_type_1.PointerType.LIST && + pointer_1.getTargetListElementSize(srcPtr) === list_element_size_1.ListElementSize.COMPOSITE) { + srcPtrContent.byteOffset -= 8; + } + const r = pointer_1.initPointer(srcPtrContent.segment, srcPtrContent.byteOffset, dstPtr); + // Read the old pointer data, but discard the original offset. + const a = srcPtrTarget.segment.getUint8(srcPtrTarget.byteOffset) & 0x03; + const b = srcPtrTarget.segment.getUint32(srcPtrTarget.byteOffset + 4); + r.pointer.segment.setUint32(r.pointer.byteOffset, a | (r.offsetWords << 2)); + r.pointer.segment.setUint32(r.pointer.byteOffset + 4, b); + } + } + // Zero out the old content. + srcContent.segment.fillZeroWords(srcContent.byteOffset, object_size_1.getWordLength(srcSize) * srcLength); + } + } + return l; +} +exports.getList = getList; +function getPointer(index, s) { + checkPointerBounds(index, s); + const ps = getPointerSection(s); + ps.byteOffset += index * 8; + return new pointer_1.Pointer(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1); +} +exports.getPointer = getPointer; +function getPointerAs(index, PointerClass, s) { + checkPointerBounds(index, s); + const ps = getPointerSection(s); + ps.byteOffset += index * 8; + return new PointerClass(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1); +} +exports.getPointerAs = getPointerAs; +function getPointerSection(s) { + const ps = pointer_1.getContent(s); + ps.byteOffset += util_1.padToWord(getSize(s).dataByteLength); + return ps; +} +exports.getPointerSection = getPointerSection; +function getSize(s) { + if (s._capnp.compositeIndex !== undefined) { + // For composite lists the object size is stored in a tag word right before the content. + const c = pointer_1.getContent(s, true); + c.byteOffset -= 8; + return pointer_1.getStructSize(c); + } + return pointer_1.getTargetStructSize(s); +} +exports.getSize = getSize; +function getStruct(index, StructClass, s, defaultValue) { + const t = getPointerAs(index, StructClass, s); + if (pointer_1.isNull(t)) { + if (defaultValue) { + pointer_1.Pointer.copyFrom(defaultValue, t); + } + else { + initStruct(StructClass._capnp.size, t); + } + } + else { + pointer_1.validate(pointer_type_1.PointerType.STRUCT, t); + const ts = pointer_1.getTargetStructSize(t); + // This can happen when reading a struct that was constructed with an older version of the same schema, and new + // fields were added to the struct. A shallow copy of the struct will be made so that there's enough room for the + // data and pointer sections. This will unfortunately leave a "hole" of zeroes in the message, but that hole will + // at least compress well. + if (ts.dataByteLength < StructClass._capnp.size.dataByteLength || + ts.pointerLength < StructClass._capnp.size.pointerLength) { + trace("need to resize child struct %s", t); + resize(StructClass._capnp.size, t); + } + } + return t; +} +exports.getStruct = getStruct; +function getText(index, s, defaultValue) { + const t = text_1.Text.fromPointer(getPointer(index, s)); + // FIXME: This will perform an unnecessary string<>ArrayBuffer roundtrip. + if (pointer_1.isNull(t) && defaultValue) + t.set(0, defaultValue); + return t.get(0); +} +exports.getText = getText; +/** + * Read an uint16 value out of a struct.. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +function getUint16(byteOffset, s, defaultMask) { + checkDataBounds(byteOffset, 2, s); + const ds = getDataSection(s); + if (defaultMask === undefined) { + return ds.segment.getUint16(ds.byteOffset + byteOffset); + } + return ds.segment.getUint16(ds.byteOffset + byteOffset) ^ defaultMask.getUint16(0, true); +} +exports.getUint16 = getUint16; +/** + * Read an uint32 value out of a struct. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +function getUint32(byteOffset, s, defaultMask) { + checkDataBounds(byteOffset, 4, s); + const ds = getDataSection(s); + if (defaultMask === undefined) { + return ds.segment.getUint32(ds.byteOffset + byteOffset); + } + return ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true); +} +exports.getUint32 = getUint32; +/** + * Read an uint64 value out of a struct. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +function getUint64(byteOffset, s, defaultMask) { + checkDataBounds(byteOffset, 8, s); + const ds = getDataSection(s); + if (defaultMask === undefined) { + return ds.segment.getUint64(ds.byteOffset + byteOffset); + } + const lo = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true); + const hi = ds.segment.getUint32(ds.byteOffset + byteOffset + 4) ^ defaultMask.getUint32(4, true); + TMP_WORD.setUint32(0, lo, constants_1.NATIVE_LITTLE_ENDIAN); + TMP_WORD.setUint32(4, hi, constants_1.NATIVE_LITTLE_ENDIAN); + return new index_1.Uint64(new Uint8Array(TMP_WORD.buffer.slice(0))); +} +exports.getUint64 = getUint64; +/** + * Read an uint8 value out of a struct. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ +function getUint8(byteOffset, s, defaultMask) { + checkDataBounds(byteOffset, 1, s); + const ds = getDataSection(s); + if (defaultMask === undefined) { + return ds.segment.getUint8(ds.byteOffset + byteOffset); + } + return ds.segment.getUint8(ds.byteOffset + byteOffset) ^ defaultMask.getUint8(0); +} +exports.getUint8 = getUint8; +function getVoid() { + throw new Error(errors_1.INVARIANT_UNREACHABLE_CODE); +} +exports.getVoid = getVoid; +function initData(index, length, s) { + checkPointerBounds(index, s); + const ps = getPointerSection(s); + ps.byteOffset += index * 8; + const l = new data_1.Data(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1); + pointer_1.erase(l); + list_1.List.initList(list_element_size_1.ListElementSize.BYTE, length, l); + return l; +} +exports.initData = initData; +function initList(index, ListClass, length, s) { + checkPointerBounds(index, s); + const ps = getPointerSection(s); + ps.byteOffset += index * 8; + const l = new ListClass(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1); + pointer_1.erase(l); + list_1.List.initList(ListClass._capnp.size, length, l, ListClass._capnp.compositeSize); + return l; +} +exports.initList = initList; +/** + * Write a boolean (bit) value to the struct. + * + * @protected + * @param {number} bitOffset The offset in **bits** from the start of the data section. + * @param {boolean} value The value to write (writes a 0 for `false`, 1 for `true`). + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +function setBit(bitOffset, value, s, defaultMask) { + const byteOffset = Math.floor(bitOffset / 8); + const bitMask = 1 << bitOffset % 8; + checkDataBounds(byteOffset, 1, s); + const ds = getDataSection(s); + const b = ds.segment.getUint8(ds.byteOffset + byteOffset); + // If the default mask bit is set, that means `true` values are actually written as `0`. + if (defaultMask !== undefined) { + value = (defaultMask.getUint8(0) & bitMask) !== 0 ? !value : value; + } + ds.segment.setUint8(ds.byteOffset + byteOffset, value ? b | bitMask : b & ~bitMask); +} +exports.setBit = setBit; +/** + * Write a primitive float32 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +function setFloat32(byteOffset, value, s, defaultMask) { + checkDataBounds(byteOffset, 4, s); + const ds = getDataSection(s); + if (defaultMask !== undefined) { + TMP_WORD.setFloat32(0, value, constants_1.NATIVE_LITTLE_ENDIAN); + const v = TMP_WORD.getUint32(0, constants_1.NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(0, true); + ds.segment.setUint32(ds.byteOffset + byteOffset, v); + return; + } + ds.segment.setFloat32(ds.byteOffset + byteOffset, value); +} +exports.setFloat32 = setFloat32; +/** + * Write a primitive float64 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +function setFloat64(byteOffset, value, s, defaultMask) { + checkDataBounds(byteOffset, 8, s); + const ds = getDataSection(s); + if (defaultMask !== undefined) { + TMP_WORD.setFloat64(0, value, constants_1.NATIVE_LITTLE_ENDIAN); + const lo = TMP_WORD.getUint32(0, constants_1.NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(0, true); + const hi = TMP_WORD.getUint32(4, constants_1.NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(4, true); + ds.segment.setUint32(ds.byteOffset + byteOffset, lo); + ds.segment.setUint32(ds.byteOffset + byteOffset + 4, hi); + return; + } + ds.segment.setFloat64(ds.byteOffset + byteOffset, value); +} +exports.setFloat64 = setFloat64; +/** + * Write a primitive int16 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +function setInt16(byteOffset, value, s, defaultMask) { + checkDataBounds(byteOffset, 2, s); + const ds = getDataSection(s); + if (defaultMask !== undefined) { + TMP_WORD.setInt16(0, value, constants_1.NATIVE_LITTLE_ENDIAN); + const v = TMP_WORD.getUint16(0, constants_1.NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint16(0, true); + ds.segment.setUint16(ds.byteOffset + byteOffset, v); + return; + } + ds.segment.setInt16(ds.byteOffset + byteOffset, value); +} +exports.setInt16 = setInt16; +/** + * Write a primitive int32 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +function setInt32(byteOffset, value, s, defaultMask) { + checkDataBounds(byteOffset, 4, s); + const ds = getDataSection(s); + if (defaultMask !== undefined) { + TMP_WORD.setInt32(0, value, constants_1.NATIVE_LITTLE_ENDIAN); + const v = TMP_WORD.getUint32(0, constants_1.NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(0, true); + ds.segment.setUint32(ds.byteOffset + byteOffset, v); + return; + } + ds.segment.setInt32(ds.byteOffset + byteOffset, value); +} +exports.setInt32 = setInt32; +/** + * Write a primitive int64 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +function setInt64(byteOffset, value, s, defaultMask) { + checkDataBounds(byteOffset, 8, s); + const ds = getDataSection(s); + if (defaultMask !== undefined) { + // PERF: We could cast the Int64 to a DataView to apply the mask using four 32-bit reads, but we already have a + // typed array so avoiding the object allocation turns out to be slightly faster. Int64 is guaranteed to be in + // little-endian format by design. + for (let i = 0; i < 8; i++) { + ds.segment.setUint8(ds.byteOffset + byteOffset + i, value.buffer[i] ^ defaultMask.getUint8(i)); + } + return; + } + ds.segment.setInt64(ds.byteOffset + byteOffset, value); +} +exports.setInt64 = setInt64; +/** + * Write a primitive int8 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +function setInt8(byteOffset, value, s, defaultMask) { + checkDataBounds(byteOffset, 1, s); + const ds = getDataSection(s); + if (defaultMask !== undefined) { + TMP_WORD.setInt8(0, value); + const v = TMP_WORD.getUint8(0) ^ defaultMask.getUint8(0); + ds.segment.setUint8(ds.byteOffset + byteOffset, v); + return; + } + ds.segment.setInt8(ds.byteOffset + byteOffset, value); +} +exports.setInt8 = setInt8; +function setPointer(index, value, s) { + pointer_1.copyFrom(value, getPointer(index, s)); +} +exports.setPointer = setPointer; +function setText(index, value, s) { + text_1.Text.fromPointer(getPointer(index, s)).set(0, value); +} +exports.setText = setText; +/** + * Write a primitive uint16 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +function setUint16(byteOffset, value, s, defaultMask) { + checkDataBounds(byteOffset, 2, s); + const ds = getDataSection(s); + if (defaultMask !== undefined) + value ^= defaultMask.getUint16(0, true); + ds.segment.setUint16(ds.byteOffset + byteOffset, value); +} +exports.setUint16 = setUint16; +/** + * Write a primitive uint32 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +function setUint32(byteOffset, value, s, defaultMask) { + checkDataBounds(byteOffset, 4, s); + const ds = getDataSection(s); + if (defaultMask !== undefined) + value ^= defaultMask.getUint32(0, true); + ds.segment.setUint32(ds.byteOffset + byteOffset, value); +} +exports.setUint32 = setUint32; +/** + * Write a primitive uint64 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +function setUint64(byteOffset, value, s, defaultMask) { + checkDataBounds(byteOffset, 8, s); + const ds = getDataSection(s); + if (defaultMask !== undefined) { + // PERF: We could cast the Uint64 to a DataView to apply the mask using four 32-bit reads, but we already have a + // typed array so avoiding the object allocation turns out to be slightly faster. Uint64 is guaranteed to be in + // little-endian format by design. + for (let i = 0; i < 8; i++) { + ds.segment.setUint8(ds.byteOffset + byteOffset + i, value.buffer[i] ^ defaultMask.getUint8(i)); + } + return; + } + ds.segment.setUint64(ds.byteOffset + byteOffset, value); +} +exports.setUint64 = setUint64; +/** + * Write a primitive uint8 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ +function setUint8(byteOffset, value, s, defaultMask) { + checkDataBounds(byteOffset, 1, s); + const ds = getDataSection(s); + if (defaultMask !== undefined) + value ^= defaultMask.getUint8(0); + ds.segment.setUint8(ds.byteOffset + byteOffset, value); +} +exports.setUint8 = setUint8; +function setVoid() { + throw new Error(errors_1.INVARIANT_UNREACHABLE_CODE); +} +exports.setVoid = setVoid; +function testWhich(name, found, wanted, s) { + if (found !== wanted) { + throw new Error(util_1.format(errors_1.PTR_INVALID_UNION_ACCESS, s, name, found, wanted)); + } +} +exports.testWhich = testWhich; +function checkDataBounds(byteOffset, byteLength, s) { + const dataByteLength = getSize(s).dataByteLength; + if (byteOffset < 0 || byteLength < 0 || byteOffset + byteLength > dataByteLength) { + throw new Error(util_1.format(errors_1.PTR_STRUCT_DATA_OUT_OF_BOUNDS, s, byteLength, byteOffset, dataByteLength)); + } +} +exports.checkDataBounds = checkDataBounds; +function checkPointerBounds(index, s) { + const pointerLength = getSize(s).pointerLength; + if (index < 0 || index >= pointerLength) { + throw new Error(util_1.format(errors_1.PTR_STRUCT_POINTER_OUT_OF_BOUNDS, s, index, pointerLength)); + } +} +exports.checkPointerBounds = checkPointerBounds; +//# sourceMappingURL=struct.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/struct.js.map b/node_modules/capnp-ts/src/serialization/pointers/struct.js.map new file mode 100644 index 0000000..a6233ff --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/struct.js.map @@ -0,0 +1 @@ +{"version":3,"file":"struct.js","sourceRoot":"","sources":["struct.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,+CAAkE;AAClE,6CAAkD;AAClD,qCAA+C;AAC/C,4DAAuD;AACvD,gDAA6F;AAE7F,iCAA8B;AAC9B,iCAAwC;AAExC,uCAoBmB;AACnB,iDAA6C;AAC7C,iCAA8B;AAC9B,yCAQsB;AAEtB,MAAM,KAAK,GAAG,eAAS,CAAC,cAAc,CAAC,CAAC;AACxC,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,4CAA4C;AAC5C,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AAiBlD,MAAa,MAAO,SAAQ,iBAAO;IA0CjC;;;;;;;;;;;OAWG;IAEH,YAAY,OAAgB,EAAE,UAAkB,EAAE,UAAU,GAAG,qBAAS,EAAE,cAAuB;QAC/F,KAAK,CAAC,OAAO,EAAE,U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AAU,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC;KACnG;AACH,CAAC;AAND,0CAMC;AAED,SAAgB,kBAAkB,CAAC,KAAa,EAAE,CAAS;IACzD,MAAM,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;IAE/C,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,aAAa,EAAE;QACvC,MAAM,IAAI,KAAK,CAAC,aAAM,CAAC,yCAAgC,EAAE,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC;KACpF;AACH,CAAC;AAND,gDAMC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/struct.ts b/node_modules/capnp-ts/src/serialization/pointers/struct.ts new file mode 100644 index 0000000..30b3fc0 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/struct.ts @@ -0,0 +1,1090 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { MAX_DEPTH, NATIVE_LITTLE_ENDIAN } from "../../constants"; +import { Int64, Uint64 } from "../../types/index"; +import { format, padToWord } from "../../util"; +import { ListElementSize } from "../list-element-size"; +import { ObjectSize, getByteLength, getDataWordLength, getWordLength } from "../object-size"; +import { Segment } from "../segment"; +import { Data } from "./data"; +import { List, ListCtor } from "./list"; +import { Orphan } from "./orphan"; +import { + _Pointer, + _PointerCtor, + Pointer, + PointerCtor, + getContent, + getStructSize, + initPointer, + erase, + setStructPointer, + followFars, + getTargetListElementSize, + getTargetPointerType, + isNull, + getTargetCompositeListSize, + getTargetListLength, + setListPointer, + getTargetStructSize, + validate, + copyFrom, +} from "./pointer"; +import { PointerType } from "./pointer-type"; +import { Text } from "./text"; +import { + PTR_INIT_COMPOSITE_STRUCT, + PTR_ADOPT_COMPOSITE_STRUCT, + PTR_DISOWN_COMPOSITE_STRUCT, + PTR_INVALID_UNION_ACCESS, + PTR_STRUCT_DATA_OUT_OF_BOUNDS, + PTR_STRUCT_POINTER_OUT_OF_BOUNDS, + INVARIANT_UNREACHABLE_CODE, +} from "../../errors"; + +const trace = initTrace("capnp:struct"); +trace("load"); + +// Used to apply bit masks (default values). +const TMP_WORD = new DataView(new ArrayBuffer(8)); + +export interface _StructCtor extends _PointerCtor { + readonly id: string; + readonly size: ObjectSize; +} + +export interface StructCtor<T extends Struct> { + readonly _capnp: _StructCtor; + + new (segment: Segment, byteOffset: number, depthLimit?: number, compositeIndex?: number): T; +} + +export interface _Struct extends _Pointer { + compositeIndex?: number; +} + +export class Struct extends Pointer { + static readonly _capnp = { + displayName: "Struct" as string, + }; + static readonly getAs = getAs; + static readonly getBit = getBit; + static readonly getData = getData; + static readonly getFloat32 = getFloat32; + static readonly getFloat64 = getFloat64; + static readonly getUint8 = getUint8; + static readonly getUint16 = getUint16; + static readonly getUint32 = getUint32; + static readonly getUint64 = getUint64; + static readonly getInt8 = getInt8; + static readonly getInt16 = getInt16; + static readonly getInt32 = getInt32; + static readonly getInt64 = getInt64; + static readonly getList = getList; + static readonly getPointer = getPointer; + static readonly getPointerAs = getPointerAs; + static readonly getStruct = getStruct; + static readonly getText = getText; + static readonly initData = initData; + static readonly initList = initList; + static readonly initStruct = initStruct; + static readonly initStructAt = initStructAt; + static readonly setBit = setBit; + static readonly setFloat32 = setFloat32; + static readonly setFloat64 = setFloat64; + static readonly setUint8 = setUint8; + static readonly setUint16 = setUint16; + static readonly setUint32 = setUint32; + static readonly setUint64 = setUint64; + static readonly setInt8 = setInt8; + static readonly setInt16 = setInt16; + static readonly setInt32 = setInt32; + static readonly setInt64 = setInt64; + static readonly setText = setText; + static readonly testWhich = testWhich; + + readonly _capnp!: _Struct; + + /** + * Create a new pointer to a struct. + * + * @constructor {Struct} + * @param {Segment} segment The segment the pointer resides in. + * @param {number} byteOffset The offset from the beginning of the segment to the beginning of the pointer data. + * @param {any} [depthLimit=MAX_DEPTH] The nesting depth limit for this object. + * @param {number} [compositeIndex] If set, then this pointer is actually a reference to a composite list + * (`this._getPointerTargetType() === PointerType.LIST`), and this number is used as the index of the struct within + * the list. It is not valid to call `initStruct()` on a composite struct – the struct contents are initialized when + * the list pointer is initialized. + */ + + constructor(segment: Segment, byteOffset: number, depthLimit = MAX_DEPTH, compositeIndex?: number) { + super(segment, byteOffset, depthLimit); + + this._capnp.compositeIndex = compositeIndex; + this._capnp.compositeList = compositeIndex !== undefined; + } + + static toString(): string { + return this._capnp.displayName; + } + + toString(): string { + return ( + `Struct_${super.toString()}` + + `${this._capnp.compositeIndex === undefined ? "" : `,ci:${this._capnp.compositeIndex}`}` + ); + } +} + +/** + * Initialize a struct with the provided object size. This will allocate new space for the struct contents, ideally in + * the same segment as this pointer. + * + * @param {ObjectSize} size An object describing the size of the struct's data and pointer sections. + * @param {Struct} s The struct to initialize. + * @returns {void} + */ + +export function initStruct(size: ObjectSize, s: Struct): void { + if (s._capnp.compositeIndex !== undefined) { + throw new Error(format(PTR_INIT_COMPOSITE_STRUCT, s)); + } + + // Make sure to clear existing contents before overwriting the pointer data (erase is a noop if already empty). + + erase(s); + + const c = s.segment.allocate(getByteLength(size)); + + const res = initPointer(c.segment, c.byteOffset, s); + + setStructPointer(res.offsetWords, size, res.pointer); +} + +export function initStructAt<T extends Struct>(index: number, StructClass: StructCtor<T>, p: Pointer): T { + const s = getPointerAs(index, StructClass, p); + + initStruct(StructClass._capnp.size, s); + + return s; +} + +/** + * Make a shallow copy of a struct's contents and update the pointer to point to the new content. The data and pointer + * sections will be resized to the provided size. + * + * WARNING: This method can cause data loss if `dstSize` is smaller than the original size! + * + * @param {ObjectSize} dstSize The desired size for the struct contents. + * @param {Struct} s The struct to resize. + * @returns {void} + */ + +export function resize(dstSize: ObjectSize, s: Struct): void { + const srcSize = getSize(s); + const srcContent = getContent(s); + const dstContent = s.segment.allocate(getByteLength(dstSize)); + + // Only copy the data section for now. The pointer section will need to be rewritten. + dstContent.segment.copyWords( + dstContent.byteOffset, + srcContent.segment, + srcContent.byteOffset, + Math.min(getDataWordLength(srcSize), getDataWordLength(dstSize)) + ); + + const res = initPointer(dstContent.segment, dstContent.byteOffset, s); + + setStructPointer(res.offsetWords, dstSize, res.pointer); + + // Iterate through the new pointer section and update the offsets so they point to the right place. This is a bit + // more complicated than it appears due to the fact that the original pointers could have been far pointers, and + // the new pointers might need to be allocated as far pointers if the segment is full. + + for (let i = 0; i < Math.min(srcSize.pointerLength, dstSize.pointerLength); i++) { + const srcPtr = new Pointer(srcContent.segment, srcContent.byteOffset + srcSize.dataByteLength + i * 8); + if (isNull(srcPtr)) { + // If source pointer is null, leave the destination pointer as default null. + continue; + } + const srcPtrTarget = followFars(srcPtr); + const srcPtrContent = getContent(srcPtr); + const dstPtr = new Pointer(dstContent.segment, dstContent.byteOffset + dstSize.dataByteLength + i * 8); + + // For composite lists the offset needs to point to the tag word, not the first element which is what getContent + // returns. + + if ( + getTargetPointerType(srcPtr) === PointerType.LIST && + getTargetListElementSize(srcPtr) === ListElementSize.COMPOSITE + ) { + srcPtrContent.byteOffset -= 8; + } + + const r = initPointer(srcPtrContent.segment, srcPtrContent.byteOffset, dstPtr); + + // Read the old pointer data, but discard the original offset. + + const a = srcPtrTarget.segment.getUint8(srcPtrTarget.byteOffset) & 0x03; + const b = srcPtrTarget.segment.getUint32(srcPtrTarget.byteOffset + 4); + + r.pointer.segment.setUint32(r.pointer.byteOffset, a | (r.offsetWords << 2)); + r.pointer.segment.setUint32(r.pointer.byteOffset + 4, b); + } + + // Zero out the old data and pointer sections. + + srcContent.segment.fillZeroWords(srcContent.byteOffset, getWordLength(srcSize)); +} + +export function adopt<T extends Struct>(src: Orphan<T>, s: Struct): void { + if (s._capnp.compositeIndex !== undefined) { + throw new Error(format(PTR_ADOPT_COMPOSITE_STRUCT, s)); + } + + Pointer.adopt(src, s); +} + +export function disown<T extends Struct>(s: Struct): Orphan<T> { + if (s._capnp.compositeIndex !== undefined) { + throw new Error(format(PTR_DISOWN_COMPOSITE_STRUCT, s)); + } + + return Pointer.disown(s); +} + +/** + * Convert a struct to a struct of the provided class. Particularly useful when casting to nested group types. + * + * @protected + * @template T + * @param {StructCtor<T>} StructClass The struct class to convert to. Not particularly useful if `Struct`. + * @param {Struct} s The struct to convert. + * @returns {T} A new instance of the desired struct class pointing to the same location. + */ + +export function getAs<T extends Struct>(StructClass: StructCtor<T>, s: Struct): T { + return new StructClass(s.segment, s.byteOffset, s._capnp.depthLimit, s._capnp.compositeIndex); +} + +/** + * Read a boolean (bit) value out of a struct. + * + * @protected + * @param {number} bitOffset The offset in **bits** from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {boolean} The value. + */ + +export function getBit(bitOffset: number, s: Struct, defaultMask?: DataView): boolean { + const byteOffset = Math.floor(bitOffset / 8); + const bitMask = 1 << bitOffset % 8; + + checkDataBounds(byteOffset, 1, s); + + const ds = getDataSection(s); + + const v = ds.segment.getUint8(ds.byteOffset + byteOffset); + + if (defaultMask === undefined) return (v & bitMask) !== 0; + + const defaultValue = defaultMask.getUint8(0); + return ((v ^ defaultValue) & bitMask) !== 0; +} + +export function getData(index: number, s: Struct, defaultValue?: Pointer): Data { + checkPointerBounds(index, s); + + const ps = getPointerSection(s); + + ps.byteOffset += index * 8; + + const l = new Data(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1); + + if (isNull(l)) { + if (defaultValue) { + Pointer.copyFrom(defaultValue, l); + } else { + List.initList(ListElementSize.BYTE, 0, l); + } + } + + return l; +} + +export function getDataSection(s: Struct): Pointer { + return getContent(s); +} + +/** + * Read a float32 value out of a struct. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ + +export function getFloat32(byteOffset: number, s: Struct, defaultMask?: DataView): number { + checkDataBounds(byteOffset, 4, s); + + const ds = getDataSection(s); + + if (defaultMask === undefined) { + return ds.segment.getFloat32(ds.byteOffset + byteOffset); + } + + const v = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true); + TMP_WORD.setUint32(0, v, NATIVE_LITTLE_ENDIAN); + return TMP_WORD.getFloat32(0, NATIVE_LITTLE_ENDIAN); +} + +/** + * Read a float64 value out of this segment. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ + +export function getFloat64(byteOffset: number, s: Struct, defaultMask?: DataView): number { + checkDataBounds(byteOffset, 8, s); + + const ds = getDataSection(s); + + if (defaultMask !== undefined) { + const lo = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true); + const hi = ds.segment.getUint32(ds.byteOffset + byteOffset + 4) ^ defaultMask.getUint32(4, true); + TMP_WORD.setUint32(0, lo, NATIVE_LITTLE_ENDIAN); + TMP_WORD.setUint32(4, hi, NATIVE_LITTLE_ENDIAN); + return TMP_WORD.getFloat64(0, NATIVE_LITTLE_ENDIAN); + } + + return ds.segment.getFloat64(ds.byteOffset + byteOffset); +} + +/** + * Read an int16 value out of this segment. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ + +export function getInt16(byteOffset: number, s: Struct, defaultMask?: DataView): number { + checkDataBounds(byteOffset, 2, s); + + const ds = getDataSection(s); + + if (defaultMask === undefined) { + return ds.segment.getInt16(ds.byteOffset + byteOffset); + } + + const v = ds.segment.getUint16(ds.byteOffset + byteOffset) ^ defaultMask.getUint16(0, true); + TMP_WORD.setUint16(0, v, NATIVE_LITTLE_ENDIAN); + return TMP_WORD.getInt16(0, NATIVE_LITTLE_ENDIAN); +} + +/** + * Read an int32 value out of this segment. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ + +export function getInt32(byteOffset: number, s: Struct, defaultMask?: DataView): number { + checkDataBounds(byteOffset, 4, s); + + const ds = getDataSection(s); + + if (defaultMask === undefined) { + return ds.segment.getInt32(ds.byteOffset + byteOffset); + } + + const v = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint16(0, true); + TMP_WORD.setUint32(0, v, NATIVE_LITTLE_ENDIAN); + return TMP_WORD.getInt32(0, NATIVE_LITTLE_ENDIAN); +} + +/** + * Read an int64 value out of this segment. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ + +export function getInt64(byteOffset: number, s: Struct, defaultMask?: DataView): Int64 { + checkDataBounds(byteOffset, 8, s); + + const ds = getDataSection(s); + + if (defaultMask === undefined) { + return ds.segment.getInt64(ds.byteOffset + byteOffset); + } + + const lo = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true); + const hi = ds.segment.getUint32(ds.byteOffset + byteOffset + 4) ^ defaultMask.getUint32(4, true); + TMP_WORD.setUint32(0, lo, NATIVE_LITTLE_ENDIAN); + TMP_WORD.setUint32(4, hi, NATIVE_LITTLE_ENDIAN); + return new Int64(new Uint8Array(TMP_WORD.buffer.slice(0))); +} + +/** + * Read an int8 value out of this segment. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ + +export function getInt8(byteOffset: number, s: Struct, defaultMask?: DataView): number { + checkDataBounds(byteOffset, 1, s); + + const ds = getDataSection(s); + + if (defaultMask === undefined) { + return ds.segment.getInt8(ds.byteOffset + byteOffset); + } + + const v = ds.segment.getUint8(ds.byteOffset + byteOffset) ^ defaultMask.getUint8(0); + TMP_WORD.setUint8(0, v); + return TMP_WORD.getInt8(0); +} + +export function getList<T>(index: number, ListClass: ListCtor<T>, s: Struct, defaultValue?: Pointer): List<T> { + checkPointerBounds(index, s); + + const ps = getPointerSection(s); + + ps.byteOffset += index * 8; + + const l = new ListClass(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1); + + if (isNull(l)) { + if (defaultValue) { + Pointer.copyFrom(defaultValue, l); + } else { + List.initList(ListClass._capnp.size, 0, l, ListClass._capnp.compositeSize); + } + } else if (ListClass._capnp.compositeSize !== undefined) { + // If this is a composite list we need to be sure the composite elements are big enough to hold everything as + // specified in the schema. If the new schema has added fields we'll need to "resize" (shallow-copy) the list so + // it has room for the new fields. + + const srcSize = getTargetCompositeListSize(l); + const dstSize = ListClass._capnp.compositeSize; + + if (dstSize.dataByteLength > srcSize.dataByteLength || dstSize.pointerLength > srcSize.pointerLength) { + const srcContent = getContent(l); + const srcLength = getTargetListLength(l); + + trace("resizing composite list %s due to protocol upgrade, new size: %d", l, getByteLength(dstSize) * srcLength); + + // Allocate an extra 8 bytes for the tag. + const dstContent = l.segment.allocate(getByteLength(dstSize) * srcLength + 8); + + const res = initPointer(dstContent.segment, dstContent.byteOffset, l); + + setListPointer(res.offsetWords, ListClass._capnp.size, srcLength, res.pointer, dstSize); + + // Write the new tag word. + + setStructPointer(srcLength, dstSize, dstContent); + + // Seek ahead past the tag word before copying the content. + dstContent.byteOffset += 8; + + for (let i = 0; i < srcLength; i++) { + const srcElementOffset = srcContent.byteOffset + i * getByteLength(srcSize); + const dstElementOffset = dstContent.byteOffset + i * getByteLength(dstSize); + + // Copy the data section. + + dstContent.segment.copyWords(dstElementOffset, srcContent.segment, srcElementOffset, getWordLength(srcSize)); + + // Iterate through the pointers and update the offsets so they point to the right place. + + for (let j = 0; j < srcSize.pointerLength; j++) { + const srcPtr = new Pointer(srcContent.segment, srcElementOffset + srcSize.dataByteLength + j * 8); + const dstPtr = new Pointer(dstContent.segment, dstElementOffset + dstSize.dataByteLength + j * 8); + + const srcPtrTarget = followFars(srcPtr); + const srcPtrContent = getContent(srcPtr); + + if ( + getTargetPointerType(srcPtr) === PointerType.LIST && + getTargetListElementSize(srcPtr) === ListElementSize.COMPOSITE + ) { + srcPtrContent.byteOffset -= 8; + } + + const r = initPointer(srcPtrContent.segment, srcPtrContent.byteOffset, dstPtr); + + // Read the old pointer data, but discard the original offset. + + const a = srcPtrTarget.segment.getUint8(srcPtrTarget.byteOffset) & 0x03; + const b = srcPtrTarget.segment.getUint32(srcPtrTarget.byteOffset + 4); + + r.pointer.segment.setUint32(r.pointer.byteOffset, a | (r.offsetWords << 2)); + r.pointer.segment.setUint32(r.pointer.byteOffset + 4, b); + } + } + + // Zero out the old content. + + srcContent.segment.fillZeroWords(srcContent.byteOffset, getWordLength(srcSize) * srcLength); + } + } + + return l; +} + +export function getPointer(index: number, s: Struct): Pointer { + checkPointerBounds(index, s); + + const ps = getPointerSection(s); + + ps.byteOffset += index * 8; + + return new Pointer(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1); +} + +export function getPointerAs<T extends Pointer>(index: number, PointerClass: PointerCtor<T>, s: Struct): T { + checkPointerBounds(index, s); + + const ps = getPointerSection(s); + + ps.byteOffset += index * 8; + + return new PointerClass(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1); +} + +export function getPointerSection(s: Struct): Pointer { + const ps = getContent(s); + + ps.byteOffset += padToWord(getSize(s).dataByteLength); + + return ps; +} + +export function getSize(s: Struct): ObjectSize { + if (s._capnp.compositeIndex !== undefined) { + // For composite lists the object size is stored in a tag word right before the content. + + const c = getContent(s, true); + + c.byteOffset -= 8; + + return getStructSize(c); + } + + return getTargetStructSize(s); +} + +export function getStruct<T extends Struct>( + index: number, + StructClass: StructCtor<T>, + s: Struct, + defaultValue?: Pointer +): T { + const t = getPointerAs(index, StructClass, s); + + if (isNull(t)) { + if (defaultValue) { + Pointer.copyFrom(defaultValue, t); + } else { + initStruct(StructClass._capnp.size, t); + } + } else { + validate(PointerType.STRUCT, t); + + const ts = getTargetStructSize(t); + + // This can happen when reading a struct that was constructed with an older version of the same schema, and new + // fields were added to the struct. A shallow copy of the struct will be made so that there's enough room for the + // data and pointer sections. This will unfortunately leave a "hole" of zeroes in the message, but that hole will + // at least compress well. + if ( + ts.dataByteLength < StructClass._capnp.size.dataByteLength || + ts.pointerLength < StructClass._capnp.size.pointerLength + ) { + trace("need to resize child struct %s", t); + + resize(StructClass._capnp.size, t); + } + } + + return t; +} + +export function getText(index: number, s: Struct, defaultValue?: string): string { + const t = Text.fromPointer(getPointer(index, s)); + + // FIXME: This will perform an unnecessary string<>ArrayBuffer roundtrip. + if (isNull(t) && defaultValue) t.set(0, defaultValue); + + return t.get(0); +} + +/** + * Read an uint16 value out of a struct.. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ + +export function getUint16(byteOffset: number, s: Struct, defaultMask?: DataView): number { + checkDataBounds(byteOffset, 2, s); + + const ds = getDataSection(s); + + if (defaultMask === undefined) { + return ds.segment.getUint16(ds.byteOffset + byteOffset); + } + + return ds.segment.getUint16(ds.byteOffset + byteOffset) ^ defaultMask.getUint16(0, true); +} + +/** + * Read an uint32 value out of a struct. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ + +export function getUint32(byteOffset: number, s: Struct, defaultMask?: DataView): number { + checkDataBounds(byteOffset, 4, s); + + const ds = getDataSection(s); + + if (defaultMask === undefined) { + return ds.segment.getUint32(ds.byteOffset + byteOffset); + } + + return ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true); +} + +/** + * Read an uint64 value out of a struct. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ + +export function getUint64(byteOffset: number, s: Struct, defaultMask?: DataView): Uint64 { + checkDataBounds(byteOffset, 8, s); + + const ds = getDataSection(s); + + if (defaultMask === undefined) { + return ds.segment.getUint64(ds.byteOffset + byteOffset); + } + + const lo = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true); + const hi = ds.segment.getUint32(ds.byteOffset + byteOffset + 4) ^ defaultMask.getUint32(4, true); + TMP_WORD.setUint32(0, lo, NATIVE_LITTLE_ENDIAN); + TMP_WORD.setUint32(4, hi, NATIVE_LITTLE_ENDIAN); + return new Uint64(new Uint8Array(TMP_WORD.buffer.slice(0))); +} + +/** + * Read an uint8 value out of a struct. + * + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {Struct} s The struct to read from. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {number} The value. + */ + +export function getUint8(byteOffset: number, s: Struct, defaultMask?: DataView): number { + checkDataBounds(byteOffset, 1, s); + + const ds = getDataSection(s); + + if (defaultMask === undefined) { + return ds.segment.getUint8(ds.byteOffset + byteOffset); + } + + return ds.segment.getUint8(ds.byteOffset + byteOffset) ^ defaultMask.getUint8(0); +} + +export function getVoid(): void { + throw new Error(INVARIANT_UNREACHABLE_CODE); +} + +export function initData(index: number, length: number, s: Struct): Data { + checkPointerBounds(index, s); + + const ps = getPointerSection(s); + + ps.byteOffset += index * 8; + + const l = new Data(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1); + + erase(l); + + List.initList(ListElementSize.BYTE, length, l); + + return l; +} + +export function initList<T>(index: number, ListClass: ListCtor<T>, length: number, s: Struct): List<T> { + checkPointerBounds(index, s); + + const ps = getPointerSection(s); + + ps.byteOffset += index * 8; + + const l = new ListClass(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1); + + erase(l); + + List.initList(ListClass._capnp.size, length, l, ListClass._capnp.compositeSize); + + return l; +} + +/** + * Write a boolean (bit) value to the struct. + * + * @protected + * @param {number} bitOffset The offset in **bits** from the start of the data section. + * @param {boolean} value The value to write (writes a 0 for `false`, 1 for `true`). + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ + +export function setBit(bitOffset: number, value: boolean, s: Struct, defaultMask?: DataView): void { + const byteOffset = Math.floor(bitOffset / 8); + const bitMask = 1 << bitOffset % 8; + + checkDataBounds(byteOffset, 1, s); + + const ds = getDataSection(s); + + const b = ds.segment.getUint8(ds.byteOffset + byteOffset); + + // If the default mask bit is set, that means `true` values are actually written as `0`. + + if (defaultMask !== undefined) { + value = (defaultMask.getUint8(0) & bitMask) !== 0 ? !value : value; + } + + ds.segment.setUint8(ds.byteOffset + byteOffset, value ? b | bitMask : b & ~bitMask); +} + +/** + * Write a primitive float32 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ + +export function setFloat32(byteOffset: number, value: number, s: Struct, defaultMask?: DataView): void { + checkDataBounds(byteOffset, 4, s); + + const ds = getDataSection(s); + + if (defaultMask !== undefined) { + TMP_WORD.setFloat32(0, value, NATIVE_LITTLE_ENDIAN); + const v = TMP_WORD.getUint32(0, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(0, true); + ds.segment.setUint32(ds.byteOffset + byteOffset, v); + + return; + } + + ds.segment.setFloat32(ds.byteOffset + byteOffset, value); +} + +/** + * Write a primitive float64 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ + +export function setFloat64(byteOffset: number, value: number, s: Struct, defaultMask?: DataView): void { + checkDataBounds(byteOffset, 8, s); + + const ds = getDataSection(s); + + if (defaultMask !== undefined) { + TMP_WORD.setFloat64(0, value, NATIVE_LITTLE_ENDIAN); + const lo = TMP_WORD.getUint32(0, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(0, true); + const hi = TMP_WORD.getUint32(4, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(4, true); + ds.segment.setUint32(ds.byteOffset + byteOffset, lo); + ds.segment.setUint32(ds.byteOffset + byteOffset + 4, hi); + + return; + } + + ds.segment.setFloat64(ds.byteOffset + byteOffset, value); +} + +/** + * Write a primitive int16 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ + +export function setInt16(byteOffset: number, value: number, s: Struct, defaultMask?: DataView): void { + checkDataBounds(byteOffset, 2, s); + + const ds = getDataSection(s); + + if (defaultMask !== undefined) { + TMP_WORD.setInt16(0, value, NATIVE_LITTLE_ENDIAN); + const v = TMP_WORD.getUint16(0, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint16(0, true); + ds.segment.setUint16(ds.byteOffset + byteOffset, v); + + return; + } + + ds.segment.setInt16(ds.byteOffset + byteOffset, value); +} + +/** + * Write a primitive int32 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ + +export function setInt32(byteOffset: number, value: number, s: Struct, defaultMask?: DataView): void { + checkDataBounds(byteOffset, 4, s); + + const ds = getDataSection(s); + + if (defaultMask !== undefined) { + TMP_WORD.setInt32(0, value, NATIVE_LITTLE_ENDIAN); + const v = TMP_WORD.getUint32(0, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(0, true); + ds.segment.setUint32(ds.byteOffset + byteOffset, v); + + return; + } + + ds.segment.setInt32(ds.byteOffset + byteOffset, value); +} + +/** + * Write a primitive int64 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ + +export function setInt64(byteOffset: number, value: Int64, s: Struct, defaultMask?: DataView): void { + checkDataBounds(byteOffset, 8, s); + + const ds = getDataSection(s); + + if (defaultMask !== undefined) { + // PERF: We could cast the Int64 to a DataView to apply the mask using four 32-bit reads, but we already have a + // typed array so avoiding the object allocation turns out to be slightly faster. Int64 is guaranteed to be in + // little-endian format by design. + + for (let i = 0; i < 8; i++) { + ds.segment.setUint8(ds.byteOffset + byteOffset + i, value.buffer[i] ^ defaultMask.getUint8(i)); + } + + return; + } + + ds.segment.setInt64(ds.byteOffset + byteOffset, value); +} + +/** + * Write a primitive int8 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ + +export function setInt8(byteOffset: number, value: number, s: Struct, defaultMask?: DataView): void { + checkDataBounds(byteOffset, 1, s); + + const ds = getDataSection(s); + + if (defaultMask !== undefined) { + TMP_WORD.setInt8(0, value); + const v = TMP_WORD.getUint8(0) ^ defaultMask.getUint8(0); + ds.segment.setUint8(ds.byteOffset + byteOffset, v); + + return; + } + + ds.segment.setInt8(ds.byteOffset + byteOffset, value); +} + +export function setPointer(index: number, value: Pointer, s: Struct): void { + copyFrom(value, getPointer(index, s)); +} + +export function setText(index: number, value: string, s: Struct): void { + Text.fromPointer(getPointer(index, s)).set(0, value); +} + +/** + * Write a primitive uint16 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ + +export function setUint16(byteOffset: number, value: number, s: Struct, defaultMask?: DataView): void { + checkDataBounds(byteOffset, 2, s); + + const ds = getDataSection(s); + + if (defaultMask !== undefined) value ^= defaultMask.getUint16(0, true); + + ds.segment.setUint16(ds.byteOffset + byteOffset, value); +} + +/** + * Write a primitive uint32 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ + +export function setUint32(byteOffset: number, value: number, s: Struct, defaultMask?: DataView): void { + checkDataBounds(byteOffset, 4, s); + + const ds = getDataSection(s); + + if (defaultMask !== undefined) value ^= defaultMask.getUint32(0, true); + + ds.segment.setUint32(ds.byteOffset + byteOffset, value); +} + +/** + * Write a primitive uint64 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ + +export function setUint64(byteOffset: number, value: Uint64, s: Struct, defaultMask?: DataView): void { + checkDataBounds(byteOffset, 8, s); + + const ds = getDataSection(s); + + if (defaultMask !== undefined) { + // PERF: We could cast the Uint64 to a DataView to apply the mask using four 32-bit reads, but we already have a + // typed array so avoiding the object allocation turns out to be slightly faster. Uint64 is guaranteed to be in + // little-endian format by design. + + for (let i = 0; i < 8; i++) { + ds.segment.setUint8(ds.byteOffset + byteOffset + i, value.buffer[i] ^ defaultMask.getUint8(i)); + } + + return; + } + + ds.segment.setUint64(ds.byteOffset + byteOffset, value); +} + +/** + * Write a primitive uint8 value to the struct. + * + * @protected + * @param {number} byteOffset The offset in bytes from the start of the data section. + * @param {number} value The value to write. + * @param {Struct} s The struct to write to. + * @param {DataView} [defaultMask] The default value as a DataView. + * @returns {void} + */ + +export function setUint8(byteOffset: number, value: number, s: Struct, defaultMask?: DataView): void { + checkDataBounds(byteOffset, 1, s); + + const ds = getDataSection(s); + + if (defaultMask !== undefined) value ^= defaultMask.getUint8(0); + + ds.segment.setUint8(ds.byteOffset + byteOffset, value); +} + +export function setVoid(): void { + throw new Error(INVARIANT_UNREACHABLE_CODE); +} + +export function testWhich(name: string, found: number, wanted: number, s: Struct): void { + if (found !== wanted) { + throw new Error(format(PTR_INVALID_UNION_ACCESS, s, name, found, wanted)); + } +} + +export function checkDataBounds(byteOffset: number, byteLength: number, s: Struct): void { + const dataByteLength = getSize(s).dataByteLength; + + if (byteOffset < 0 || byteLength < 0 || byteOffset + byteLength > dataByteLength) { + throw new Error(format(PTR_STRUCT_DATA_OUT_OF_BOUNDS, s, byteLength, byteOffset, dataByteLength)); + } +} + +export function checkPointerBounds(index: number, s: Struct): void { + const pointerLength = getSize(s).pointerLength; + + if (index < 0 || index >= pointerLength) { + throw new Error(format(PTR_STRUCT_POINTER_OUT_OF_BOUNDS, s, index, pointerLength)); + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/text-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/text-list.d.ts new file mode 100644 index 0000000..bd4c8bb --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/text-list.d.ts @@ -0,0 +1,10 @@ +/** + * @author jdiaz5513 + */ +import { _ListCtor, List } from "./list"; +export declare class TextList extends List<string> { + static readonly _capnp: _ListCtor; + get(index: number): string; + set(index: number, value: string): void; + toString(): string; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/text-list.js b/node_modules/capnp-ts/src/serialization/pointers/text-list.js new file mode 100644 index 0000000..0005b0c --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/text-list.js @@ -0,0 +1,35 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.TextList = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const list_element_size_1 = require("../list-element-size"); +const list_1 = require("./list"); +const text_1 = require("./text"); +const pointer_1 = require("./pointer"); +const trace = debug_1.default("capnp:list:composite"); +trace("load"); +class TextList extends list_1.List { + get(index) { + const c = pointer_1.getContent(this); + c.byteOffset += index * 8; + return text_1.Text.fromPointer(c).get(0); + } + set(index, value) { + const c = pointer_1.getContent(this); + c.byteOffset += index * 8; + text_1.Text.fromPointer(c).set(0, value); + } + toString() { + return `Text_${super.toString()}`; + } +} +exports.TextList = TextList; +TextList._capnp = { + displayName: "List<Text>", + size: list_element_size_1.ListElementSize.POINTER +}; +//# sourceMappingURL=text-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/text-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/text-list.js.map new file mode 100644 index 0000000..7c9c627 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/text-list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"text-list.js","sourceRoot":"","sources":["text-list.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,4DAAuD;AACvD,iCAAyC;AACzC,iCAA8B;AAC9B,uCAAuC;AAEvC,MAAM,KAAK,GAAG,eAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,QAAS,SAAQ,WAAY;IAMxC,GAAG,CAAC,KAAa;QACf,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAE3B,CAAC,CAAC,UAAU,IAAI,KAAK,GAAG,CAAC,CAAC;QAE1B,OAAO,WAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACpC,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,KAAa;QAC9B,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAE3B,CAAC,CAAC,UAAU,IAAI,KAAK,GAAG,CAAC,CAAC;QAE1B,WAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,QAAQ;QACN,OAAO,QAAQ,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;IACpC,CAAC;;AAxBH,4BAyBC;AAxBiB,eAAM,GAAc;IAClC,WAAW,EAAE,YAAsB;IACnC,IAAI,EAAE,mCAAe,CAAC,OAAO;CAC9B,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/text-list.ts b/node_modules/capnp-ts/src/serialization/pointers/text-list.ts new file mode 100644 index 0000000..0c2c8fd --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/text-list.ts @@ -0,0 +1,40 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { ListElementSize } from "../list-element-size"; +import { _ListCtor, List } from "./list"; +import { Text } from "./text"; +import { getContent } from "./pointer"; + +const trace = initTrace("capnp:list:composite"); +trace("load"); + +export class TextList extends List<string> { + static readonly _capnp: _ListCtor = { + displayName: "List<Text>" as string, + size: ListElementSize.POINTER + }; + + get(index: number): string { + const c = getContent(this); + + c.byteOffset += index * 8; + + return Text.fromPointer(c).get(0); + } + + set(index: number, value: string): void { + const c = getContent(this); + + c.byteOffset += index * 8; + + Text.fromPointer(c).set(0, value); + } + + toString(): string { + return `Text_${super.toString()}`; + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/text.d.ts b/node_modules/capnp-ts/src/serialization/pointers/text.d.ts new file mode 100644 index 0000000..bbbaa7d --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/text.d.ts @@ -0,0 +1,31 @@ +/** + * @author jdiaz5513 + */ +import { List } from "./list"; +import { Pointer } from "./pointer"; +export declare class Text extends List<string> { + static fromPointer(pointer: Pointer): Text; + /** + * Read a utf-8 encoded string value from this pointer. + * + * @param {number} [index] The index at which to start reading; defaults to zero. + * @returns {string} The string value. + */ + get(index?: number): string; + /** + * Get the number of utf-8 encoded bytes in this text. This does **not** include the NUL byte. + * + * @returns {number} The number of bytes allocated for the text. + */ + getLength(): number; + /** + * Write a utf-8 encoded string value starting at the specified index. + * + * @param {number} index The index at which to start copying the string. Note that if this is not zero the bytes + * before `index` will be left as-is. All bytes after `index` will be overwritten. + * @param {string} value The string value to set. + * @returns {void} + */ + set(index: number, value: string): void; + toString(): string; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/text.js b/node_modules/capnp-ts/src/serialization/pointers/text.js new file mode 100644 index 0000000..e4de308 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/text.js @@ -0,0 +1,91 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Text = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const util_1 = require("../../util"); +const list_element_size_1 = require("../list-element-size"); +const list_1 = require("./list"); +const pointer_1 = require("./pointer"); +const pointer_type_1 = require("./pointer-type"); +const trace = debug_1.default("capnp:text"); +trace("load"); +class Text extends list_1.List { + static fromPointer(pointer) { + pointer_1.validate(pointer_type_1.PointerType.LIST, pointer, list_element_size_1.ListElementSize.BYTE); + return textFromPointerUnchecked(pointer); + } + /** + * Read a utf-8 encoded string value from this pointer. + * + * @param {number} [index] The index at which to start reading; defaults to zero. + * @returns {string} The string value. + */ + get(index = 0) { + if (index !== 0) { + trace("Called get() on %s with a strange index (%d).", this, index); + } + if (pointer_1.isNull(this)) + return ""; + const c = pointer_1.getContent(this); + // Remember to exclude the NUL byte. + return util_1.decodeUtf8(new Uint8Array(c.segment.buffer, c.byteOffset + index, this.getLength() - index)); + } + /** + * Get the number of utf-8 encoded bytes in this text. This does **not** include the NUL byte. + * + * @returns {number} The number of bytes allocated for the text. + */ + getLength() { + return super.getLength() - 1; + } + /** + * Write a utf-8 encoded string value starting at the specified index. + * + * @param {number} index The index at which to start copying the string. Note that if this is not zero the bytes + * before `index` will be left as-is. All bytes after `index` will be overwritten. + * @param {string} value The string value to set. + * @returns {void} + */ + set(index, value) { + if (index !== 0) { + trace("Called set() on %s with a strange index (%d).", this, index); + } + const src = util_1.encodeUtf8(value); + const dstLength = src.byteLength + index; + let c; + let original; + // TODO: Consider reusing existing space if list is already initialized and there's enough room for the value. + if (!pointer_1.isNull(this)) { + c = pointer_1.getContent(this); + // Only copy bytes that will remain after copying. Everything after `index` should end up truncated. + let originalLength = this.getLength(); + if (originalLength >= index) { + originalLength = index; + } + else { + trace("%d byte gap exists between original text and new text in %s.", index - originalLength, this); + } + original = new Uint8Array(c.segment.buffer.slice(c.byteOffset, c.byteOffset + Math.min(originalLength, index))); + pointer_1.erase(this); + } + // Always allocate an extra byte for the NUL byte. + list_1.initList(list_element_size_1.ListElementSize.BYTE, dstLength + 1, this); + c = pointer_1.getContent(this); + const dst = new Uint8Array(c.segment.buffer, c.byteOffset, dstLength); + if (original) + dst.set(original); + dst.set(src, index); + } + toString() { + return `Text_${super.toString()}`; + } +} +exports.Text = Text; +function textFromPointerUnchecked(pointer) { + return new Text(pointer.segment, pointer.byteOffset, pointer._capnp.depthLimit); +} +//# sourceMappingURL=text.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/text.js.map b/node_modules/capnp-ts/src/serialization/pointers/text.js.map new file mode 100644 index 0000000..4cd6d29 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/text.js.map @@ -0,0 +1 @@ +{"version":3,"file":"text.js","sourceRoot":"","sources":["text.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,qCAAoD;AACpD,4DAAuD;AACvD,iCAAwC;AACxC,uCAAyE;AACzE,iDAA6C;AAE7C,MAAM,KAAK,GAAG,eAAS,CAAC,YAAY,CAAC,CAAC;AACtC,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,IAAK,SAAQ,WAAY;IACpC,MAAM,CAAC,WAAW,CAAC,OAAgB;QACjC,kBAAQ,CAAC,0BAAW,CAAC,IAAI,EAAE,OAAO,EAAE,mCAAe,CAAC,IAAI,CAAC,CAAC;QAE1D,OAAO,wBAAwB,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;OAKG;IAEH,GAAG,CAAC,KAAK,GAAG,CAAC;QACX,IAAI,KAAK,KAAK,CAAC,EAAE;YACf,KAAK,CAAC,+CAA+C,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;SACrE;QAED,IAAI,gBAAM,CAAC,IAAI,CAAC;YAAE,OAAO,EAAE,CAAC;QAE5B,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAE3B,oCAAoC;QAEpC,OAAO,iBAAU,C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C,EAAE,IAAI,CAAC,CAAC;QAEpD,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QACrB,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QAEtE,IAAI,QAAQ;YAAE,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAEhC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACtB,CAAC;IAED,QAAQ;QACN,OAAO,QAAQ,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;IACpC,CAAC;CACF;AA3GD,oBA2GC;AAED,SAAS,wBAAwB,CAAC,OAAgB;IAChD,OAAO,IAAI,IAAI,CACb,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,MAAM,CAAC,UAAU,CAC1B,CAAC;AACJ,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/text.ts b/node_modules/capnp-ts/src/serialization/pointers/text.ts new file mode 100644 index 0000000..2804097 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/text.ts @@ -0,0 +1,131 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { decodeUtf8, encodeUtf8 } from "../../util"; +import { ListElementSize } from "../list-element-size"; +import { List, initList } from "./list"; +import { Pointer, validate, isNull, getContent, erase } from "./pointer"; +import { PointerType } from "./pointer-type"; + +const trace = initTrace("capnp:text"); +trace("load"); + +export class Text extends List<string> { + static fromPointer(pointer: Pointer): Text { + validate(PointerType.LIST, pointer, ListElementSize.BYTE); + + return textFromPointerUnchecked(pointer); + } + + /** + * Read a utf-8 encoded string value from this pointer. + * + * @param {number} [index] The index at which to start reading; defaults to zero. + * @returns {string} The string value. + */ + + get(index = 0): string { + if (index !== 0) { + trace("Called get() on %s with a strange index (%d).", this, index); + } + + if (isNull(this)) return ""; + + const c = getContent(this); + + // Remember to exclude the NUL byte. + + return decodeUtf8( + new Uint8Array( + c.segment.buffer, + c.byteOffset + index, + this.getLength() - index + ) + ); + } + + /** + * Get the number of utf-8 encoded bytes in this text. This does **not** include the NUL byte. + * + * @returns {number} The number of bytes allocated for the text. + */ + + getLength(): number { + return super.getLength() - 1; + } + + /** + * Write a utf-8 encoded string value starting at the specified index. + * + * @param {number} index The index at which to start copying the string. Note that if this is not zero the bytes + * before `index` will be left as-is. All bytes after `index` will be overwritten. + * @param {string} value The string value to set. + * @returns {void} + */ + + set(index: number, value: string): void { + if (index !== 0) { + trace("Called set() on %s with a strange index (%d).", this, index); + } + + const src = encodeUtf8(value); + const dstLength = src.byteLength + index; + let c: Pointer; + let original: Uint8Array | undefined; + + // TODO: Consider reusing existing space if list is already initialized and there's enough room for the value. + + if (!isNull(this)) { + c = getContent(this); + + // Only copy bytes that will remain after copying. Everything after `index` should end up truncated. + + let originalLength = this.getLength(); + + if (originalLength >= index) { + originalLength = index; + } else { + trace( + "%d byte gap exists between original text and new text in %s.", + index - originalLength, + this + ); + } + + original = new Uint8Array( + c.segment.buffer.slice( + c.byteOffset, + c.byteOffset + Math.min(originalLength, index) + ) + ); + + erase(this); + } + + // Always allocate an extra byte for the NUL byte. + + initList(ListElementSize.BYTE, dstLength + 1, this); + + c = getContent(this); + const dst = new Uint8Array(c.segment.buffer, c.byteOffset, dstLength); + + if (original) dst.set(original); + + dst.set(src, index); + } + + toString(): string { + return `Text_${super.toString()}`; + } +} + +function textFromPointerUnchecked(pointer: Pointer): Text { + return new Text( + pointer.segment, + pointer.byteOffset, + pointer._capnp.depthLimit + ); +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/uint16-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/uint16-list.d.ts new file mode 100644 index 0000000..02df3da --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/uint16-list.d.ts @@ -0,0 +1,10 @@ +/** + * @author jdiaz5513 + */ +import { _ListCtor, List } from "./list"; +export declare class Uint16List extends List<number> { + static readonly _capnp: _ListCtor; + get(index: number): number; + set(index: number, value: number): void; + toString(): string; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/uint16-list.js b/node_modules/capnp-ts/src/serialization/pointers/uint16-list.js new file mode 100644 index 0000000..e6ca94e --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/uint16-list.js @@ -0,0 +1,32 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Uint16List = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const list_element_size_1 = require("../list-element-size"); +const list_1 = require("./list"); +const pointer_1 = require("./pointer"); +const trace = debug_1.default("capnp:list:composite"); +trace("load"); +class Uint16List extends list_1.List { + get(index) { + const c = pointer_1.getContent(this); + return c.segment.getUint16(c.byteOffset + index * 2); + } + set(index, value) { + const c = pointer_1.getContent(this); + c.segment.setUint16(c.byteOffset + index * 2, value); + } + toString() { + return `Uint16_${super.toString()}`; + } +} +exports.Uint16List = Uint16List; +Uint16List._capnp = { + displayName: "List<Uint16>", + size: list_element_size_1.ListElementSize.BYTE_2 +}; +//# sourceMappingURL=uint16-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/uint16-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/uint16-list.js.map new file mode 100644 index 0000000..e9c8dce --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/uint16-list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"uint16-list.js","sourceRoot":"","sources":["uint16-list.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,4DAAuD;AACvD,iCAAyC;AACzC,uCAAuC;AAEvC,MAAM,KAAK,GAAG,eAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,UAAW,SAAQ,WAAY;IAM1C,GAAG,CAAC,KAAa;QACf,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;IACvD,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,KAAa;QAC9B,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAE3B,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IACvD,CAAC;IAED,QAAQ;QACN,OAAO,UAAU,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;IACtC,CAAC;;AAnBH,gCAoBC;AAnBiB,iBAAM,GAAc;IAClC,WAAW,EAAE,cAAc;IAC3B,IAAI,EAAE,mCAAe,CAAC,MAAM;CAC7B,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/uint16-list.ts b/node_modules/capnp-ts/src/serialization/pointers/uint16-list.ts new file mode 100644 index 0000000..64741f0 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/uint16-list.ts @@ -0,0 +1,34 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { ListElementSize } from "../list-element-size"; +import { _ListCtor, List } from "./list"; +import { getContent } from "./pointer"; + +const trace = initTrace("capnp:list:composite"); +trace("load"); + +export class Uint16List extends List<number> { + static readonly _capnp: _ListCtor = { + displayName: "List<Uint16>", + size: ListElementSize.BYTE_2 + }; + + get(index: number): number { + const c = getContent(this); + return c.segment.getUint16(c.byteOffset + index * 2); + } + + set(index: number, value: number): void { + const c = getContent(this); + + c.segment.setUint16(c.byteOffset + index * 2, value); + } + + toString(): string { + return `Uint16_${super.toString()}`; + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/uint32-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/uint32-list.d.ts new file mode 100644 index 0000000..245b4aa --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/uint32-list.d.ts @@ -0,0 +1,10 @@ +/** + * @author jdiaz5513 + */ +import { _ListCtor, List } from "./list"; +export declare class Uint32List extends List<number> { + static readonly _capnp: _ListCtor; + get(index: number): number; + set(index: number, value: number): void; + toString(): string; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/uint32-list.js b/node_modules/capnp-ts/src/serialization/pointers/uint32-list.js new file mode 100644 index 0000000..7ef3a02 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/uint32-list.js @@ -0,0 +1,32 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Uint32List = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const list_element_size_1 = require("../list-element-size"); +const list_1 = require("./list"); +const pointer_1 = require("./pointer"); +const trace = debug_1.default("capnp:list:composite"); +trace("load"); +class Uint32List extends list_1.List { + get(index) { + const c = pointer_1.getContent(this); + return c.segment.getUint32(c.byteOffset + index * 4); + } + set(index, value) { + const c = pointer_1.getContent(this); + c.segment.setUint32(c.byteOffset + index * 4, value); + } + toString() { + return `Uint32_${super.toString()}`; + } +} +exports.Uint32List = Uint32List; +Uint32List._capnp = { + displayName: "List<Uint32>", + size: list_element_size_1.ListElementSize.BYTE_4 +}; +//# sourceMappingURL=uint32-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/uint32-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/uint32-list.js.map new file mode 100644 index 0000000..241593f --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/uint32-list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"uint32-list.js","sourceRoot":"","sources":["uint32-list.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,4DAAuD;AACvD,iCAAyC;AACzC,uCAAuC;AAEvC,MAAM,KAAK,GAAG,eAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,UAAW,SAAQ,WAAY;IAM1C,GAAG,CAAC,KAAa;QACf,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;IACvD,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,KAAa;QAC9B,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IACvD,CAAC;IAED,QAAQ;QACN,OAAO,UAAU,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;IACtC,CAAC;;AAlBH,gCAmBC;AAlBiB,iBAAM,GAAc;IAClC,WAAW,EAAE,cAAwB;IACrC,IAAI,EAAE,mCAAe,CAAC,MAAM;CAC7B,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/uint32-list.ts b/node_modules/capnp-ts/src/serialization/pointers/uint32-list.ts new file mode 100644 index 0000000..2a6eafc --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/uint32-list.ts @@ -0,0 +1,33 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { ListElementSize } from "../list-element-size"; +import { _ListCtor, List } from "./list"; +import { getContent } from "./pointer"; + +const trace = initTrace("capnp:list:composite"); +trace("load"); + +export class Uint32List extends List<number> { + static readonly _capnp: _ListCtor = { + displayName: "List<Uint32>" as string, + size: ListElementSize.BYTE_4 + }; + + get(index: number): number { + const c = getContent(this); + return c.segment.getUint32(c.byteOffset + index * 4); + } + + set(index: number, value: number): void { + const c = getContent(this); + c.segment.setUint32(c.byteOffset + index * 4, value); + } + + toString(): string { + return `Uint32_${super.toString()}`; + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/uint64-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/uint64-list.d.ts new file mode 100644 index 0000000..467e08d --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/uint64-list.d.ts @@ -0,0 +1,11 @@ +/** + * @author jdiaz5513 + */ +import { Uint64 } from "../../types/index"; +import { _ListCtor, List } from "./list"; +export declare class Uint64List extends List<Uint64> { + static readonly _capnp: _ListCtor; + get(index: number): Uint64; + set(index: number, value: Uint64): void; + toString(): string; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/uint64-list.js b/node_modules/capnp-ts/src/serialization/pointers/uint64-list.js new file mode 100644 index 0000000..0e49e01 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/uint64-list.js @@ -0,0 +1,32 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Uint64List = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const list_element_size_1 = require("../list-element-size"); +const list_1 = require("./list"); +const pointer_1 = require("./pointer"); +const trace = debug_1.default("capnp:list:composite"); +trace("load"); +class Uint64List extends list_1.List { + get(index) { + const c = pointer_1.getContent(this); + return c.segment.getUint64(c.byteOffset + index * 8); + } + set(index, value) { + const c = pointer_1.getContent(this); + c.segment.setUint64(c.byteOffset + index * 8, value); + } + toString() { + return `Uint64_${super.toString()}`; + } +} +exports.Uint64List = Uint64List; +Uint64List._capnp = { + displayName: "List<Uint64>", + size: list_element_size_1.ListElementSize.BYTE_8, +}; +//# sourceMappingURL=uint64-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/uint64-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/uint64-list.js.map new file mode 100644 index 0000000..b5b0102 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/uint64-list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"uint64-list.js","sourceRoot":"","sources":["uint64-list.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAG9B,4DAAuD;AACvD,iCAAyC;AACzC,uCAAuC;AAEvC,MAAM,KAAK,GAAG,eAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,UAAW,SAAQ,WAAY;IAM1C,GAAG,CAAC,KAAa;QACf,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;IACvD,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,KAAa;QAC9B,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IACvD,CAAC;IAED,QAAQ;QACN,OAAO,UAAU,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;IACtC,CAAC;;AAlBH,gCAmBC;AAlBiB,iBAAM,GAAc;IAClC,WAAW,EAAE,cAAwB;IACrC,IAAI,EAAE,mCAAe,CAAC,MAAM;CAC7B,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/uint64-list.ts b/node_modules/capnp-ts/src/serialization/pointers/uint64-list.ts new file mode 100644 index 0000000..d46a6cb --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/uint64-list.ts @@ -0,0 +1,34 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { Uint64 } from "../../types/index"; +import { ListElementSize } from "../list-element-size"; +import { _ListCtor, List } from "./list"; +import { getContent } from "./pointer"; + +const trace = initTrace("capnp:list:composite"); +trace("load"); + +export class Uint64List extends List<Uint64> { + static readonly _capnp: _ListCtor = { + displayName: "List<Uint64>" as string, + size: ListElementSize.BYTE_8, + }; + + get(index: number): Uint64 { + const c = getContent(this); + return c.segment.getUint64(c.byteOffset + index * 8); + } + + set(index: number, value: Uint64): void { + const c = getContent(this); + c.segment.setUint64(c.byteOffset + index * 8, value); + } + + toString(): string { + return `Uint64_${super.toString()}`; + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/uint8-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/uint8-list.d.ts new file mode 100644 index 0000000..3383f88 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/uint8-list.d.ts @@ -0,0 +1,10 @@ +/** + * @author jdiaz5513 + */ +import { _ListCtor, List } from "./list"; +export declare class Uint8List extends List<number> { + static readonly _capnp: _ListCtor; + get(index: number): number; + set(index: number, value: number): void; + toString(): string; +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/uint8-list.js b/node_modules/capnp-ts/src/serialization/pointers/uint8-list.js new file mode 100644 index 0000000..2387ad6 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/uint8-list.js @@ -0,0 +1,32 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Uint8List = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const list_element_size_1 = require("../list-element-size"); +const list_1 = require("./list"); +const pointer_1 = require("./pointer"); +const trace = debug_1.default("capnp:list:composite"); +trace("load"); +class Uint8List extends list_1.List { + get(index) { + const c = pointer_1.getContent(this); + return c.segment.getUint8(c.byteOffset + index); + } + set(index, value) { + const c = pointer_1.getContent(this); + c.segment.setUint8(c.byteOffset + index, value); + } + toString() { + return `Uint8_${super.toString()}`; + } +} +exports.Uint8List = Uint8List; +Uint8List._capnp = { + displayName: "List<Uint8>", + size: list_element_size_1.ListElementSize.BYTE +}; +//# sourceMappingURL=uint8-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/uint8-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/uint8-list.js.map new file mode 100644 index 0000000..aced68e --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/uint8-list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"uint8-list.js","sourceRoot":"","sources":["uint8-list.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,4DAAuD;AACvD,iCAAyC;AACzC,uCAAuC;AAEvC,MAAM,KAAK,GAAG,eAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,SAAU,SAAQ,WAAY;IAMzC,GAAG,CAAC,KAAa;QACf,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,CAAC,CAAC;IAClD,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,KAAa;QAC9B,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC;IAED,QAAQ;QACN,OAAO,SAAS,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;IACrC,CAAC;;AAlBH,8BAmBC;AAlBiB,gBAAM,GAAc;IAClC,WAAW,EAAE,aAAuB;IACpC,IAAI,EAAE,mCAAe,CAAC,IAAI;CAC3B,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/uint8-list.ts b/node_modules/capnp-ts/src/serialization/pointers/uint8-list.ts new file mode 100644 index 0000000..524fd9d --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/uint8-list.ts @@ -0,0 +1,33 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { ListElementSize } from "../list-element-size"; +import { _ListCtor, List } from "./list"; +import { getContent } from "./pointer"; + +const trace = initTrace("capnp:list:composite"); +trace("load"); + +export class Uint8List extends List<number> { + static readonly _capnp: _ListCtor = { + displayName: "List<Uint8>" as string, + size: ListElementSize.BYTE + }; + + get(index: number): number { + const c = getContent(this); + return c.segment.getUint8(c.byteOffset + index); + } + + set(index: number, value: number): void { + const c = getContent(this); + c.segment.setUint8(c.byteOffset + index, value); + } + + toString(): string { + return `Uint8_${super.toString()}`; + } +} diff --git a/node_modules/capnp-ts/src/serialization/pointers/void-list.d.ts b/node_modules/capnp-ts/src/serialization/pointers/void-list.d.ts new file mode 100644 index 0000000..50392a0 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/void-list.d.ts @@ -0,0 +1,8 @@ +/** + * Why would anyone **SANE** ever use this!? + * + * @author jdiaz5513 + */ +import { ListCtor } from "./list"; +import { Void } from "./void"; +export declare const VoidList: ListCtor<Void>; diff --git a/node_modules/capnp-ts/src/serialization/pointers/void-list.js b/node_modules/capnp-ts/src/serialization/pointers/void-list.js new file mode 100644 index 0000000..68a75d3 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/void-list.js @@ -0,0 +1,12 @@ +"use strict"; +/** + * Why would anyone **SANE** ever use this!? + * + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.VoidList = void 0; +const pointer_list_1 = require("./pointer-list"); +const void_1 = require("./void"); +exports.VoidList = pointer_list_1.PointerList(void_1.Void); +//# sourceMappingURL=void-list.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/void-list.js.map b/node_modules/capnp-ts/src/serialization/pointers/void-list.js.map new file mode 100644 index 0000000..5706639 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/void-list.js.map @@ -0,0 +1 @@ +{"version":3,"file":"void-list.js","sourceRoot":"","sources":["void-list.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAGH,iDAA6C;AAC7C,iCAA8B;AAEjB,QAAA,QAAQ,GAAmB,0BAAW,CAAC,WAAI,CAAC,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/void-list.ts b/node_modules/capnp-ts/src/serialization/pointers/void-list.ts new file mode 100644 index 0000000..07b4b6e --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/void-list.ts @@ -0,0 +1,11 @@ +/** + * Why would anyone **SANE** ever use this!? + * + * @author jdiaz5513 + */ + +import { ListCtor } from "./list"; +import { PointerList } from "./pointer-list"; +import { Void } from "./void"; + +export const VoidList: ListCtor<Void> = PointerList(Void); diff --git a/node_modules/capnp-ts/src/serialization/pointers/void.d.ts b/node_modules/capnp-ts/src/serialization/pointers/void.d.ts new file mode 100644 index 0000000..798baa2 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/void.d.ts @@ -0,0 +1,8 @@ +/** + * @author jdiaz5513 + */ +import { _StructCtor, Struct } from "./struct"; +export declare class Void extends Struct { + static readonly _capnp: _StructCtor; +} +export declare const VOID: undefined; diff --git a/node_modules/capnp-ts/src/serialization/pointers/void.js b/node_modules/capnp-ts/src/serialization/pointers/void.js new file mode 100644 index 0000000..15b9d2f --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/void.js @@ -0,0 +1,19 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.VOID = exports.Void = void 0; +const object_size_1 = require("../object-size"); +const struct_1 = require("./struct"); +class Void extends struct_1.Struct { +} +exports.Void = Void; +Void._capnp = { + displayName: "Void", + id: "0", + size: new object_size_1.ObjectSize(0, 0) +}; +// This following line makes a mysterious "whooshing" sound when it runs. +exports.VOID = undefined; +//# sourceMappingURL=void.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/void.js.map b/node_modules/capnp-ts/src/serialization/pointers/void.js.map new file mode 100644 index 0000000..3cd848a --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/void.js.map @@ -0,0 +1 @@ +{"version":3,"file":"void.js","sourceRoot":"","sources":["void.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,gDAA4C;AAC5C,qCAA+C;AAE/C,MAAa,IAAK,SAAQ,eAAM;;AAAhC,oBAMC;AALiB,WAAM,GAAgB;IACpC,WAAW,EAAE,MAAgB;IAC7B,EAAE,EAAE,GAAG;IACP,IAAI,EAAE,IAAI,wBAAU,CAAC,CAAC,EAAE,CAAC,CAAC;CAC3B,CAAC;AAGJ,yEAAyE;AAE5D,QAAA,IAAI,GAAG,SAAS,CAAC"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/pointers/void.ts b/node_modules/capnp-ts/src/serialization/pointers/void.ts new file mode 100644 index 0000000..a03c1ad --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/pointers/void.ts @@ -0,0 +1,18 @@ +/** + * @author jdiaz5513 + */ + +import { ObjectSize } from "../object-size"; +import { _StructCtor, Struct } from "./struct"; + +export class Void extends Struct { + static readonly _capnp: _StructCtor = { + displayName: "Void" as string, + id: "0", + size: new ObjectSize(0, 0) + }; +} + +// This following line makes a mysterious "whooshing" sound when it runs. + +export const VOID = undefined; diff --git a/node_modules/capnp-ts/src/serialization/segment.d.ts b/node_modules/capnp-ts/src/serialization/segment.d.ts new file mode 100644 index 0000000..bdc6737 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/segment.d.ts @@ -0,0 +1,256 @@ +/** + * @author jdiaz5513 + */ +import { Int64, Uint64 } from "../types"; +import { Message } from "./message"; +import { Pointer } from "./pointers"; +export declare class Segment implements DataView { + buffer: ArrayBuffer; + /** The number of bytes currently allocated in the segment. */ + byteLength: number; + /** + * This value should always be zero. It's only here to satisfy the DataView interface. + * + * In the future the Segment implementation (or a child class) may allow accessing the buffer from a nonzero offset, + * but that adds a lot of extra arithmetic. + */ + byteOffset: number; + readonly [Symbol.toStringTag]: "DataView"; + readonly id: number; + readonly message: Message; + private _dv; + constructor(id: number, message: Message, buffer: ArrayBuffer, byteLength?: number); + /** + * Attempt to allocate the requested number of bytes in this segment. If this segment is full this method will return + * a pointer to freshly allocated space in another segment from the same message. + * + * @param {number} byteLength The number of bytes to allocate, will be rounded up to the nearest word. + * @returns {Pointer} A pointer to the newly allocated space. + */ + allocate(byteLength: number): Pointer; + /** + * Quickly copy a word (8 bytes) from `srcSegment` into this one at the given offset. + * + * @param {number} byteOffset The offset to write the word to. + * @param {Segment} srcSegment The segment to copy the word from. + * @param {number} srcByteOffset The offset from the start of `srcSegment` to copy from. + * @returns {void} + */ + copyWord(byteOffset: number, srcSegment: Segment, srcByteOffset: number): void; + /** + * Quickly copy words from `srcSegment` into this one. + * + * @param {number} byteOffset The offset to start copying into. + * @param {Segment} srcSegment The segment to copy from. + * @param {number} srcByteOffset The start offset to copy from. + * @param {number} wordLength The number of words to copy. + * @returns {void} + */ + copyWords(byteOffset: number, srcSegment: Segment, srcByteOffset: number, wordLength: number): void; + /** + * Quickly fill a number of words in the buffer with zeroes. + * + * @param {number} byteOffset The first byte to set to zero. + * @param {number} wordLength The number of words (not bytes!) to zero out. + * @returns {void} + */ + fillZeroWords(byteOffset: number, wordLength: number): void; + /** WARNING: This function is not yet implemented. */ + getBigInt64(byteOffset: number, littleEndian?: boolean): bigint; + /** WARNING: This function is not yet implemented. */ + getBigUint64(byteOffset: number, littleEndian?: boolean): bigint; + /** + * Get the total number of bytes available in this segment (the size of its underlying buffer). + * + * @returns {number} The total number of bytes this segment can hold. + */ + getCapacity(): number; + /** + * Read a float32 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getFloat32(byteOffset: number): number; + /** + * Read a float64 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getFloat64(byteOffset: number): number; + /** + * Read an int16 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getInt16(byteOffset: number): number; + /** + * Read an int32 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getInt32(byteOffset: number): number; + /** + * Read an int64 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getInt64(byteOffset: number): Int64; + /** + * Read an int8 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getInt8(byteOffset: number): number; + /** + * Read a uint16 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getUint16(byteOffset: number): number; + /** + * Read a uint32 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getUint32(byteOffset: number): number; + /** + * Read a uint8 value out of this segment. + * NOTE: this does not copy the memory region, so updates to the underlying buffer will affect the Uint64 value! + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getUint64(byteOffset: number): Uint64; + /** + * Read a uint8 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getUint8(byteOffset: number): number; + hasCapacity(byteLength: number): boolean; + /** + * Quickly check the word at the given offset to see if it is equal to zero. + * + * PERF_V8: Fastest way to do this is by reading the whole word as a `number` (float64) in the _native_ endian format + * and see if it's zero. + * + * Benchmark: http://jsben.ch/#/Pjooc + * + * @param {number} byteOffset The offset to the word. + * @returns {boolean} `true` if the word is zero. + */ + isWordZero(byteOffset: number): boolean; + /** + * Swap out this segment's underlying buffer with a new one. It's assumed that the new buffer has the same content but + * more free space, otherwise all existing pointers to this segment will be hilariously broken. + * + * @param {ArrayBuffer} buffer The new buffer to use. + * @returns {void} + */ + replaceBuffer(buffer: ArrayBuffer): void; + /** WARNING: This function is not yet implemented. */ + setBigInt64(byteOffset: number, value: bigint, littleEndian?: boolean): void; + /** WARNING: This function is not yet implemented. */ + setBigUint64(byteOffset: number, value: bigint, littleEndian?: boolean): void; + /** + * Write a float32 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + setFloat32(byteOffset: number, val: number): void; + /** + * Write an float64 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + setFloat64(byteOffset: number, val: number): void; + /** + * Write an int16 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + setInt16(byteOffset: number, val: number): void; + /** + * Write an int32 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + setInt32(byteOffset: number, val: number): void; + /** + * Write an int8 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + setInt8(byteOffset: number, val: number): void; + /** + * Write an int64 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {Int64} val The value to store. + * @returns {void} + */ + setInt64(byteOffset: number, val: Int64): void; + /** + * Write a uint16 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + setUint16(byteOffset: number, val: number): void; + /** + * Write a uint32 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + setUint32(byteOffset: number, val: number): void; + /** + * Write a uint64 value to the specified offset. + * TODO: benchmark other ways to perform this write operation. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {Uint64} val The value to store. + * @returns {void} + */ + setUint64(byteOffset: number, val: Uint64): void; + /** + * Write a uint8 (byte) value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + setUint8(byteOffset: number, val: number): void; + /** + * Write a zero word (8 bytes) to the specified offset. This is slightly faster than calling `setUint64` or + * `setFloat64` with a zero value. + * + * Benchmark: http://jsben.ch/#/dUdPI + * + * @param {number} byteOffset The offset of the word to set to zero. + * @returns {void} + */ + setWordZero(byteOffset: number): void; + toString(): string; +} diff --git a/node_modules/capnp-ts/src/serialization/segment.js b/node_modules/capnp-ts/src/serialization/segment.js new file mode 100644 index 0000000..984a065 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/segment.js @@ -0,0 +1,370 @@ +"use strict"; +/** + * @author jdiaz5513 + */ +var _a; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Segment = void 0; +const tslib_1 = require("tslib"); +const debug_1 = tslib_1.__importDefault(require("debug")); +const constants_1 = require("../constants"); +const errors_1 = require("../errors"); +const types_1 = require("../types"); +const util_1 = require("../util"); +const pointers_1 = require("./pointers"); +const trace = debug_1.default("capnp:segment"); +trace("load"); +class Segment { + constructor(id, message, buffer, byteLength = 0) { + this[_a] = "Segment"; + this.id = id; + this.message = message; + this.buffer = buffer; + this._dv = new DataView(buffer); + this.byteOffset = 0; + this.byteLength = byteLength; + } + /** + * Attempt to allocate the requested number of bytes in this segment. If this segment is full this method will return + * a pointer to freshly allocated space in another segment from the same message. + * + * @param {number} byteLength The number of bytes to allocate, will be rounded up to the nearest word. + * @returns {Pointer} A pointer to the newly allocated space. + */ + allocate(byteLength) { + trace("allocate(%d)", byteLength); + // eslint-disable-next-line @typescript-eslint/no-this-alias + let segment = this; + byteLength = util_1.padToWord(byteLength); + if (byteLength > constants_1.MAX_SEGMENT_LENGTH - 8) { + throw new Error(util_1.format(errors_1.SEG_SIZE_OVERFLOW, byteLength)); + } + if (!segment.hasCapacity(byteLength)) { + segment = segment.message.allocateSegment(byteLength); + } + const byteOffset = segment.byteLength; + segment.byteLength = segment.byteLength + byteLength; + trace("Allocated %x bytes in %s (requested segment: %s).", byteLength, this, segment); + return new pointers_1.Pointer(segment, byteOffset); + } + /** + * Quickly copy a word (8 bytes) from `srcSegment` into this one at the given offset. + * + * @param {number} byteOffset The offset to write the word to. + * @param {Segment} srcSegment The segment to copy the word from. + * @param {number} srcByteOffset The offset from the start of `srcSegment` to copy from. + * @returns {void} + */ + copyWord(byteOffset, srcSegment, srcByteOffset) { + const value = srcSegment._dv.getFloat64(srcByteOffset, constants_1.NATIVE_LITTLE_ENDIAN); + this._dv.setFloat64(byteOffset, value, constants_1.NATIVE_LITTLE_ENDIAN); + } + /** + * Quickly copy words from `srcSegment` into this one. + * + * @param {number} byteOffset The offset to start copying into. + * @param {Segment} srcSegment The segment to copy from. + * @param {number} srcByteOffset The start offset to copy from. + * @param {number} wordLength The number of words to copy. + * @returns {void} + */ + copyWords(byteOffset, srcSegment, srcByteOffset, wordLength) { + const dst = new Float64Array(this.buffer, byteOffset, wordLength); + const src = new Float64Array(srcSegment.buffer, srcByteOffset, wordLength); + dst.set(src); + } + /** + * Quickly fill a number of words in the buffer with zeroes. + * + * @param {number} byteOffset The first byte to set to zero. + * @param {number} wordLength The number of words (not bytes!) to zero out. + * @returns {void} + */ + fillZeroWords(byteOffset, wordLength) { + new Float64Array(this.buffer, byteOffset, wordLength).fill(0); + } + /** WARNING: This function is not yet implemented. */ + getBigInt64(byteOffset, littleEndian) { + throw new Error(util_1.format(errors_1.NOT_IMPLEMENTED, byteOffset, littleEndian)); + } + /** WARNING: This function is not yet implemented. */ + getBigUint64(byteOffset, littleEndian) { + throw new Error(util_1.format(errors_1.NOT_IMPLEMENTED, byteOffset, littleEndian)); + } + /** + * Get the total number of bytes available in this segment (the size of its underlying buffer). + * + * @returns {number} The total number of bytes this segment can hold. + */ + getCapacity() { + return this.buffer.byteLength; + } + /** + * Read a float32 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getFloat32(byteOffset) { + return this._dv.getFloat32(byteOffset, true); + } + /** + * Read a float64 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getFloat64(byteOffset) { + return this._dv.getFloat64(byteOffset, true); + } + /** + * Read an int16 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getInt16(byteOffset) { + return this._dv.getInt16(byteOffset, true); + } + /** + * Read an int32 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getInt32(byteOffset) { + return this._dv.getInt32(byteOffset, true); + } + /** + * Read an int64 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getInt64(byteOffset) { + return new types_1.Int64(new Uint8Array(this.buffer.slice(byteOffset, byteOffset + 8))); + } + /** + * Read an int8 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getInt8(byteOffset) { + return this._dv.getInt8(byteOffset); + } + /** + * Read a uint16 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getUint16(byteOffset) { + return this._dv.getUint16(byteOffset, true); + } + /** + * Read a uint32 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getUint32(byteOffset) { + return this._dv.getUint32(byteOffset, true); + } + /** + * Read a uint8 value out of this segment. + * NOTE: this does not copy the memory region, so updates to the underlying buffer will affect the Uint64 value! + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getUint64(byteOffset) { + return new types_1.Uint64(new Uint8Array(this.buffer.slice(byteOffset, byteOffset + 8))); + } + /** + * Read a uint8 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + getUint8(byteOffset) { + return this._dv.getUint8(byteOffset); + } + hasCapacity(byteLength) { + trace("hasCapacity(%d)", byteLength); + // capacity - allocated >= requested + return this.buffer.byteLength - this.byteLength >= byteLength; + } + /** + * Quickly check the word at the given offset to see if it is equal to zero. + * + * PERF_V8: Fastest way to do this is by reading the whole word as a `number` (float64) in the _native_ endian format + * and see if it's zero. + * + * Benchmark: http://jsben.ch/#/Pjooc + * + * @param {number} byteOffset The offset to the word. + * @returns {boolean} `true` if the word is zero. + */ + isWordZero(byteOffset) { + return this._dv.getFloat64(byteOffset, constants_1.NATIVE_LITTLE_ENDIAN) === 0; + } + /** + * Swap out this segment's underlying buffer with a new one. It's assumed that the new buffer has the same content but + * more free space, otherwise all existing pointers to this segment will be hilariously broken. + * + * @param {ArrayBuffer} buffer The new buffer to use. + * @returns {void} + */ + replaceBuffer(buffer) { + trace("replaceBuffer(%p)", buffer); + if (this.buffer === buffer) + return; + if (buffer.byteLength < this.byteLength) { + throw new Error(errors_1.SEG_REPLACEMENT_BUFFER_TOO_SMALL); + } + this._dv = new DataView(buffer); + this.buffer = buffer; + } + /** WARNING: This function is not yet implemented. */ + setBigInt64(byteOffset, value, littleEndian) { + throw new Error(util_1.format(errors_1.NOT_IMPLEMENTED, byteOffset, value, littleEndian)); + } + /** WARNING: This function is not yet implemented. */ + setBigUint64(byteOffset, value, littleEndian) { + throw new Error(util_1.format(errors_1.NOT_IMPLEMENTED, byteOffset, value, littleEndian)); + } + /** + * Write a float32 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + setFloat32(byteOffset, val) { + this._dv.setFloat32(byteOffset, val, true); + } + /** + * Write an float64 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + setFloat64(byteOffset, val) { + this._dv.setFloat64(byteOffset, val, true); + } + /** + * Write an int16 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + setInt16(byteOffset, val) { + this._dv.setInt16(byteOffset, val, true); + } + /** + * Write an int32 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + setInt32(byteOffset, val) { + this._dv.setInt32(byteOffset, val, true); + } + /** + * Write an int8 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + setInt8(byteOffset, val) { + this._dv.setInt8(byteOffset, val); + } + /** + * Write an int64 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {Int64} val The value to store. + * @returns {void} + */ + setInt64(byteOffset, val) { + this._dv.setUint8(byteOffset, val.buffer[0]); + this._dv.setUint8(byteOffset + 1, val.buffer[1]); + this._dv.setUint8(byteOffset + 2, val.buffer[2]); + this._dv.setUint8(byteOffset + 3, val.buffer[3]); + this._dv.setUint8(byteOffset + 4, val.buffer[4]); + this._dv.setUint8(byteOffset + 5, val.buffer[5]); + this._dv.setUint8(byteOffset + 6, val.buffer[6]); + this._dv.setUint8(byteOffset + 7, val.buffer[7]); + } + /** + * Write a uint16 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + setUint16(byteOffset, val) { + this._dv.setUint16(byteOffset, val, true); + } + /** + * Write a uint32 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + setUint32(byteOffset, val) { + this._dv.setUint32(byteOffset, val, true); + } + /** + * Write a uint64 value to the specified offset. + * TODO: benchmark other ways to perform this write operation. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {Uint64} val The value to store. + * @returns {void} + */ + setUint64(byteOffset, val) { + this._dv.setUint8(byteOffset + 0, val.buffer[0]); + this._dv.setUint8(byteOffset + 1, val.buffer[1]); + this._dv.setUint8(byteOffset + 2, val.buffer[2]); + this._dv.setUint8(byteOffset + 3, val.buffer[3]); + this._dv.setUint8(byteOffset + 4, val.buffer[4]); + this._dv.setUint8(byteOffset + 5, val.buffer[5]); + this._dv.setUint8(byteOffset + 6, val.buffer[6]); + this._dv.setUint8(byteOffset + 7, val.buffer[7]); + } + /** + * Write a uint8 (byte) value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + setUint8(byteOffset, val) { + this._dv.setUint8(byteOffset, val); + } + /** + * Write a zero word (8 bytes) to the specified offset. This is slightly faster than calling `setUint64` or + * `setFloat64` with a zero value. + * + * Benchmark: http://jsben.ch/#/dUdPI + * + * @param {number} byteOffset The offset of the word to set to zero. + * @returns {void} + */ + setWordZero(byteOffset) { + this._dv.setFloat64(byteOffset, 0, constants_1.NATIVE_LITTLE_ENDIAN); + } + toString() { + return util_1.format("Segment_id:%d,off:%a,len:%a,cap:%a", this.id, this.byteLength, this.byteOffset, this.buffer.byteLength); + } +} +exports.Segment = Segment; +_a = Symbol.toStringTag; +//# sourceMappingURL=segment.js.map
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/segment.js.map b/node_modules/capnp-ts/src/serialization/segment.js.map new file mode 100644 index 0000000..f973518 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/segment.js.map @@ -0,0 +1 @@ +{"version":3,"file":"segment.js","sourceRoot":"","sources":["segment.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;AAEH,0DAA8B;AAE9B,4CAAwE;AACxE,sCAAiG;AACjG,oCAAyC;AACzC,kCAA4C;AAE5C,yCAAqC;AAErC,MAAM,KAAK,GAAG,eAAS,CAAC,eAAe,CAAC,CAAC;AACzC,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,OAAO;IAwBlB,YAAY,EAAU,EAAE,OAAgB,EAAE,MAAmB,EAAE,UAAU,GAAG,CAAC;QARpE,QAAoB,GAAG,SAAuB,CAAC;QAStD,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;QAEhC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;QACpB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;;;;;OAMG;IAEH,QAAQ,CAAC,UAAkB;QACzB,KAAK,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;QAElC,4DAA4D;QAC5D,IAAI,OAAO,GA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I,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IACrC,CAAC;IAED;;;;;;;;OAQG;IAEH,WAAW,CAAC,UAAkB;QAC5B,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,EAAE,gCAAoB,CAAC,CAAC;IAC3D,CAAC;IAED,QAAQ;QACN,OAAO,aAAM,CACX,oCAAoC,EACpC,IAAI,CAAC,EAAE,EACP,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,MAAM,CAAC,UAAU,CACvB,CAAC;IACJ,CAAC;CACF;AA3cD,0BA2cC;KA3bW,MAAM,CAAC,WAAW"}
\ No newline at end of file diff --git a/node_modules/capnp-ts/src/serialization/segment.ts b/node_modules/capnp-ts/src/serialization/segment.ts new file mode 100644 index 0000000..b488451 --- /dev/null +++ b/node_modules/capnp-ts/src/serialization/segment.ts @@ -0,0 +1,476 @@ +/** + * @author jdiaz5513 + */ + +import initTrace from "debug"; + +import { MAX_SEGMENT_LENGTH, NATIVE_LITTLE_ENDIAN } from "../constants"; +import { NOT_IMPLEMENTED, SEG_REPLACEMENT_BUFFER_TOO_SMALL, SEG_SIZE_OVERFLOW } from "../errors"; +import { Int64, Uint64 } from "../types"; +import { format, padToWord } from "../util"; +import { Message } from "./message"; +import { Pointer } from "./pointers"; + +const trace = initTrace("capnp:segment"); +trace("load"); + +export class Segment implements DataView { + buffer: ArrayBuffer; + + /** The number of bytes currently allocated in the segment. */ + + byteLength: number; + + /** + * This value should always be zero. It's only here to satisfy the DataView interface. + * + * In the future the Segment implementation (or a child class) may allow accessing the buffer from a nonzero offset, + * but that adds a lot of extra arithmetic. + */ + + byteOffset: number; + + readonly [Symbol.toStringTag] = "Segment" as "DataView"; + + readonly id: number; + + readonly message: Message; + + private _dv: DataView; + + constructor(id: number, message: Message, buffer: ArrayBuffer, byteLength = 0) { + this.id = id; + this.message = message; + this.buffer = buffer; + this._dv = new DataView(buffer); + + this.byteOffset = 0; + this.byteLength = byteLength; + } + + /** + * Attempt to allocate the requested number of bytes in this segment. If this segment is full this method will return + * a pointer to freshly allocated space in another segment from the same message. + * + * @param {number} byteLength The number of bytes to allocate, will be rounded up to the nearest word. + * @returns {Pointer} A pointer to the newly allocated space. + */ + + allocate(byteLength: number): Pointer { + trace("allocate(%d)", byteLength); + + // eslint-disable-next-line @typescript-eslint/no-this-alias + let segment: Segment = this; + + byteLength = padToWord(byteLength); + + if (byteLength > MAX_SEGMENT_LENGTH - 8) { + throw new Error(format(SEG_SIZE_OVERFLOW, byteLength)); + } + + if (!segment.hasCapacity(byteLength)) { + segment = segment.message.allocateSegment(byteLength); + } + + const byteOffset = segment.byteLength; + + segment.byteLength = segment.byteLength + byteLength; + + trace("Allocated %x bytes in %s (requested segment: %s).", byteLength, this, segment); + + return new Pointer(segment, byteOffset); + } + + /** + * Quickly copy a word (8 bytes) from `srcSegment` into this one at the given offset. + * + * @param {number} byteOffset The offset to write the word to. + * @param {Segment} srcSegment The segment to copy the word from. + * @param {number} srcByteOffset The offset from the start of `srcSegment` to copy from. + * @returns {void} + */ + + copyWord(byteOffset: number, srcSegment: Segment, srcByteOffset: number): void { + const value = srcSegment._dv.getFloat64(srcByteOffset, NATIVE_LITTLE_ENDIAN); + + this._dv.setFloat64(byteOffset, value, NATIVE_LITTLE_ENDIAN); + } + + /** + * Quickly copy words from `srcSegment` into this one. + * + * @param {number} byteOffset The offset to start copying into. + * @param {Segment} srcSegment The segment to copy from. + * @param {number} srcByteOffset The start offset to copy from. + * @param {number} wordLength The number of words to copy. + * @returns {void} + */ + + copyWords(byteOffset: number, srcSegment: Segment, srcByteOffset: number, wordLength: number): void { + const dst = new Float64Array(this.buffer, byteOffset, wordLength); + const src = new Float64Array(srcSegment.buffer, srcByteOffset, wordLength); + + dst.set(src); + } + + /** + * Quickly fill a number of words in the buffer with zeroes. + * + * @param {number} byteOffset The first byte to set to zero. + * @param {number} wordLength The number of words (not bytes!) to zero out. + * @returns {void} + */ + + fillZeroWords(byteOffset: number, wordLength: number): void { + new Float64Array(this.buffer, byteOffset, wordLength).fill(0); + } + + /** WARNING: This function is not yet implemented. */ + + getBigInt64(byteOffset: number, littleEndian?: boolean): bigint { + throw new Error(format(NOT_IMPLEMENTED, byteOffset, littleEndian)); + } + + /** WARNING: This function is not yet implemented. */ + + getBigUint64(byteOffset: number, littleEndian?: boolean): bigint { + throw new Error(format(NOT_IMPLEMENTED, byteOffset, littleEndian)); + } + + /** + * Get the total number of bytes available in this segment (the size of its underlying buffer). + * + * @returns {number} The total number of bytes this segment can hold. + */ + + getCapacity(): number { + return this.buffer.byteLength; + } + + /** + * Read a float32 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + + getFloat32(byteOffset: number): number { + return this._dv.getFloat32(byteOffset, true); + } + + /** + * Read a float64 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + + getFloat64(byteOffset: number): number { + return this._dv.getFloat64(byteOffset, true); + } + + /** + * Read an int16 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + + getInt16(byteOffset: number): number { + return this._dv.getInt16(byteOffset, true); + } + + /** + * Read an int32 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + + getInt32(byteOffset: number): number { + return this._dv.getInt32(byteOffset, true); + } + + /** + * Read an int64 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + + getInt64(byteOffset: number): Int64 { + return new Int64(new Uint8Array(this.buffer.slice(byteOffset, byteOffset + 8))); + } + + /** + * Read an int8 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + + getInt8(byteOffset: number): number { + return this._dv.getInt8(byteOffset); + } + + /** + * Read a uint16 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + + getUint16(byteOffset: number): number { + return this._dv.getUint16(byteOffset, true); + } + + /** + * Read a uint32 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + + getUint32(byteOffset: number): number { + return this._dv.getUint32(byteOffset, true); + } + + /** + * Read a uint8 value out of this segment. + * NOTE: this does not copy the memory region, so updates to the underlying buffer will affect the Uint64 value! + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + + getUint64(byteOffset: number): Uint64 { + return new Uint64(new Uint8Array(this.buffer.slice(byteOffset, byteOffset + 8))); + } + + /** + * Read a uint8 value out of this segment. + * + * @param {number} byteOffset The offset in bytes to the value. + * @returns {number} The value. + */ + + getUint8(byteOffset: number): number { + return this._dv.getUint8(byteOffset); + } + + hasCapacity(byteLength: number): boolean { + trace("hasCapacity(%d)", byteLength); + + // capacity - allocated >= requested + + return this.buffer.byteLength - this.byteLength >= byteLength; + } + + /** + * Quickly check the word at the given offset to see if it is equal to zero. + * + * PERF_V8: Fastest way to do this is by reading the whole word as a `number` (float64) in the _native_ endian format + * and see if it's zero. + * + * Benchmark: http://jsben.ch/#/Pjooc + * + * @param {number} byteOffset The offset to the word. + * @returns {boolean} `true` if the word is zero. + */ + + isWordZero(byteOffset: number): boolean { + return this._dv.getFloat64(byteOffset, NATIVE_LITTLE_ENDIAN) === 0; + } + + /** + * Swap out this segment's underlying buffer with a new one. It's assumed that the new buffer has the same content but + * more free space, otherwise all existing pointers to this segment will be hilariously broken. + * + * @param {ArrayBuffer} buffer The new buffer to use. + * @returns {void} + */ + + replaceBuffer(buffer: ArrayBuffer): void { + trace("replaceBuffer(%p)", buffer); + + if (this.buffer === buffer) return; + + if (buffer.byteLength < this.byteLength) { + throw new Error(SEG_REPLACEMENT_BUFFER_TOO_SMALL); + } + + this._dv = new DataView(buffer); + this.buffer = buffer; + } + + /** WARNING: This function is not yet implemented. */ + + setBigInt64(byteOffset: number, value: bigint, littleEndian?: boolean): void { + throw new Error(format(NOT_IMPLEMENTED, byteOffset, value, littleEndian)); + } + + /** WARNING: This function is not yet implemented. */ + + setBigUint64(byteOffset: number, value: bigint, littleEndian?: boolean): void { + throw new Error(format(NOT_IMPLEMENTED, byteOffset, value, littleEndian)); + } + + /** + * Write a float32 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + + setFloat32(byteOffset: number, val: number): void { + this._dv.setFloat32(byteOffset, val, true); + } + + /** + * Write an float64 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + + setFloat64(byteOffset: number, val: number): void { + this._dv.setFloat64(byteOffset, val, true); + } + + /** + * Write an int16 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + + setInt16(byteOffset: number, val: number): void { + this._dv.setInt16(byteOffset, val, true); + } + + /** + * Write an int32 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + + setInt32(byteOffset: number, val: number): void { + this._dv.setInt32(byteOffset, val, true); + } + + /** + * Write an int8 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + + setInt8(byteOffset: number, val: number): void { + this._dv.setInt8(byteOffset, val); + } + + /** + * Write an int64 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {Int64} val The value to store. + * @returns {void} + */ + + setInt64(byteOffset: number, val: Int64): void { + this._dv.setUint8(byteOffset, val.buffer[0]); + this._dv.setUint8(byteOffset + 1, val.buffer[1]); + this._dv.setUint8(byteOffset + 2, val.buffer[2]); + this._dv.setUint8(byteOffset + 3, val.buffer[3]); + this._dv.setUint8(byteOffset + 4, val.buffer[4]); + this._dv.setUint8(byteOffset + 5, val.buffer[5]); + this._dv.setUint8(byteOffset + 6, val.buffer[6]); + this._dv.setUint8(byteOffset + 7, val.buffer[7]); + } + + /** + * Write a uint16 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + + setUint16(byteOffset: number, val: number): void { + this._dv.setUint16(byteOffset, val, true); + } + + /** + * Write a uint32 value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + + setUint32(byteOffset: number, val: number): void { + this._dv.setUint32(byteOffset, val, true); + } + + /** + * Write a uint64 value to the specified offset. + * TODO: benchmark other ways to perform this write operation. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {Uint64} val The value to store. + * @returns {void} + */ + + setUint64(byteOffset: number, val: Uint64): void { + this._dv.setUint8(byteOffset + 0, val.buffer[0]); + this._dv.setUint8(byteOffset + 1, val.buffer[1]); + this._dv.setUint8(byteOffset + 2, val.buffer[2]); + this._dv.setUint8(byteOffset + 3, val.buffer[3]); + this._dv.setUint8(byteOffset + 4, val.buffer[4]); + this._dv.setUint8(byteOffset + 5, val.buffer[5]); + this._dv.setUint8(byteOffset + 6, val.buffer[6]); + this._dv.setUint8(byteOffset + 7, val.buffer[7]); + } + + /** + * Write a uint8 (byte) value to the specified offset. + * + * @param {number} byteOffset The offset from the beginning of the buffer. + * @param {number} val The value to store. + * @returns {void} + */ + + setUint8(byteOffset: number, val: number): void { + this._dv.setUint8(byteOffset, val); + } + + /** + * Write a zero word (8 bytes) to the specified offset. This is slightly faster than calling `setUint64` or + * `setFloat64` with a zero value. + * + * Benchmark: http://jsben.ch/#/dUdPI + * + * @param {number} byteOffset The offset of the word to set to zero. + * @returns {void} + */ + + setWordZero(byteOffset: number): void { + this._dv.setFloat64(byteOffset, 0, NATIVE_LITTLE_ENDIAN); + } + + toString(): string { + return format( + "Segment_id:%d,off:%a,len:%a,cap:%a", + this.id, + this.byteLength, + this.byteOffset, + this.buffer.byteLength + ); + } +} |
