diff options
Diffstat (limited to 'node_modules/capnp-ts/src/serialization/arena')
28 files changed, 523 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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,CAAC,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":[],"mapp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AC,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,sBAA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D,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; +} |
