diff options
| author | akiyamn | 2023-09-24 23:22:21 +1000 |
|---|---|---|
| committer | akiyamn | 2023-09-24 23:22:21 +1000 |
| commit | 4e87195739f2a5d9a05451b48773c8afdc680765 (patch) | |
| tree | 9cba501844a4a11dcbdffc4050ed8189561c55ed /node_modules/capnp-ts/src/serialization/pointers | |
| download | price-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.tar.gz price-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.zip | |
Initial commit (by create-cloudflare CLI)
Diffstat (limited to 'node_modules/capnp-ts/src/serialization/pointers')
120 files changed, 7670 insertions, 0 deletions
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 @@ +{"version":3,"file":"bool-list.js","sourceRoot":"","sources":["bool-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,WAAa;IAMzC,GAAG,CAAC,KAAa;QACf,MAAM,OAAO,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;QAC/B,MAAM,UAAU,GAAG,KAAK,KAAK,CAAC,CAAC;QAC/B,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,GAAG,UAAU,CAAC,CAAC;QAExD,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,KAAc;QAC/B,MAAM,OAAO,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;QAC/B,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,MAAM,UAAU,GAAG,CAAC,CAAC,UAAU,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC;QAChD,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QAEzC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrE,CAAC;IAED,QAAQ;QACN,OAAO,QAAQ,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;IACpC,CAAC;;AA1BH,4BA2BC;AA1BiB,eAAM,GAAc;IAClC,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,KAAK,GAAG,eAAS,CAAC,YAAY,CAAC,CAAC;AACtC,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd;;;;;;;GAOG;AAEH,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,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;IAES,MAAM,CAAC,qBAAqB,CAAC,OAAgB;QACrD,OAAO,IAAI,IAAI,CACb,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,MAAM,CAAC,UAAU,CAC1B,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IAEH,iHAAiH;IACjH,eAAe;IAEf,UAAU,CAAC,GAAkC;QAC3C,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAE3B,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QACnC,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,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAC3B,CAAC,CAAC,UAAU,EACZ,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC,SAAS,EAAE,CAChC,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IAEH,UAAU;QACR,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,IAAI,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;IACxE,CAAC;IAED,QAAQ;QACN,OAAO,QAAQ,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;IACpC,CAAC;IAED;;;;;;;OAOG;IAEH,YAAY;QACV,MAAM,CAAC,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 +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,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/serialization/pointers/orphan.js.map @@ -0,0 +1 @@ +{"version":3,"file":"orphan.js","sourceRoot":"","sources":["orphan.ts"],"names":[],"mappings":";;;;AAAA,0DAA8B;AAE9B,yCAAsG;AACtG,qCAAoC;AACpC,4DAAuD;AACvD,gDAA2D;AAE3D,uCAgBmB;AACnB,iDAA6C;AAE7C,MAAM,KAAK,GAAG,eAAS,CAAC,cAAc,CAAC,CAAC;AACxC,KAAK,CAAC,MAAM,CAAC,CAAC;AAUd,oHAAoH;AACpH,sEAAsE;AAEtE;;;;;;;;;GASG;AAEH,MAAa,MAAM;IAOjB,YAAY,GAAM;QAChB,MAAM,CAAC,GAAG,oBAAU,CAAC,GAAG,CAAC,CAAC;QAE1B,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC;QAE/B,IAAI,CAAC,MAAM,GAAG,EAAa,CAAC;QAE5B,iFAAiF;QAEjF,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,8BAAoB,CAAC,GAAG,CAAC,CAA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a,CAAC,IAAI,CAAC,UAAU,EAAE,2BAAa,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;gBAE7E,MAAM;YAER,KAAK,0BAAW,CAAC,IAAI,CAAC,CAAC;gBACrB,MAAM,UAAU,GAAG,2BAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACpG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;gBAExD,MAAM;aACP;YACD;gBACE,uDAAuD;gBAEvD,MAAM;SACT;QAED,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC1B,CAAC;IAED,QAAQ;QACN,OAAO,aAAM,CAAC,sBAAsB,EAAE,IAAI,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,EAAE,UAAkB,EAAE,UAAU,GAAG,qBAAS;QACtE,IAAI,CAAC,MAAM,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;QACnD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAE7B,IAAI,UAAU,KAAK,CAAC,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,aAAM,CAAC,iCAAwB,EAAE,IAAI,CAAC,CAAC,CAAC;SACzD;QAED,iGAAiG;QAEjG,sBAAsB,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAE9C,6GAA6G;QAC7G,yGAAyG;QACzG,iHAAiH;QACjH,eAAe;QAEf,IAAI,UAAU,GAAG,CAAC,IAAI,UAAU,GAAG,OAAO,CAAC,UAAU,EAAE;YACrD,MAAM,IAAI,KAAK,CAAC,aAAM,CAAC,iCAAwB,EAAE,UAAU,CAAC,CAAC,CAAC;SAC/D;QAED,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACxB,CAAC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GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,EAAE,EAAE;QAC9C,MAAM,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,CAAC,GAAG,CAAC,CAAC;QAE9C,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,UAAU,GAAG,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;QAC1G,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,UAAU,GAAG,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;QAE1G,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAC1B;IAED,kHAAkH;IAClH,iEAAiE;IAEjE,IAAI,GAAG,CAAC,MAAM,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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D,0BAEC;AAED,SAAgB,SAAS,CAAC,IAAY,EAAE,KAAa,EAAE,MAAc,EAAE,CAAS;IAC9E,IAAI,KAAK,KAAK,MAAM,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,aAAM,CAAC,iCAAwB,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;KAC3E;AACH,CAAC;AAJD,8BAIC;AAED,SAAgB,eAAe,CAAC,UAAkB,EAAE,UAAkB,EAAE,CAAS;IAC/E,MAAM,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC;IAEjD,IAAI,UAAU,GAAG,CAAC,IAAI,UAAU,GAAG,CAAC,IAAI,UAAU,GAAG,UAAU,GAAG,cAAc,EAAE;QAChF,MAAM,IAAI,KAAK,CAAC,aAAM,CAAC,sCAA6B,EAAE,CAAC,EAAE,UAAU,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,KA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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; |
