mirror of
https://github.com/JonasunderscoreJones/api-worker.git
synced 2025-10-23 10:29:19 +02:00
Initial commit (by create-cloudflare CLI)
This commit is contained in:
commit
58a42872a0
1745 changed files with 741893 additions and 0 deletions
59
node_modules/capnp-ts/CHANGELOG.md
generated
vendored
Normal file
59
node_modules/capnp-ts/CHANGELOG.md
generated
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
<a name="0.4.0"></a>
|
||||
# [0.4.0](https://github.com/jdiaz5513/capnp-ts/compare/v0.3.1...v0.4.0) (2018-09-26)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* revert botched import paths ([#111](https://github.com/jdiaz5513/capnp-ts/issues/111)) ([e280020](https://github.com/jdiaz5513/capnp-ts/commit/e280020))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **compiler:** add support for capnpc v0.7.0 ([#110](https://github.com/jdiaz5513/capnp-ts/issues/110)) ([22bd14d](https://github.com/jdiaz5513/capnp-ts/commit/22bd14d))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="0.3.1"></a>
|
||||
## [0.3.1](https://github.com/jdiaz5513/capnp-ts/compare/v0.3.0...v0.3.1) (2018-09-25)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **serialization:** fix parse crash on null pointer dereference in resize ([#107](https://github.com/jdiaz5513/capnp-ts/issues/107)) ([3f8b307](https://github.com/jdiaz5513/capnp-ts/commit/3f8b307)), closes [#78](https://github.com/jdiaz5513/capnp-ts/issues/78)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="0.3.0"></a>
|
||||
# [0.3.0](https://github.com/jdiaz5513/capnp-ts/compare/v0.2.4...v0.3.0) (2018-08-29)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **build:** avoid use of debug script for capnpc build step ([#101](https://github.com/jdiaz5513/capnp-ts/issues/101)) ([f1d606a](https://github.com/jdiaz5513/capnp-ts/commit/f1d606a))
|
||||
* **serialization:** set instance variables before they may be referenced ([#106](https://github.com/jdiaz5513/capnp-ts/issues/106)) ([21deff5](https://github.com/jdiaz5513/capnp-ts/commit/21deff5))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **compiler:** implement remaining serialization features ([#98](https://github.com/jdiaz5513/capnp-ts/issues/98)) ([524b6bd](https://github.com/jdiaz5513/capnp-ts/commit/524b6bd))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="0.2.4"></a>
|
||||
## [0.2.4](https://github.com/jdiaz5513/capnp-ts/compare/v0.2.3...v0.2.4) (2017-11-24)
|
||||
|
||||
|
||||
|
||||
|
||||
**Note:** Version bump only for package capnp-ts
|
21
node_modules/capnp-ts/README.md
generated
vendored
Normal file
21
node_modules/capnp-ts/README.md
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
# capnp-ts
|
||||
|
||||
A strongly typed [Cap'n Proto](https://capnproto.org/) implementation for the browser and Node.js using TypeScript.
|
||||
|
||||
Here's a quick usage example:
|
||||
|
||||
```typescript
|
||||
import * as capnp from 'capnp-ts';
|
||||
|
||||
import {MyStruct} from './myschema.capnp';
|
||||
|
||||
export function loadMessage(buffer: ArrayBuffer): MyStruct {
|
||||
|
||||
const message = capnp.Message.fromArrayBuffer(buffer);
|
||||
|
||||
return message.getRoot(MyStruct);
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
An extended readme is available on the project site: [https://github.com/jdiaz5513/capnp-ts](https://github.com/jdiaz5513/capnp-ts).
|
26
node_modules/capnp-ts/package.json
generated
vendored
Normal file
26
node_modules/capnp-ts/package.json
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"author": "jdiaz5513",
|
||||
"bugs": {
|
||||
"url": "https://github.com/jdiaz5513/capnp-ts/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": "^4.3.1",
|
||||
"tslib": "^2.2.0"
|
||||
},
|
||||
"description": "Strongly typed Cap'n Proto implementation for the browser and Node.js using TypeScript",
|
||||
"homepage": "https://github.com/jdiaz5513/capnp-ts#readme",
|
||||
"keywords": [
|
||||
"capnp",
|
||||
"rpc",
|
||||
"typescript"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./src/index.js",
|
||||
"name": "capnp-ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/jdiaz5513/capnp-ts.git"
|
||||
},
|
||||
"types": "./src/index.d.ts",
|
||||
"version": "0.7.0"
|
||||
}
|
75
node_modules/capnp-ts/src/constants.d.ts
generated
vendored
Normal file
75
node_modules/capnp-ts/src/constants.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
/** Default size (in bytes) for newly allocated segments. */
|
||||
export declare const DEFAULT_BUFFER_SIZE = 4096;
|
||||
export declare const DEFAULT_DECODE_LIMIT: number;
|
||||
/**
|
||||
* Limit to how deeply nested pointers are allowed to be. The root struct of a message will start at this value, and it
|
||||
* is decremented as pointers are dereferenced.
|
||||
*/
|
||||
export declare const DEFAULT_DEPTH_LIMIT = 64;
|
||||
/**
|
||||
* Limit to the number of **bytes** that can be traversed in a single message. This is necessary to prevent certain
|
||||
* classes of DoS attacks where maliciously crafted data can be self-referencing in a way that wouldn't trigger the
|
||||
* depth limit.
|
||||
*
|
||||
* For this reason, it is advised to cache pointers into variables and not constantly dereference them since the
|
||||
* message's traversal limit gets decremented each time.
|
||||
*/
|
||||
export declare const DEFAULT_TRAVERSE_LIMIT: number;
|
||||
/**
|
||||
* When allocating array buffers dynamically (while packing or in certain Arena implementations) the previous buffer's
|
||||
* size is multiplied by this number to determine the next buffer's size. This is chosen to keep both time spent
|
||||
* reallocating and wasted memory to a minimum.
|
||||
*
|
||||
* Smaller numbers would save memory at the expense of CPU time.
|
||||
*/
|
||||
export declare const GROWTH_FACTOR = 1.5;
|
||||
/** A bitmask applied to obtain the size of a list pointer. */
|
||||
export declare const LIST_SIZE_MASK = 7;
|
||||
/** Maximum number of bytes to dump at once when dumping array buffers to string. */
|
||||
export declare const MAX_BUFFER_DUMP_BYTES = 8192;
|
||||
/** The maximum value for a 32-bit integer. */
|
||||
export declare const MAX_INT32 = 2147483647;
|
||||
/** The maximum value for a 32-bit unsigned integer. */
|
||||
export declare const MAX_UINT32 = 4294967295;
|
||||
/** The largest integer that can be precisely represented in JavaScript. */
|
||||
export declare const MAX_SAFE_INTEGER = 9007199254740991;
|
||||
/** Maximum limit on the number of segments in a message stream. */
|
||||
export declare const MAX_STREAM_SEGMENTS = 512;
|
||||
/** The smallest integer that can be precisely represented in JavaScript. */
|
||||
export declare const MIN_SAFE_INTEGER = -9007199254740991;
|
||||
/** Minimum growth increment for a SingleSegmentArena. */
|
||||
export declare const MIN_SINGLE_SEGMENT_GROWTH = 4096;
|
||||
/**
|
||||
* This will be `true` if the machine running this code stores numbers natively in little-endian format. This is useful
|
||||
* for some numeric type conversions when the endianness does not affect the output. Using the native endianness for
|
||||
* these operations is _slightly_ faster.
|
||||
*/
|
||||
export declare const NATIVE_LITTLE_ENDIAN: boolean;
|
||||
/**
|
||||
* When packing a message, this is the number of zero bytes required after a SPAN (0xff) tag is written to the packed
|
||||
* message before the span is terminated.
|
||||
*
|
||||
* This little detail is left up to the implementation because it can be tuned for performance. Setting this to a higher
|
||||
* value may help with messages that contain a ton of text/data.
|
||||
*
|
||||
* It is imperative to never set this below 1 or else BAD THINGS. You have been warned.
|
||||
*/
|
||||
export declare const PACK_SPAN_THRESHOLD = 2;
|
||||
/**
|
||||
* How far to travel into a nested pointer structure during a deep copy; when this limit is exhausted the copy
|
||||
* operation will throw an error.
|
||||
*/
|
||||
export declare const POINTER_COPY_LIMIT = 32;
|
||||
/** A bitmask for looking up the double-far flag on a far pointer. */
|
||||
export declare const POINTER_DOUBLE_FAR_MASK = 4;
|
||||
/** A bitmask for looking up the pointer type. */
|
||||
export declare const POINTER_TYPE_MASK = 3;
|
||||
/** Used for some 64-bit conversions, equal to Math.pow(2, 32). */
|
||||
export declare const VAL32 = 4294967296;
|
||||
/** The maximum value allowed for depth traversal limits. */
|
||||
export declare const MAX_DEPTH = 2147483647;
|
||||
/** The maximum byte length for a single segment. */
|
||||
export declare const MAX_SEGMENT_LENGTH = 4294967295;
|
82
node_modules/capnp-ts/src/constants.js
generated
vendored
Normal file
82
node_modules/capnp-ts/src/constants.js
generated
vendored
Normal file
|
@ -0,0 +1,82 @@
|
|||
"use strict";
|
||||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MAX_SEGMENT_LENGTH = exports.MAX_DEPTH = exports.VAL32 = exports.POINTER_TYPE_MASK = exports.POINTER_DOUBLE_FAR_MASK = exports.POINTER_COPY_LIMIT = exports.PACK_SPAN_THRESHOLD = exports.NATIVE_LITTLE_ENDIAN = exports.MIN_SINGLE_SEGMENT_GROWTH = exports.MIN_SAFE_INTEGER = exports.MAX_STREAM_SEGMENTS = exports.MAX_SAFE_INTEGER = exports.MAX_UINT32 = exports.MAX_INT32 = exports.MAX_BUFFER_DUMP_BYTES = exports.LIST_SIZE_MASK = exports.GROWTH_FACTOR = exports.DEFAULT_TRAVERSE_LIMIT = exports.DEFAULT_DEPTH_LIMIT = exports.DEFAULT_DECODE_LIMIT = exports.DEFAULT_BUFFER_SIZE = void 0;
|
||||
// Perform some bit gymnastics to determine the native endian format.
|
||||
const tmpWord = new DataView(new ArrayBuffer(8));
|
||||
new Uint16Array(tmpWord.buffer)[0] = 0x0102;
|
||||
/** Default size (in bytes) for newly allocated segments. */
|
||||
exports.DEFAULT_BUFFER_SIZE = 4096;
|
||||
exports.DEFAULT_DECODE_LIMIT = 64 << 20; // 64 MiB
|
||||
/**
|
||||
* Limit to how deeply nested pointers are allowed to be. The root struct of a message will start at this value, and it
|
||||
* is decremented as pointers are dereferenced.
|
||||
*/
|
||||
exports.DEFAULT_DEPTH_LIMIT = 64;
|
||||
/**
|
||||
* Limit to the number of **bytes** that can be traversed in a single message. This is necessary to prevent certain
|
||||
* classes of DoS attacks where maliciously crafted data can be self-referencing in a way that wouldn't trigger the
|
||||
* depth limit.
|
||||
*
|
||||
* For this reason, it is advised to cache pointers into variables and not constantly dereference them since the
|
||||
* message's traversal limit gets decremented each time.
|
||||
*/
|
||||
exports.DEFAULT_TRAVERSE_LIMIT = 64 << 20; // 64 MiB
|
||||
/**
|
||||
* When allocating array buffers dynamically (while packing or in certain Arena implementations) the previous buffer's
|
||||
* size is multiplied by this number to determine the next buffer's size. This is chosen to keep both time spent
|
||||
* reallocating and wasted memory to a minimum.
|
||||
*
|
||||
* Smaller numbers would save memory at the expense of CPU time.
|
||||
*/
|
||||
exports.GROWTH_FACTOR = 1.5;
|
||||
/** A bitmask applied to obtain the size of a list pointer. */
|
||||
exports.LIST_SIZE_MASK = 0x00000007;
|
||||
/** Maximum number of bytes to dump at once when dumping array buffers to string. */
|
||||
exports.MAX_BUFFER_DUMP_BYTES = 8192;
|
||||
/** The maximum value for a 32-bit integer. */
|
||||
exports.MAX_INT32 = 0x7fffffff;
|
||||
/** The maximum value for a 32-bit unsigned integer. */
|
||||
exports.MAX_UINT32 = 0xffffffff;
|
||||
/** The largest integer that can be precisely represented in JavaScript. */
|
||||
exports.MAX_SAFE_INTEGER = 9007199254740991;
|
||||
/** Maximum limit on the number of segments in a message stream. */
|
||||
exports.MAX_STREAM_SEGMENTS = 512;
|
||||
/** The smallest integer that can be precisely represented in JavaScript. */
|
||||
exports.MIN_SAFE_INTEGER = -9007199254740991;
|
||||
/** Minimum growth increment for a SingleSegmentArena. */
|
||||
exports.MIN_SINGLE_SEGMENT_GROWTH = 4096;
|
||||
/**
|
||||
* This will be `true` if the machine running this code stores numbers natively in little-endian format. This is useful
|
||||
* for some numeric type conversions when the endianness does not affect the output. Using the native endianness for
|
||||
* these operations is _slightly_ faster.
|
||||
*/
|
||||
exports.NATIVE_LITTLE_ENDIAN = tmpWord.getUint8(0) === 0x02;
|
||||
/**
|
||||
* When packing a message, this is the number of zero bytes required after a SPAN (0xff) tag is written to the packed
|
||||
* message before the span is terminated.
|
||||
*
|
||||
* This little detail is left up to the implementation because it can be tuned for performance. Setting this to a higher
|
||||
* value may help with messages that contain a ton of text/data.
|
||||
*
|
||||
* It is imperative to never set this below 1 or else BAD THINGS. You have been warned.
|
||||
*/
|
||||
exports.PACK_SPAN_THRESHOLD = 2;
|
||||
/**
|
||||
* How far to travel into a nested pointer structure during a deep copy; when this limit is exhausted the copy
|
||||
* operation will throw an error.
|
||||
*/
|
||||
exports.POINTER_COPY_LIMIT = 32;
|
||||
/** A bitmask for looking up the double-far flag on a far pointer. */
|
||||
exports.POINTER_DOUBLE_FAR_MASK = 0x00000004;
|
||||
/** A bitmask for looking up the pointer type. */
|
||||
exports.POINTER_TYPE_MASK = 0x00000003;
|
||||
/** Used for some 64-bit conversions, equal to Math.pow(2, 32). */
|
||||
exports.VAL32 = 0x100000000;
|
||||
/** The maximum value allowed for depth traversal limits. */
|
||||
exports.MAX_DEPTH = exports.MAX_INT32;
|
||||
/** The maximum byte length for a single segment. */
|
||||
exports.MAX_SEGMENT_LENGTH = exports.MAX_UINT32;
|
||||
//# sourceMappingURL=constants.js.map
|
1
node_modules/capnp-ts/src/constants.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/constants.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"constants.js","sourceRoot":"","sources":["constants.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,qEAAqE;AAErE,MAAM,OAAO,GAAG,IAAI,QAAQ,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AACjD,IAAI,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;AAE5C,4DAA4D;AAE/C,QAAA,mBAAmB,GAAG,IAAI,CAAC;AAE3B,QAAA,oBAAoB,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,SAAS;AAEvD;;;GAGG;AAEU,QAAA,mBAAmB,GAAG,EAAE,CAAC;AAEtC;;;;;;;GAOG;AAEU,QAAA,sBAAsB,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,SAAS;AAEzD;;;;;;GAMG;AAEU,QAAA,aAAa,GAAG,GAAG,CAAC;AAEjC,8DAA8D;AAEjD,QAAA,cAAc,GAAG,UAAU,CAAC;AAEzC,oFAAoF;AAEvE,QAAA,qBAAqB,GAAG,IAAI,CAAC;AAE1C,8CAA8C;AAEjC,QAAA,SAAS,GAAG,UAAU,CAAC;AAEpC,uDAAuD;AAE1C,QAAA,UAAU,GAAG,UAAU,CAAC;AAErC,2EAA2E;AAE9D,QAAA,gBAAgB,GAAG,gBAAgB,CAAC;AAEjD,mEAAmE;AAEtD,QAAA,mBAAmB,GAAG,GAAG,CAAC;AAEvC,4EAA4E;AAE/D,QAAA,gBAAgB,GAAG,CAAC,gBAAgB,CAAC;AAElD,yDAAyD;AAE5C,QAAA,yBAAyB,GAAG,IAAI,CAAC;AAE9C;;;;GAIG;AAEU,QAAA,oBAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAEjE;;;;;;;;GAQG;AAEU,QAAA,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;GAGG;AAEU,QAAA,kBAAkB,GAAG,EAAE,CAAC;AAErC,qEAAqE;AAExD,QAAA,uBAAuB,GAAG,UAAU,CAAC;AAElD,iDAAiD;AAEpC,QAAA,iBAAiB,GAAG,UAAU,CAAC;AAE5C,kEAAkE;AAErD,QAAA,KAAK,GAAG,WAAW,CAAC;AAEjC,4DAA4D;AAE/C,QAAA,SAAS,GAAG,iBAAS,CAAC;AAEnC,oDAAoD;AAEvC,QAAA,kBAAkB,GAAG,kBAAU,CAAC"}
|
121
node_modules/capnp-ts/src/constants.ts
generated
vendored
Normal file
121
node_modules/capnp-ts/src/constants.ts
generated
vendored
Normal file
|
@ -0,0 +1,121 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
|
||||
// Perform some bit gymnastics to determine the native endian format.
|
||||
|
||||
const tmpWord = new DataView(new ArrayBuffer(8));
|
||||
new Uint16Array(tmpWord.buffer)[0] = 0x0102;
|
||||
|
||||
/** Default size (in bytes) for newly allocated segments. */
|
||||
|
||||
export const DEFAULT_BUFFER_SIZE = 4096;
|
||||
|
||||
export const DEFAULT_DECODE_LIMIT = 64 << 20; // 64 MiB
|
||||
|
||||
/**
|
||||
* Limit to how deeply nested pointers are allowed to be. The root struct of a message will start at this value, and it
|
||||
* is decremented as pointers are dereferenced.
|
||||
*/
|
||||
|
||||
export const DEFAULT_DEPTH_LIMIT = 64;
|
||||
|
||||
/**
|
||||
* Limit to the number of **bytes** that can be traversed in a single message. This is necessary to prevent certain
|
||||
* classes of DoS attacks where maliciously crafted data can be self-referencing in a way that wouldn't trigger the
|
||||
* depth limit.
|
||||
*
|
||||
* For this reason, it is advised to cache pointers into variables and not constantly dereference them since the
|
||||
* message's traversal limit gets decremented each time.
|
||||
*/
|
||||
|
||||
export const DEFAULT_TRAVERSE_LIMIT = 64 << 20; // 64 MiB
|
||||
|
||||
/**
|
||||
* When allocating array buffers dynamically (while packing or in certain Arena implementations) the previous buffer's
|
||||
* size is multiplied by this number to determine the next buffer's size. This is chosen to keep both time spent
|
||||
* reallocating and wasted memory to a minimum.
|
||||
*
|
||||
* Smaller numbers would save memory at the expense of CPU time.
|
||||
*/
|
||||
|
||||
export const GROWTH_FACTOR = 1.5;
|
||||
|
||||
/** A bitmask applied to obtain the size of a list pointer. */
|
||||
|
||||
export const LIST_SIZE_MASK = 0x00000007;
|
||||
|
||||
/** Maximum number of bytes to dump at once when dumping array buffers to string. */
|
||||
|
||||
export const MAX_BUFFER_DUMP_BYTES = 8192;
|
||||
|
||||
/** The maximum value for a 32-bit integer. */
|
||||
|
||||
export const MAX_INT32 = 0x7fffffff;
|
||||
|
||||
/** The maximum value for a 32-bit unsigned integer. */
|
||||
|
||||
export const MAX_UINT32 = 0xffffffff;
|
||||
|
||||
/** The largest integer that can be precisely represented in JavaScript. */
|
||||
|
||||
export const MAX_SAFE_INTEGER = 9007199254740991;
|
||||
|
||||
/** Maximum limit on the number of segments in a message stream. */
|
||||
|
||||
export const MAX_STREAM_SEGMENTS = 512;
|
||||
|
||||
/** The smallest integer that can be precisely represented in JavaScript. */
|
||||
|
||||
export const MIN_SAFE_INTEGER = -9007199254740991;
|
||||
|
||||
/** Minimum growth increment for a SingleSegmentArena. */
|
||||
|
||||
export const MIN_SINGLE_SEGMENT_GROWTH = 4096;
|
||||
|
||||
/**
|
||||
* This will be `true` if the machine running this code stores numbers natively in little-endian format. This is useful
|
||||
* for some numeric type conversions when the endianness does not affect the output. Using the native endianness for
|
||||
* these operations is _slightly_ faster.
|
||||
*/
|
||||
|
||||
export const NATIVE_LITTLE_ENDIAN = tmpWord.getUint8(0) === 0x02;
|
||||
|
||||
/**
|
||||
* When packing a message, this is the number of zero bytes required after a SPAN (0xff) tag is written to the packed
|
||||
* message before the span is terminated.
|
||||
*
|
||||
* This little detail is left up to the implementation because it can be tuned for performance. Setting this to a higher
|
||||
* value may help with messages that contain a ton of text/data.
|
||||
*
|
||||
* It is imperative to never set this below 1 or else BAD THINGS. You have been warned.
|
||||
*/
|
||||
|
||||
export const PACK_SPAN_THRESHOLD = 2;
|
||||
|
||||
/**
|
||||
* How far to travel into a nested pointer structure during a deep copy; when this limit is exhausted the copy
|
||||
* operation will throw an error.
|
||||
*/
|
||||
|
||||
export const POINTER_COPY_LIMIT = 32;
|
||||
|
||||
/** A bitmask for looking up the double-far flag on a far pointer. */
|
||||
|
||||
export const POINTER_DOUBLE_FAR_MASK = 0x00000004;
|
||||
|
||||
/** A bitmask for looking up the pointer type. */
|
||||
|
||||
export const POINTER_TYPE_MASK = 0x00000003;
|
||||
|
||||
/** Used for some 64-bit conversions, equal to Math.pow(2, 32). */
|
||||
|
||||
export const VAL32 = 0x100000000;
|
||||
|
||||
/** The maximum value allowed for depth traversal limits. */
|
||||
|
||||
export const MAX_DEPTH = MAX_INT32;
|
||||
|
||||
/** The maximum byte length for a single segment. */
|
||||
|
||||
export const MAX_SEGMENT_LENGTH = MAX_UINT32;
|
51
node_modules/capnp-ts/src/errors.d.ts
generated
vendored
Normal file
51
node_modules/capnp-ts/src/errors.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* This file contains all the error strings used in the library. Also contains silliness.
|
||||
*
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
export declare const INVARIANT_UNREACHABLE_CODE = "CAPNP-TS000 Unreachable code detected.";
|
||||
export declare function assertNever(n: never): never;
|
||||
export declare const MSG_INVALID_FRAME_HEADER = "CAPNP-TS001 Attempted to parse an invalid message frame header; are you sure this is a Cap'n Proto message?";
|
||||
export declare const MSG_NO_SEGMENTS_IN_ARENA = "CAPNP-TS002 Attempted to preallocate a message with no segments in the arena.";
|
||||
export declare const MSG_PACK_NOT_WORD_ALIGNED = "CAPNP-TS003 Attempted to pack a message that was not word-aligned.";
|
||||
export declare const MSG_SEGMENT_OUT_OF_BOUNDS = "CAPNP-TS004 Segment ID %X is out of bounds for message %s.";
|
||||
export declare const MSG_SEGMENT_TOO_SMALL = "CAPNP-TS005 First segment must have at least enough room to hold the root pointer (8 bytes).";
|
||||
export declare const NOT_IMPLEMENTED = "CAPNP-TS006 %s is not implemented.";
|
||||
export declare const PTR_ADOPT_COMPOSITE_STRUCT = "CAPNP-TS007 Attempted to adopt a struct into a composite list (%s).";
|
||||
export declare const PTR_ADOPT_WRONG_MESSAGE = "CAPNP-TS008 Attempted to adopt %s into a pointer in a different message %s.";
|
||||
export declare const PTR_ALREADY_ADOPTED = "CAPNP-TS009 Attempted to adopt %s more than once.";
|
||||
export declare const PTR_COMPOSITE_SIZE_UNDEFINED = "CAPNP-TS010 Attempted to set a composite list without providing a composite element size.";
|
||||
export declare const PTR_DEPTH_LIMIT_EXCEEDED = "CAPNP-TS011 Nesting depth limit exceeded for %s.";
|
||||
export declare const PTR_DISOWN_COMPOSITE_STRUCT = "CAPNP-TS012 Attempted to disown a struct member from a composite list (%s).";
|
||||
export declare const PTR_INIT_COMPOSITE_STRUCT = "CAPNP-TS013 Attempted to initialize a struct member from a composite list (%s).";
|
||||
export declare const PTR_INIT_NON_GROUP = "CAPNP-TS014 Attempted to initialize a group field with a non-group struct class.";
|
||||
export declare const PTR_INVALID_FAR_TARGET = "CAPNP-TS015 Target of a far pointer (%s) is another far pointer.";
|
||||
export declare const PTR_INVALID_LIST_SIZE = "CAPNP-TS016 Invalid list element size: %x.";
|
||||
export declare const PTR_INVALID_POINTER_TYPE = "CAPNP-TS017 Invalid pointer type: %x.";
|
||||
export declare const PTR_INVALID_UNION_ACCESS = "CAPNP-TS018 Attempted to access getter on %s for union field %s that is not currently set (wanted: %d, found: %d).";
|
||||
export declare const PTR_OFFSET_OUT_OF_BOUNDS = "CAPNP-TS019 Pointer offset %a is out of bounds for underlying buffer.";
|
||||
export declare const PTR_STRUCT_DATA_OUT_OF_BOUNDS = "CAPNP-TS020 Attempted to access out-of-bounds struct data (struct: %s, %d bytes at %a, data words: %d).";
|
||||
export declare const PTR_STRUCT_POINTER_OUT_OF_BOUNDS = "CAPNP-TS021 Attempted to access out-of-bounds struct pointer (%s, index: %d, length: %d).";
|
||||
export declare const PTR_TRAVERSAL_LIMIT_EXCEEDED = "CAPNP-TS022 Traversal limit exceeded! Slow down! %s";
|
||||
export declare const PTR_WRONG_LIST_TYPE = "CAPNP-TS023 Cannot convert %s to a %s list.";
|
||||
export declare const PTR_WRONG_POINTER_TYPE = "CAPNP-TS024 Attempted to convert pointer %s to a %s type.";
|
||||
export declare const PTR_WRONG_COMPOSITE_DATA_SIZE = "CAPNP-TS025 Attempted to convert %s to a composite list with the wrong data size (found: %d).";
|
||||
export declare const PTR_WRONG_COMPOSITE_PTR_SIZE = "CAPNP-TS026 Attempted to convert %s to a composite list with the wrong pointer size (found: %d).";
|
||||
export declare const PTR_WRONG_STRUCT_DATA_SIZE = "CAPNP-TS027 Attempted to convert %s to a struct with the wrong data size (found: %d).";
|
||||
export declare const PTR_WRONG_STRUCT_PTR_SIZE = "CAPNP-TS028 Attempted to convert %s to a struct with the wrong pointer size (found: %d).";
|
||||
export declare const RANGE_INT32_OVERFLOW = "CAPNP-TS029 32-bit signed integer overflow detected.";
|
||||
export declare const RANGE_INT64_UNDERFLOW = "CAPNP-TS030 Buffer is not large enough to hold a word.";
|
||||
export declare const RANGE_INVALID_UTF8 = "CAPNP-TS031 Invalid UTF-8 code sequence detected.";
|
||||
export declare const RANGE_SIZE_OVERFLOW: string;
|
||||
export declare const RANGE_UINT32_OVERFLOW = "CAPNP-TS033 32-bit unsigned integer overflow detected.";
|
||||
export declare const SEG_BUFFER_NOT_ALLOCATED = "CAPNP-TS034 allocate() needs to be called at least once before getting a buffer.";
|
||||
export declare const SEG_GET_NON_ZERO_SINGLE = "CAPNP-TS035 Attempted to get a segment other than 0 (%d) from a single segment arena.";
|
||||
export declare const SEG_ID_OUT_OF_BOUNDS = "CAPNP-TS036 Attempted to get an out-of-bounds segment (%d).";
|
||||
export declare const SEG_NOT_WORD_ALIGNED = "CAPNP-TS037 Segment buffer length %d is not a multiple of 8.";
|
||||
export declare const SEG_REPLACEMENT_BUFFER_TOO_SMALL = "CAPNP-TS038 Attempted to replace a segment buffer with one that is smaller than the allocated space.";
|
||||
export declare const SEG_SIZE_OVERFLOW: string;
|
||||
export declare const TYPE_COMPOSITE_SIZE_UNDEFINED = "CAPNP-TS040 Must provide a composite element size for composite list pointers.";
|
||||
export declare const TYPE_GET_GENERIC_LIST = "CAPNP-TS041 Attempted to call get() on a generic list.";
|
||||
export declare const TYPE_SET_GENERIC_LIST = "CAPNP-TS042 Attempted to call set() on a generic list.";
|
||||
export declare const PTR_WRITE_CONST_LIST = "CAPNP-TS043 Attempted to write to a const list.";
|
||||
export declare const PTR_WRITE_CONST_STRUCT = "CAPNP-TS044 Attempted to write to a const struct.";
|
86
node_modules/capnp-ts/src/errors.js
generated
vendored
Normal file
86
node_modules/capnp-ts/src/errors.js
generated
vendored
Normal file
|
@ -0,0 +1,86 @@
|
|||
"use strict";
|
||||
/**
|
||||
* This file contains all the error strings used in the library. Also contains silliness.
|
||||
*
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PTR_WRITE_CONST_STRUCT = exports.PTR_WRITE_CONST_LIST = exports.TYPE_SET_GENERIC_LIST = exports.TYPE_GET_GENERIC_LIST = exports.TYPE_COMPOSITE_SIZE_UNDEFINED = exports.SEG_SIZE_OVERFLOW = exports.SEG_REPLACEMENT_BUFFER_TOO_SMALL = exports.SEG_NOT_WORD_ALIGNED = exports.SEG_ID_OUT_OF_BOUNDS = exports.SEG_GET_NON_ZERO_SINGLE = exports.SEG_BUFFER_NOT_ALLOCATED = exports.RANGE_UINT32_OVERFLOW = exports.RANGE_SIZE_OVERFLOW = exports.RANGE_INVALID_UTF8 = exports.RANGE_INT64_UNDERFLOW = exports.RANGE_INT32_OVERFLOW = exports.PTR_WRONG_STRUCT_PTR_SIZE = exports.PTR_WRONG_STRUCT_DATA_SIZE = exports.PTR_WRONG_COMPOSITE_PTR_SIZE = exports.PTR_WRONG_COMPOSITE_DATA_SIZE = exports.PTR_WRONG_POINTER_TYPE = exports.PTR_WRONG_LIST_TYPE = exports.PTR_TRAVERSAL_LIMIT_EXCEEDED = exports.PTR_STRUCT_POINTER_OUT_OF_BOUNDS = exports.PTR_STRUCT_DATA_OUT_OF_BOUNDS = exports.PTR_OFFSET_OUT_OF_BOUNDS = exports.PTR_INVALID_UNION_ACCESS = exports.PTR_INVALID_POINTER_TYPE = exports.PTR_INVALID_LIST_SIZE = exports.PTR_INVALID_FAR_TARGET = exports.PTR_INIT_NON_GROUP = exports.PTR_INIT_COMPOSITE_STRUCT = exports.PTR_DISOWN_COMPOSITE_STRUCT = exports.PTR_DEPTH_LIMIT_EXCEEDED = exports.PTR_COMPOSITE_SIZE_UNDEFINED = exports.PTR_ALREADY_ADOPTED = exports.PTR_ADOPT_WRONG_MESSAGE = exports.PTR_ADOPT_COMPOSITE_STRUCT = exports.NOT_IMPLEMENTED = exports.MSG_SEGMENT_TOO_SMALL = exports.MSG_SEGMENT_OUT_OF_BOUNDS = exports.MSG_PACK_NOT_WORD_ALIGNED = exports.MSG_NO_SEGMENTS_IN_ARENA = exports.MSG_INVALID_FRAME_HEADER = exports.assertNever = exports.INVARIANT_UNREACHABLE_CODE = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const debug_1 = tslib_1.__importDefault(require("debug"));
|
||||
const constants_1 = require("./constants");
|
||||
const trace = debug_1.default("capnp:errors");
|
||||
trace("load");
|
||||
// Invariant violations (sometimes known as "precondition failed").
|
||||
//
|
||||
// All right, hold up the brakes. This is a serious 1 === 0 WHAT THE FAILURE moment here. Tell the SO's you won't be
|
||||
// home for dinner.
|
||||
exports.INVARIANT_UNREACHABLE_CODE = "CAPNP-TS000 Unreachable code detected.";
|
||||
function assertNever(n) {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
throw new Error(exports.INVARIANT_UNREACHABLE_CODE + ` (never block hit with: ${n})`);
|
||||
}
|
||||
exports.assertNever = assertNever;
|
||||
// Message errors.
|
||||
//
|
||||
// Now who told you it would be a good idea to fuzz the inputs? You just made the program sad.
|
||||
exports.MSG_INVALID_FRAME_HEADER = "CAPNP-TS001 Attempted to parse an invalid message frame header; are you sure this is a Cap'n Proto message?";
|
||||
exports.MSG_NO_SEGMENTS_IN_ARENA = "CAPNP-TS002 Attempted to preallocate a message with no segments in the arena.";
|
||||
exports.MSG_PACK_NOT_WORD_ALIGNED = "CAPNP-TS003 Attempted to pack a message that was not word-aligned.";
|
||||
exports.MSG_SEGMENT_OUT_OF_BOUNDS = "CAPNP-TS004 Segment ID %X is out of bounds for message %s.";
|
||||
exports.MSG_SEGMENT_TOO_SMALL = "CAPNP-TS005 First segment must have at least enough room to hold the root pointer (8 bytes).";
|
||||
// Used for methods that are not yet implemented.
|
||||
//
|
||||
// My bad. I'll get to it. Eventually.
|
||||
exports.NOT_IMPLEMENTED = "CAPNP-TS006 %s is not implemented.";
|
||||
// Pointer-related errors.
|
||||
//
|
||||
// Look, this is probably the hardest part of the code. Cut some slack here! You probably found a bug.
|
||||
exports.PTR_ADOPT_COMPOSITE_STRUCT = "CAPNP-TS007 Attempted to adopt a struct into a composite list (%s).";
|
||||
exports.PTR_ADOPT_WRONG_MESSAGE = "CAPNP-TS008 Attempted to adopt %s into a pointer in a different message %s.";
|
||||
exports.PTR_ALREADY_ADOPTED = "CAPNP-TS009 Attempted to adopt %s more than once.";
|
||||
exports.PTR_COMPOSITE_SIZE_UNDEFINED = "CAPNP-TS010 Attempted to set a composite list without providing a composite element size.";
|
||||
exports.PTR_DEPTH_LIMIT_EXCEEDED = "CAPNP-TS011 Nesting depth limit exceeded for %s.";
|
||||
exports.PTR_DISOWN_COMPOSITE_STRUCT = "CAPNP-TS012 Attempted to disown a struct member from a composite list (%s).";
|
||||
exports.PTR_INIT_COMPOSITE_STRUCT = "CAPNP-TS013 Attempted to initialize a struct member from a composite list (%s).";
|
||||
exports.PTR_INIT_NON_GROUP = "CAPNP-TS014 Attempted to initialize a group field with a non-group struct class.";
|
||||
exports.PTR_INVALID_FAR_TARGET = "CAPNP-TS015 Target of a far pointer (%s) is another far pointer.";
|
||||
exports.PTR_INVALID_LIST_SIZE = "CAPNP-TS016 Invalid list element size: %x.";
|
||||
exports.PTR_INVALID_POINTER_TYPE = "CAPNP-TS017 Invalid pointer type: %x.";
|
||||
exports.PTR_INVALID_UNION_ACCESS = "CAPNP-TS018 Attempted to access getter on %s for union field %s that is not currently set (wanted: %d, found: %d).";
|
||||
exports.PTR_OFFSET_OUT_OF_BOUNDS = "CAPNP-TS019 Pointer offset %a is out of bounds for underlying buffer.";
|
||||
exports.PTR_STRUCT_DATA_OUT_OF_BOUNDS = "CAPNP-TS020 Attempted to access out-of-bounds struct data (struct: %s, %d bytes at %a, data words: %d).";
|
||||
exports.PTR_STRUCT_POINTER_OUT_OF_BOUNDS = "CAPNP-TS021 Attempted to access out-of-bounds struct pointer (%s, index: %d, length: %d).";
|
||||
exports.PTR_TRAVERSAL_LIMIT_EXCEEDED = "CAPNP-TS022 Traversal limit exceeded! Slow down! %s";
|
||||
exports.PTR_WRONG_LIST_TYPE = "CAPNP-TS023 Cannot convert %s to a %s list.";
|
||||
exports.PTR_WRONG_POINTER_TYPE = "CAPNP-TS024 Attempted to convert pointer %s to a %s type.";
|
||||
exports.PTR_WRONG_COMPOSITE_DATA_SIZE = "CAPNP-TS025 Attempted to convert %s to a composite list with the wrong data size (found: %d).";
|
||||
exports.PTR_WRONG_COMPOSITE_PTR_SIZE = "CAPNP-TS026 Attempted to convert %s to a composite list with the wrong pointer size (found: %d).";
|
||||
exports.PTR_WRONG_STRUCT_DATA_SIZE = "CAPNP-TS027 Attempted to convert %s to a struct with the wrong data size (found: %d).";
|
||||
exports.PTR_WRONG_STRUCT_PTR_SIZE = "CAPNP-TS028 Attempted to convert %s to a struct with the wrong pointer size (found: %d).";
|
||||
// Custom error messages for the built-in `RangeError` class.
|
||||
//
|
||||
// You don't get a witty comment with these.
|
||||
exports.RANGE_INT32_OVERFLOW = "CAPNP-TS029 32-bit signed integer overflow detected.";
|
||||
exports.RANGE_INT64_UNDERFLOW = "CAPNP-TS030 Buffer is not large enough to hold a word.";
|
||||
exports.RANGE_INVALID_UTF8 = "CAPNP-TS031 Invalid UTF-8 code sequence detected.";
|
||||
exports.RANGE_SIZE_OVERFLOW = `CAPNP-TS032 Size %x exceeds maximum ${constants_1.MAX_SEGMENT_LENGTH.toString(16)}.`;
|
||||
exports.RANGE_UINT32_OVERFLOW = "CAPNP-TS033 32-bit unsigned integer overflow detected.";
|
||||
// Segment-related errors.
|
||||
//
|
||||
// These suck. Deal with it.
|
||||
exports.SEG_BUFFER_NOT_ALLOCATED = "CAPNP-TS034 allocate() needs to be called at least once before getting a buffer.";
|
||||
exports.SEG_GET_NON_ZERO_SINGLE = "CAPNP-TS035 Attempted to get a segment other than 0 (%d) from a single segment arena.";
|
||||
exports.SEG_ID_OUT_OF_BOUNDS = "CAPNP-TS036 Attempted to get an out-of-bounds segment (%d).";
|
||||
exports.SEG_NOT_WORD_ALIGNED = "CAPNP-TS037 Segment buffer length %d is not a multiple of 8.";
|
||||
exports.SEG_REPLACEMENT_BUFFER_TOO_SMALL = "CAPNP-TS038 Attempted to replace a segment buffer with one that is smaller than the allocated space.";
|
||||
exports.SEG_SIZE_OVERFLOW = `CAPNP-TS039 Requested size %x exceeds maximum value (${constants_1.MAX_SEGMENT_LENGTH}).`;
|
||||
// Custom error messages for the built-in `TypeError` class.
|
||||
//
|
||||
// If it looks like a duck, quacks like an elephant, and has hooves for feet, it's probably JavaScript.
|
||||
exports.TYPE_COMPOSITE_SIZE_UNDEFINED = "CAPNP-TS040 Must provide a composite element size for composite list pointers.";
|
||||
exports.TYPE_GET_GENERIC_LIST = "CAPNP-TS041 Attempted to call get() on a generic list.";
|
||||
exports.TYPE_SET_GENERIC_LIST = "CAPNP-TS042 Attempted to call set() on a generic list.";
|
||||
exports.PTR_WRITE_CONST_LIST = "CAPNP-TS043 Attempted to write to a const list.";
|
||||
exports.PTR_WRITE_CONST_STRUCT = "CAPNP-TS044 Attempted to write to a const struct.";
|
||||
//# sourceMappingURL=errors.js.map
|
1
node_modules/capnp-ts/src/errors.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/errors.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"errors.js","sourceRoot":"","sources":["errors.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;AAEH,0DAA8B;AAE9B,2CAAiD;AAEjD,MAAM,KAAK,GAAG,eAAS,CAAC,cAAc,CAAC,CAAC;AACxC,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,mEAAmE;AACnE,EAAE;AACF,oHAAoH;AACpH,mBAAmB;AAEN,QAAA,0BAA0B,GAAG,wCAAwC,CAAC;AAEnF,SAAgB,WAAW,CAAC,CAAQ;IAClC,4EAA4E;IAC5E,MAAM,IAAI,KAAK,CAAC,kCAA0B,GAAG,2BAA2B,CAAC,GAAG,CAAC,CAAC;AAChF,CAAC;AAHD,kCAGC;AAED,kBAAkB;AAClB,EAAE;AACF,8FAA8F;AAEjF,QAAA,wBAAwB,GACnC,6GAA6G,CAAC;AACnG,QAAA,wBAAwB,GAAG,+EAA+E,CAAC;AAC3G,QAAA,yBAAyB,GAAG,oEAAoE,CAAC;AACjG,QAAA,yBAAyB,GAAG,4DAA4D,CAAC;AACzF,QAAA,qBAAqB,GAChC,8FAA8F,CAAC;AAEjG,iDAAiD;AACjD,EAAE;AACF,sCAAsC;AAEzB,QAAA,eAAe,GAAG,oCAAoC,CAAC;AAEpE,0BAA0B;AAC1B,EAAE;AACF,sGAAsG;AAEzF,QAAA,0BAA0B,GAAG,qEAAqE,CAAC;AACnG,QAAA,uBAAuB,GAAG,6EAA6E,CAAC;AACxG,QAAA,mBAAmB,GAAG,mDAAmD,CAAC;AAC1E,QAAA,4BAA4B,GACvC,2FAA2F,CAAC;AACjF,QAAA,wBAAwB,GAAG,kDAAkD,CAAC;AAC9E,QAAA,2BAA2B,GACtC,6EAA6E,CAAC;AACnE,QAAA,yBAAyB,GACpC,iFAAiF,CAAC;AACvE,QAAA,kBAAkB,GAAG,kFAAkF,CAAC;AACxG,QAAA,sBAAsB,GAAG,kEAAkE,CAAC;AAC5F,QAAA,qBAAqB,GAAG,4CAA4C,CAAC;AACrE,QAAA,wBAAwB,GAAG,uCAAuC,CAAC;AACnE,QAAA,wBAAwB,GACnC,oHAAoH,CAAC;AAC1G,QAAA,wBAAwB,GAAG,uEAAuE,CAAC;AACnG,QAAA,6BAA6B,GACxC,yGAAyG,CAAC;AAC/F,QAAA,gCAAgC,GAC3C,2FAA2F,CAAC;AACjF,QAAA,4BAA4B,GAAG,qDAAqD,CAAC;AACrF,QAAA,mBAAmB,GAAG,6CAA6C,CAAC;AACpE,QAAA,sBAAsB,GAAG,2DAA2D,CAAC;AACrF,QAAA,6BAA6B,GACxC,+FAA+F,CAAC;AACrF,QAAA,4BAA4B,GACvC,kGAAkG,CAAC;AACxF,QAAA,0BAA0B,GACrC,uFAAuF,CAAC;AAC7E,QAAA,yBAAyB,GACpC,0FAA0F,CAAC;AAE7F,6DAA6D;AAC7D,EAAE;AACF,4CAA4C;AAE/B,QAAA,oBAAoB,GAAG,sDAAsD,CAAC;AAC9E,QAAA,qBAAqB,GAAG,wDAAwD,CAAC;AACjF,QAAA,kBAAkB,GAAG,mDAAmD,CAAC;AACzE,QAAA,mBAAmB,GAAG,uCAAuC,8BAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC;AAChG,QAAA,qBAAqB,GAAG,wDAAwD,CAAC;AAE9F,0BAA0B;AAC1B,EAAE;AACF,4BAA4B;AAEf,QAAA,wBAAwB,GACnC,kFAAkF,CAAC;AACxE,QAAA,uBAAuB,GAClC,uFAAuF,CAAC;AAC7E,QAAA,oBAAoB,GAAG,6DAA6D,CAAC;AACrF,QAAA,oBAAoB,GAAG,8DAA8D,CAAC;AACtF,QAAA,gCAAgC,GAC3C,sGAAsG,CAAC;AAC5F,QAAA,iBAAiB,GAAG,wDAAwD,8BAAkB,IAAI,CAAC;AAEhH,4DAA4D;AAC5D,EAAE;AACF,uGAAuG;AAE1F,QAAA,6BAA6B,GACxC,gFAAgF,CAAC;AACtE,QAAA,qBAAqB,GAAG,wDAAwD,CAAC;AACjF,QAAA,qBAAqB,GAAG,wDAAwD,CAAC;AAEjF,QAAA,oBAAoB,GAAG,iDAAiD,CAAC;AACzE,QAAA,sBAAsB,GAAG,mDAAmD,CAAC"}
|
115
node_modules/capnp-ts/src/errors.ts
generated
vendored
Normal file
115
node_modules/capnp-ts/src/errors.ts
generated
vendored
Normal file
|
@ -0,0 +1,115 @@
|
|||
/**
|
||||
* This file contains all the error strings used in the library. Also contains silliness.
|
||||
*
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
|
||||
import initTrace from "debug";
|
||||
|
||||
import { MAX_SEGMENT_LENGTH } from "./constants";
|
||||
|
||||
const trace = initTrace("capnp:errors");
|
||||
trace("load");
|
||||
|
||||
// Invariant violations (sometimes known as "precondition failed").
|
||||
//
|
||||
// All right, hold up the brakes. This is a serious 1 === 0 WHAT THE FAILURE moment here. Tell the SO's you won't be
|
||||
// home for dinner.
|
||||
|
||||
export const INVARIANT_UNREACHABLE_CODE = "CAPNP-TS000 Unreachable code detected.";
|
||||
|
||||
export function assertNever(n: never): never {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
throw new Error(INVARIANT_UNREACHABLE_CODE + ` (never block hit with: ${n})`);
|
||||
}
|
||||
|
||||
// Message errors.
|
||||
//
|
||||
// Now who told you it would be a good idea to fuzz the inputs? You just made the program sad.
|
||||
|
||||
export const MSG_INVALID_FRAME_HEADER =
|
||||
"CAPNP-TS001 Attempted to parse an invalid message frame header; are you sure this is a Cap'n Proto message?";
|
||||
export const MSG_NO_SEGMENTS_IN_ARENA = "CAPNP-TS002 Attempted to preallocate a message with no segments in the arena.";
|
||||
export const MSG_PACK_NOT_WORD_ALIGNED = "CAPNP-TS003 Attempted to pack a message that was not word-aligned.";
|
||||
export const MSG_SEGMENT_OUT_OF_BOUNDS = "CAPNP-TS004 Segment ID %X is out of bounds for message %s.";
|
||||
export const MSG_SEGMENT_TOO_SMALL =
|
||||
"CAPNP-TS005 First segment must have at least enough room to hold the root pointer (8 bytes).";
|
||||
|
||||
// Used for methods that are not yet implemented.
|
||||
//
|
||||
// My bad. I'll get to it. Eventually.
|
||||
|
||||
export const NOT_IMPLEMENTED = "CAPNP-TS006 %s is not implemented.";
|
||||
|
||||
// Pointer-related errors.
|
||||
//
|
||||
// Look, this is probably the hardest part of the code. Cut some slack here! You probably found a bug.
|
||||
|
||||
export const PTR_ADOPT_COMPOSITE_STRUCT = "CAPNP-TS007 Attempted to adopt a struct into a composite list (%s).";
|
||||
export const PTR_ADOPT_WRONG_MESSAGE = "CAPNP-TS008 Attempted to adopt %s into a pointer in a different message %s.";
|
||||
export const PTR_ALREADY_ADOPTED = "CAPNP-TS009 Attempted to adopt %s more than once.";
|
||||
export const PTR_COMPOSITE_SIZE_UNDEFINED =
|
||||
"CAPNP-TS010 Attempted to set a composite list without providing a composite element size.";
|
||||
export const PTR_DEPTH_LIMIT_EXCEEDED = "CAPNP-TS011 Nesting depth limit exceeded for %s.";
|
||||
export const PTR_DISOWN_COMPOSITE_STRUCT =
|
||||
"CAPNP-TS012 Attempted to disown a struct member from a composite list (%s).";
|
||||
export const PTR_INIT_COMPOSITE_STRUCT =
|
||||
"CAPNP-TS013 Attempted to initialize a struct member from a composite list (%s).";
|
||||
export const PTR_INIT_NON_GROUP = "CAPNP-TS014 Attempted to initialize a group field with a non-group struct class.";
|
||||
export const PTR_INVALID_FAR_TARGET = "CAPNP-TS015 Target of a far pointer (%s) is another far pointer.";
|
||||
export const PTR_INVALID_LIST_SIZE = "CAPNP-TS016 Invalid list element size: %x.";
|
||||
export const PTR_INVALID_POINTER_TYPE = "CAPNP-TS017 Invalid pointer type: %x.";
|
||||
export const PTR_INVALID_UNION_ACCESS =
|
||||
"CAPNP-TS018 Attempted to access getter on %s for union field %s that is not currently set (wanted: %d, found: %d).";
|
||||
export const PTR_OFFSET_OUT_OF_BOUNDS = "CAPNP-TS019 Pointer offset %a is out of bounds for underlying buffer.";
|
||||
export const PTR_STRUCT_DATA_OUT_OF_BOUNDS =
|
||||
"CAPNP-TS020 Attempted to access out-of-bounds struct data (struct: %s, %d bytes at %a, data words: %d).";
|
||||
export const PTR_STRUCT_POINTER_OUT_OF_BOUNDS =
|
||||
"CAPNP-TS021 Attempted to access out-of-bounds struct pointer (%s, index: %d, length: %d).";
|
||||
export const PTR_TRAVERSAL_LIMIT_EXCEEDED = "CAPNP-TS022 Traversal limit exceeded! Slow down! %s";
|
||||
export const PTR_WRONG_LIST_TYPE = "CAPNP-TS023 Cannot convert %s to a %s list.";
|
||||
export const PTR_WRONG_POINTER_TYPE = "CAPNP-TS024 Attempted to convert pointer %s to a %s type.";
|
||||
export const PTR_WRONG_COMPOSITE_DATA_SIZE =
|
||||
"CAPNP-TS025 Attempted to convert %s to a composite list with the wrong data size (found: %d).";
|
||||
export const PTR_WRONG_COMPOSITE_PTR_SIZE =
|
||||
"CAPNP-TS026 Attempted to convert %s to a composite list with the wrong pointer size (found: %d).";
|
||||
export const PTR_WRONG_STRUCT_DATA_SIZE =
|
||||
"CAPNP-TS027 Attempted to convert %s to a struct with the wrong data size (found: %d).";
|
||||
export const PTR_WRONG_STRUCT_PTR_SIZE =
|
||||
"CAPNP-TS028 Attempted to convert %s to a struct with the wrong pointer size (found: %d).";
|
||||
|
||||
// Custom error messages for the built-in `RangeError` class.
|
||||
//
|
||||
// You don't get a witty comment with these.
|
||||
|
||||
export const RANGE_INT32_OVERFLOW = "CAPNP-TS029 32-bit signed integer overflow detected.";
|
||||
export const RANGE_INT64_UNDERFLOW = "CAPNP-TS030 Buffer is not large enough to hold a word.";
|
||||
export const RANGE_INVALID_UTF8 = "CAPNP-TS031 Invalid UTF-8 code sequence detected.";
|
||||
export const RANGE_SIZE_OVERFLOW = `CAPNP-TS032 Size %x exceeds maximum ${MAX_SEGMENT_LENGTH.toString(16)}.`;
|
||||
export const RANGE_UINT32_OVERFLOW = "CAPNP-TS033 32-bit unsigned integer overflow detected.";
|
||||
|
||||
// Segment-related errors.
|
||||
//
|
||||
// These suck. Deal with it.
|
||||
|
||||
export const SEG_BUFFER_NOT_ALLOCATED =
|
||||
"CAPNP-TS034 allocate() needs to be called at least once before getting a buffer.";
|
||||
export const SEG_GET_NON_ZERO_SINGLE =
|
||||
"CAPNP-TS035 Attempted to get a segment other than 0 (%d) from a single segment arena.";
|
||||
export const SEG_ID_OUT_OF_BOUNDS = "CAPNP-TS036 Attempted to get an out-of-bounds segment (%d).";
|
||||
export const SEG_NOT_WORD_ALIGNED = "CAPNP-TS037 Segment buffer length %d is not a multiple of 8.";
|
||||
export const SEG_REPLACEMENT_BUFFER_TOO_SMALL =
|
||||
"CAPNP-TS038 Attempted to replace a segment buffer with one that is smaller than the allocated space.";
|
||||
export const SEG_SIZE_OVERFLOW = `CAPNP-TS039 Requested size %x exceeds maximum value (${MAX_SEGMENT_LENGTH}).`;
|
||||
|
||||
// Custom error messages for the built-in `TypeError` class.
|
||||
//
|
||||
// If it looks like a duck, quacks like an elephant, and has hooves for feet, it's probably JavaScript.
|
||||
|
||||
export const TYPE_COMPOSITE_SIZE_UNDEFINED =
|
||||
"CAPNP-TS040 Must provide a composite element size for composite list pointers.";
|
||||
export const TYPE_GET_GENERIC_LIST = "CAPNP-TS041 Attempted to call get() on a generic list.";
|
||||
export const TYPE_SET_GENERIC_LIST = "CAPNP-TS042 Attempted to call set() on a generic list.";
|
||||
|
||||
export const PTR_WRITE_CONST_LIST = "CAPNP-TS043 Attempted to write to a const list.";
|
||||
export const PTR_WRITE_CONST_STRUCT = "CAPNP-TS044 Attempted to write to a const struct.";
|
5
node_modules/capnp-ts/src/index.d.ts
generated
vendored
Normal file
5
node_modules/capnp-ts/src/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
export { ListElementSize, Message, ObjectSize, readRawPointer, AnyPointerList, BoolList, CompositeList, Data, DataList, Float32List, Float64List, Int16List, Int32List, Int64List, Int8List, Interface, InterfaceList, List, ListCtor, Orphan, PointerList, PointerType, Pointer, Struct, StructCtor, Text, TextList, Uint16List, Uint32List, Uint64List, Uint8List, VoidList, Void, getBitMask, getFloat32Mask, getFloat64Mask, getInt16Mask, getInt32Mask, getInt64Mask, getInt8Mask, getUint16Mask, getUint32Mask, getUint64Mask, getUint8Mask, } from "./serialization";
|
||||
export { Int64, Uint64 } from "./types";
|
53
node_modules/capnp-ts/src/index.js
generated
vendored
Normal file
53
node_modules/capnp-ts/src/index.js
generated
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
"use strict";
|
||||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Uint64 = exports.Int64 = exports.getUint8Mask = exports.getUint64Mask = exports.getUint32Mask = exports.getUint16Mask = exports.getInt8Mask = exports.getInt64Mask = exports.getInt32Mask = exports.getInt16Mask = exports.getFloat64Mask = exports.getFloat32Mask = exports.getBitMask = exports.Void = exports.VoidList = exports.Uint8List = exports.Uint64List = exports.Uint32List = exports.Uint16List = exports.TextList = exports.Text = exports.Struct = exports.Pointer = exports.PointerType = exports.PointerList = exports.Orphan = exports.List = exports.InterfaceList = exports.Interface = exports.Int8List = exports.Int64List = exports.Int32List = exports.Int16List = exports.Float64List = exports.Float32List = exports.DataList = exports.Data = exports.CompositeList = exports.BoolList = exports.AnyPointerList = exports.readRawPointer = exports.ObjectSize = exports.Message = exports.ListElementSize = void 0;
|
||||
var serialization_1 = require("./serialization");
|
||||
Object.defineProperty(exports, "ListElementSize", { enumerable: true, get: function () { return serialization_1.ListElementSize; } });
|
||||
Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return serialization_1.Message; } });
|
||||
Object.defineProperty(exports, "ObjectSize", { enumerable: true, get: function () { return serialization_1.ObjectSize; } });
|
||||
Object.defineProperty(exports, "readRawPointer", { enumerable: true, get: function () { return serialization_1.readRawPointer; } });
|
||||
Object.defineProperty(exports, "AnyPointerList", { enumerable: true, get: function () { return serialization_1.AnyPointerList; } });
|
||||
Object.defineProperty(exports, "BoolList", { enumerable: true, get: function () { return serialization_1.BoolList; } });
|
||||
Object.defineProperty(exports, "CompositeList", { enumerable: true, get: function () { return serialization_1.CompositeList; } });
|
||||
Object.defineProperty(exports, "Data", { enumerable: true, get: function () { return serialization_1.Data; } });
|
||||
Object.defineProperty(exports, "DataList", { enumerable: true, get: function () { return serialization_1.DataList; } });
|
||||
Object.defineProperty(exports, "Float32List", { enumerable: true, get: function () { return serialization_1.Float32List; } });
|
||||
Object.defineProperty(exports, "Float64List", { enumerable: true, get: function () { return serialization_1.Float64List; } });
|
||||
Object.defineProperty(exports, "Int16List", { enumerable: true, get: function () { return serialization_1.Int16List; } });
|
||||
Object.defineProperty(exports, "Int32List", { enumerable: true, get: function () { return serialization_1.Int32List; } });
|
||||
Object.defineProperty(exports, "Int64List", { enumerable: true, get: function () { return serialization_1.Int64List; } });
|
||||
Object.defineProperty(exports, "Int8List", { enumerable: true, get: function () { return serialization_1.Int8List; } });
|
||||
Object.defineProperty(exports, "Interface", { enumerable: true, get: function () { return serialization_1.Interface; } });
|
||||
Object.defineProperty(exports, "InterfaceList", { enumerable: true, get: function () { return serialization_1.InterfaceList; } });
|
||||
Object.defineProperty(exports, "List", { enumerable: true, get: function () { return serialization_1.List; } });
|
||||
Object.defineProperty(exports, "Orphan", { enumerable: true, get: function () { return serialization_1.Orphan; } });
|
||||
Object.defineProperty(exports, "PointerList", { enumerable: true, get: function () { return serialization_1.PointerList; } });
|
||||
Object.defineProperty(exports, "PointerType", { enumerable: true, get: function () { return serialization_1.PointerType; } });
|
||||
Object.defineProperty(exports, "Pointer", { enumerable: true, get: function () { return serialization_1.Pointer; } });
|
||||
Object.defineProperty(exports, "Struct", { enumerable: true, get: function () { return serialization_1.Struct; } });
|
||||
Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return serialization_1.Text; } });
|
||||
Object.defineProperty(exports, "TextList", { enumerable: true, get: function () { return serialization_1.TextList; } });
|
||||
Object.defineProperty(exports, "Uint16List", { enumerable: true, get: function () { return serialization_1.Uint16List; } });
|
||||
Object.defineProperty(exports, "Uint32List", { enumerable: true, get: function () { return serialization_1.Uint32List; } });
|
||||
Object.defineProperty(exports, "Uint64List", { enumerable: true, get: function () { return serialization_1.Uint64List; } });
|
||||
Object.defineProperty(exports, "Uint8List", { enumerable: true, get: function () { return serialization_1.Uint8List; } });
|
||||
Object.defineProperty(exports, "VoidList", { enumerable: true, get: function () { return serialization_1.VoidList; } });
|
||||
Object.defineProperty(exports, "Void", { enumerable: true, get: function () { return serialization_1.Void; } });
|
||||
Object.defineProperty(exports, "getBitMask", { enumerable: true, get: function () { return serialization_1.getBitMask; } });
|
||||
Object.defineProperty(exports, "getFloat32Mask", { enumerable: true, get: function () { return serialization_1.getFloat32Mask; } });
|
||||
Object.defineProperty(exports, "getFloat64Mask", { enumerable: true, get: function () { return serialization_1.getFloat64Mask; } });
|
||||
Object.defineProperty(exports, "getInt16Mask", { enumerable: true, get: function () { return serialization_1.getInt16Mask; } });
|
||||
Object.defineProperty(exports, "getInt32Mask", { enumerable: true, get: function () { return serialization_1.getInt32Mask; } });
|
||||
Object.defineProperty(exports, "getInt64Mask", { enumerable: true, get: function () { return serialization_1.getInt64Mask; } });
|
||||
Object.defineProperty(exports, "getInt8Mask", { enumerable: true, get: function () { return serialization_1.getInt8Mask; } });
|
||||
Object.defineProperty(exports, "getUint16Mask", { enumerable: true, get: function () { return serialization_1.getUint16Mask; } });
|
||||
Object.defineProperty(exports, "getUint32Mask", { enumerable: true, get: function () { return serialization_1.getUint32Mask; } });
|
||||
Object.defineProperty(exports, "getUint64Mask", { enumerable: true, get: function () { return serialization_1.getUint64Mask; } });
|
||||
Object.defineProperty(exports, "getUint8Mask", { enumerable: true, get: function () { return serialization_1.getUint8Mask; } });
|
||||
var types_1 = require("./types");
|
||||
Object.defineProperty(exports, "Int64", { enumerable: true, get: function () { return types_1.Int64; } });
|
||||
Object.defineProperty(exports, "Uint64", { enumerable: true, get: function () { return types_1.Uint64; } });
|
||||
//# sourceMappingURL=index.js.map
|
1
node_modules/capnp-ts/src/index.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/index.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iDA6CyB;AA5CvB,gHAAA,eAAe,OAAA;AACf,wGAAA,OAAO,OAAA;AACP,2GAAA,UAAU,OAAA;AACV,+GAAA,cAAc,OAAA;AACd,+GAAA,cAAc,OAAA;AACd,yGAAA,QAAQ,OAAA;AACR,8GAAA,aAAa,OAAA;AACb,qGAAA,IAAI,OAAA;AACJ,yGAAA,QAAQ,OAAA;AACR,4GAAA,WAAW,OAAA;AACX,4GAAA,WAAW,OAAA;AACX,0GAAA,SAAS,OAAA;AACT,0GAAA,SAAS,OAAA;AACT,0GAAA,SAAS,OAAA;AACT,yGAAA,QAAQ,OAAA;AACR,0GAAA,SAAS,OAAA;AACT,8GAAA,aAAa,OAAA;AACb,qGAAA,IAAI,OAAA;AAEJ,uGAAA,MAAM,OAAA;AACN,4GAAA,WAAW,OAAA;AACX,4GAAA,WAAW,OAAA;AACX,wGAAA,OAAO,OAAA;AACP,uGAAA,MAAM,OAAA;AAEN,qGAAA,IAAI,OAAA;AACJ,yGAAA,QAAQ,OAAA;AACR,2GAAA,UAAU,OAAA;AACV,2GAAA,UAAU,OAAA;AACV,2GAAA,UAAU,OAAA;AACV,0GAAA,SAAS,OAAA;AACT,yGAAA,QAAQ,OAAA;AACR,qGAAA,IAAI,OAAA;AACJ,2GAAA,UAAU,OAAA;AACV,+GAAA,cAAc,OAAA;AACd,+GAAA,cAAc,OAAA;AACd,6GAAA,YAAY,OAAA;AACZ,6GAAA,YAAY,OAAA;AACZ,6GAAA,YAAY,OAAA;AACZ,4GAAA,WAAW,OAAA;AACX,8GAAA,aAAa,OAAA;AACb,8GAAA,aAAa,OAAA;AACb,8GAAA,aAAa,OAAA;AACb,6GAAA,YAAY,OAAA;AAGd,iCAAwC;AAA/B,8FAAA,KAAK,OAAA;AAAE,+FAAA,MAAM,OAAA"}
|
52
node_modules/capnp-ts/src/index.ts
generated
vendored
Normal file
52
node_modules/capnp-ts/src/index.ts
generated
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
|
||||
export {
|
||||
ListElementSize,
|
||||
Message,
|
||||
ObjectSize,
|
||||
readRawPointer,
|
||||
AnyPointerList,
|
||||
BoolList,
|
||||
CompositeList,
|
||||
Data,
|
||||
DataList,
|
||||
Float32List,
|
||||
Float64List,
|
||||
Int16List,
|
||||
Int32List,
|
||||
Int64List,
|
||||
Int8List,
|
||||
Interface,
|
||||
InterfaceList,
|
||||
List,
|
||||
ListCtor,
|
||||
Orphan,
|
||||
PointerList,
|
||||
PointerType,
|
||||
Pointer,
|
||||
Struct,
|
||||
StructCtor,
|
||||
Text,
|
||||
TextList,
|
||||
Uint16List,
|
||||
Uint32List,
|
||||
Uint64List,
|
||||
Uint8List,
|
||||
VoidList,
|
||||
Void,
|
||||
getBitMask,
|
||||
getFloat32Mask,
|
||||
getFloat64Mask,
|
||||
getInt16Mask,
|
||||
getInt32Mask,
|
||||
getInt64Mask,
|
||||
getInt8Mask,
|
||||
getUint16Mask,
|
||||
getUint32Mask,
|
||||
getUint64Mask,
|
||||
getUint8Mask,
|
||||
} from "./serialization";
|
||||
|
||||
export { Int64, Uint64 } from "./types";
|
3
node_modules/capnp-ts/src/serialization/arena/any-arena.d.ts
generated
vendored
Normal file
3
node_modules/capnp-ts/src/serialization/arena/any-arena.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
import { MultiSegmentArena } from "./multi-segment-arena";
|
||||
import { SingleSegmentArena } from "./single-segment-arena";
|
||||
export declare type AnyArena = MultiSegmentArena | SingleSegmentArena;
|
3
node_modules/capnp-ts/src/serialization/arena/any-arena.js
generated
vendored
Normal file
3
node_modules/capnp-ts/src/serialization/arena/any-arena.js
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=any-arena.js.map
|
1
node_modules/capnp-ts/src/serialization/arena/any-arena.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/arena/any-arena.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"any-arena.js","sourceRoot":"","sources":["any-arena.ts"],"names":[],"mappings":""}
|
4
node_modules/capnp-ts/src/serialization/arena/any-arena.ts
generated
vendored
Normal file
4
node_modules/capnp-ts/src/serialization/arena/any-arena.ts
generated
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
import { MultiSegmentArena } from "./multi-segment-arena";
|
||||
import { SingleSegmentArena } from "./single-segment-arena";
|
||||
|
||||
export type AnyArena = MultiSegmentArena | SingleSegmentArena;
|
18
node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.d.ts
generated
vendored
Normal file
18
node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
export declare class ArenaAllocationResult {
|
||||
/**
|
||||
* The newly allocated buffer. This buffer might be a copy of an existing segment's buffer with free space appended.
|
||||
*
|
||||
* @type {ArrayBuffer}
|
||||
*/
|
||||
readonly buffer: ArrayBuffer;
|
||||
/**
|
||||
* The id of the newly-allocated segment.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
readonly id: number;
|
||||
constructor(id: number, buffer: ArrayBuffer);
|
||||
}
|
19
node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.js
generated
vendored
Normal file
19
node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.js
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
"use strict";
|
||||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ArenaAllocationResult = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const debug_1 = tslib_1.__importDefault(require("debug"));
|
||||
const trace = debug_1.default("capnp:serialization:arena:arena-allocation-result");
|
||||
trace("load");
|
||||
class ArenaAllocationResult {
|
||||
constructor(id, buffer) {
|
||||
this.id = id;
|
||||
this.buffer = buffer;
|
||||
trace("new", this);
|
||||
}
|
||||
}
|
||||
exports.ArenaAllocationResult = ArenaAllocationResult;
|
||||
//# sourceMappingURL=arena-allocation-result.js.map
|
1
node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"arena-allocation-result.js","sourceRoot":"","sources":["arena-allocation-result.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,MAAM,KAAK,GAAG,eAAS,CAAC,mDAAmD,CAAC,CAAC;AAC7E,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,qBAAqB;IAiBhC,YAAY,EAAU,EAAE,MAAmB;QACzC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACrB,CAAC;CACF;AAvBD,sDAuBC"}
|
33
node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.ts
generated
vendored
Normal file
33
node_modules/capnp-ts/src/serialization/arena/arena-allocation-result.ts
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
|
||||
import initTrace from "debug";
|
||||
|
||||
const trace = initTrace("capnp:serialization:arena:arena-allocation-result");
|
||||
trace("load");
|
||||
|
||||
export class ArenaAllocationResult {
|
||||
/**
|
||||
* The newly allocated buffer. This buffer might be a copy of an existing segment's buffer with free space appended.
|
||||
*
|
||||
* @type {ArrayBuffer}
|
||||
*/
|
||||
|
||||
readonly buffer: ArrayBuffer;
|
||||
|
||||
/**
|
||||
* The id of the newly-allocated segment.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
|
||||
readonly id: number;
|
||||
|
||||
constructor(id: number, buffer: ArrayBuffer) {
|
||||
this.id = id;
|
||||
this.buffer = buffer;
|
||||
|
||||
trace("new", this);
|
||||
}
|
||||
}
|
4
node_modules/capnp-ts/src/serialization/arena/arena-kind.d.ts
generated
vendored
Normal file
4
node_modules/capnp-ts/src/serialization/arena/arena-kind.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
export declare enum ArenaKind {
|
||||
SINGLE_SEGMENT = 0,
|
||||
MULTI_SEGMENT = 1
|
||||
}
|
9
node_modules/capnp-ts/src/serialization/arena/arena-kind.js
generated
vendored
Normal file
9
node_modules/capnp-ts/src/serialization/arena/arena-kind.js
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ArenaKind = void 0;
|
||||
var ArenaKind;
|
||||
(function (ArenaKind) {
|
||||
ArenaKind[ArenaKind["SINGLE_SEGMENT"] = 0] = "SINGLE_SEGMENT";
|
||||
ArenaKind[ArenaKind["MULTI_SEGMENT"] = 1] = "MULTI_SEGMENT";
|
||||
})(ArenaKind = exports.ArenaKind || (exports.ArenaKind = {}));
|
||||
//# sourceMappingURL=arena-kind.js.map
|
1
node_modules/capnp-ts/src/serialization/arena/arena-kind.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/arena/arena-kind.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"arena-kind.js","sourceRoot":"","sources":["arena-kind.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,6DAAc,CAAA;IACd,2DAAa,CAAA;AACf,CAAC,EAHW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAGpB"}
|
4
node_modules/capnp-ts/src/serialization/arena/arena-kind.ts
generated
vendored
Normal file
4
node_modules/capnp-ts/src/serialization/arena/arena-kind.ts
generated
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
export enum ArenaKind {
|
||||
SINGLE_SEGMENT,
|
||||
MULTI_SEGMENT
|
||||
}
|
14
node_modules/capnp-ts/src/serialization/arena/arena.d.ts
generated
vendored
Normal file
14
node_modules/capnp-ts/src/serialization/arena/arena.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
import { Segment } from "../segment";
|
||||
import { AnyArena } from "./any-arena";
|
||||
import { ArenaAllocationResult } from "./arena-allocation-result";
|
||||
export declare abstract class Arena {
|
||||
static readonly allocate: typeof allocate;
|
||||
static readonly getBuffer: typeof getBuffer;
|
||||
static readonly getNumSegments: typeof getNumSegments;
|
||||
}
|
||||
export declare function allocate(minSize: number, segments: Segment[], a: AnyArena): ArenaAllocationResult;
|
||||
export declare function getBuffer(id: number, a: AnyArena): ArrayBuffer;
|
||||
export declare function getNumSegments(a: AnyArena): number;
|
54
node_modules/capnp-ts/src/serialization/arena/arena.js
generated
vendored
Normal file
54
node_modules/capnp-ts/src/serialization/arena/arena.js
generated
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
"use strict";
|
||||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getNumSegments = exports.getBuffer = exports.allocate = exports.Arena = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const debug_1 = tslib_1.__importDefault(require("debug"));
|
||||
const errors_1 = require("../../errors");
|
||||
const arena_kind_1 = require("./arena-kind");
|
||||
const multi_segment_arena_1 = require("./multi-segment-arena");
|
||||
const single_segment_arena_1 = require("./single-segment-arena");
|
||||
const trace = debug_1.default("capnp:arena");
|
||||
trace("load");
|
||||
class Arena {
|
||||
}
|
||||
exports.Arena = Arena;
|
||||
Arena.allocate = allocate;
|
||||
Arena.getBuffer = getBuffer;
|
||||
Arena.getNumSegments = getNumSegments;
|
||||
function allocate(minSize, segments, a) {
|
||||
switch (a.kind) {
|
||||
case arena_kind_1.ArenaKind.MULTI_SEGMENT:
|
||||
return multi_segment_arena_1.MultiSegmentArena.allocate(minSize, a);
|
||||
case arena_kind_1.ArenaKind.SINGLE_SEGMENT:
|
||||
return single_segment_arena_1.SingleSegmentArena.allocate(minSize, segments, a);
|
||||
default:
|
||||
return errors_1.assertNever(a);
|
||||
}
|
||||
}
|
||||
exports.allocate = allocate;
|
||||
function getBuffer(id, a) {
|
||||
switch (a.kind) {
|
||||
case arena_kind_1.ArenaKind.MULTI_SEGMENT:
|
||||
return multi_segment_arena_1.MultiSegmentArena.getBuffer(id, a);
|
||||
case arena_kind_1.ArenaKind.SINGLE_SEGMENT:
|
||||
return single_segment_arena_1.SingleSegmentArena.getBuffer(id, a);
|
||||
default:
|
||||
return errors_1.assertNever(a);
|
||||
}
|
||||
}
|
||||
exports.getBuffer = getBuffer;
|
||||
function getNumSegments(a) {
|
||||
switch (a.kind) {
|
||||
case arena_kind_1.ArenaKind.MULTI_SEGMENT:
|
||||
return multi_segment_arena_1.MultiSegmentArena.getNumSegments(a);
|
||||
case arena_kind_1.ArenaKind.SINGLE_SEGMENT:
|
||||
return single_segment_arena_1.SingleSegmentArena.getNumSegments();
|
||||
default:
|
||||
return errors_1.assertNever(a);
|
||||
}
|
||||
}
|
||||
exports.getNumSegments = getNumSegments;
|
||||
//# sourceMappingURL=arena.js.map
|
1
node_modules/capnp-ts/src/serialization/arena/arena.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/arena/arena.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"arena.js","sourceRoot":"","sources":["arena.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAC9B,yCAA2C;AAI3C,6CAAyC;AACzC,+DAA0D;AAC1D,iEAA4D;AAE5D,MAAM,KAAK,GAAG,eAAS,CAAC,aAAa,CAAC,CAAC;AACvC,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAsB,KAAK;;AAA3B,sBAIC;AAHiB,cAAQ,GAAG,QAAQ,CAAC;AACpB,eAAS,GAAG,SAAS,CAAC;AACtB,oBAAc,GAAG,cAAc,CAAC;AAGlD,SAAgB,QAAQ,CAAC,OAAe,EAAE,QAAmB,EAAE,CAAW;IACxE,QAAQ,CAAC,CAAC,IAAI,EAAE;QACd,KAAK,sBAAS,CAAC,aAAa;YAC1B,OAAO,uCAAiB,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAEhD,KAAK,sBAAS,CAAC,cAAc;YAC3B,OAAO,yCAAkB,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;QAE3D;YACE,OAAO,oBAAW,CAAC,CAAC,CAAC,CAAC;KACzB;AACH,CAAC;AAXD,4BAWC;AAED,SAAgB,SAAS,CAAC,EAAU,EAAE,CAAW;IAC/C,QAAQ,CAAC,CAAC,IAAI,EAAE;QACd,KAAK,sBAAS,CAAC,aAAa;YAC1B,OAAO,uCAAiB,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QAE5C,KAAK,sBAAS,CAAC,cAAc;YAC3B,OAAO,yCAAkB,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QAE7C;YACE,OAAO,oBAAW,CAAC,CAAC,CAAC,CAAC;KACzB;AACH,CAAC;AAXD,8BAWC;AAED,SAAgB,cAAc,CAAC,CAAW;IACxC,QAAQ,CAAC,CAAC,IAAI,EAAE;QACd,KAAK,sBAAS,CAAC,aAAa;YAC1B,OAAO,uCAAiB,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;QAE7C,KAAK,sBAAS,CAAC,cAAc;YAC3B,OAAO,yCAAkB,CAAC,cAAc,EAAE,CAAC;QAE7C;YACE,OAAO,oBAAW,CAAC,CAAC,CAAC,CAAC;KACzB;AACH,CAAC;AAXD,wCAWC"}
|
60
node_modules/capnp-ts/src/serialization/arena/arena.ts
generated
vendored
Normal file
60
node_modules/capnp-ts/src/serialization/arena/arena.ts
generated
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
|
||||
import initTrace from "debug";
|
||||
import { assertNever } from "../../errors";
|
||||
import { Segment } from "../segment";
|
||||
import { AnyArena } from "./any-arena";
|
||||
import { ArenaAllocationResult } from "./arena-allocation-result";
|
||||
import { ArenaKind } from "./arena-kind";
|
||||
import { MultiSegmentArena } from "./multi-segment-arena";
|
||||
import { SingleSegmentArena } from "./single-segment-arena";
|
||||
|
||||
const trace = initTrace("capnp:arena");
|
||||
trace("load");
|
||||
|
||||
export abstract class Arena {
|
||||
static readonly allocate = allocate;
|
||||
static readonly getBuffer = getBuffer;
|
||||
static readonly getNumSegments = getNumSegments;
|
||||
}
|
||||
|
||||
export function allocate(minSize: number, segments: Segment[], a: AnyArena): ArenaAllocationResult {
|
||||
switch (a.kind) {
|
||||
case ArenaKind.MULTI_SEGMENT:
|
||||
return MultiSegmentArena.allocate(minSize, a);
|
||||
|
||||
case ArenaKind.SINGLE_SEGMENT:
|
||||
return SingleSegmentArena.allocate(minSize, segments, a);
|
||||
|
||||
default:
|
||||
return assertNever(a);
|
||||
}
|
||||
}
|
||||
|
||||
export function getBuffer(id: number, a: AnyArena): ArrayBuffer {
|
||||
switch (a.kind) {
|
||||
case ArenaKind.MULTI_SEGMENT:
|
||||
return MultiSegmentArena.getBuffer(id, a);
|
||||
|
||||
case ArenaKind.SINGLE_SEGMENT:
|
||||
return SingleSegmentArena.getBuffer(id, a);
|
||||
|
||||
default:
|
||||
return assertNever(a);
|
||||
}
|
||||
}
|
||||
|
||||
export function getNumSegments(a: AnyArena): number {
|
||||
switch (a.kind) {
|
||||
case ArenaKind.MULTI_SEGMENT:
|
||||
return MultiSegmentArena.getNumSegments(a);
|
||||
|
||||
case ArenaKind.SINGLE_SEGMENT:
|
||||
return SingleSegmentArena.getNumSegments();
|
||||
|
||||
default:
|
||||
return assertNever(a);
|
||||
}
|
||||
}
|
8
node_modules/capnp-ts/src/serialization/arena/index.d.ts
generated
vendored
Normal file
8
node_modules/capnp-ts/src/serialization/arena/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
export { AnyArena } from "./any-arena";
|
||||
export { Arena } from "./arena";
|
||||
export { ArenaKind } from "./arena-kind";
|
||||
export { MultiSegmentArena } from "./multi-segment-arena";
|
||||
export { SingleSegmentArena } from "./single-segment-arena";
|
15
node_modules/capnp-ts/src/serialization/arena/index.js
generated
vendored
Normal file
15
node_modules/capnp-ts/src/serialization/arena/index.js
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
"use strict";
|
||||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SingleSegmentArena = exports.MultiSegmentArena = exports.ArenaKind = exports.Arena = void 0;
|
||||
var arena_1 = require("./arena");
|
||||
Object.defineProperty(exports, "Arena", { enumerable: true, get: function () { return arena_1.Arena; } });
|
||||
var arena_kind_1 = require("./arena-kind");
|
||||
Object.defineProperty(exports, "ArenaKind", { enumerable: true, get: function () { return arena_kind_1.ArenaKind; } });
|
||||
var multi_segment_arena_1 = require("./multi-segment-arena");
|
||||
Object.defineProperty(exports, "MultiSegmentArena", { enumerable: true, get: function () { return multi_segment_arena_1.MultiSegmentArena; } });
|
||||
var single_segment_arena_1 = require("./single-segment-arena");
|
||||
Object.defineProperty(exports, "SingleSegmentArena", { enumerable: true, get: function () { return single_segment_arena_1.SingleSegmentArena; } });
|
||||
//# sourceMappingURL=index.js.map
|
1
node_modules/capnp-ts/src/serialization/arena/index.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/arena/index.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAGH,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAClB,6DAA0D;AAAjD,wHAAA,iBAAiB,OAAA;AAC1B,+DAA4D;AAAnD,0HAAA,kBAAkB,OAAA"}
|
9
node_modules/capnp-ts/src/serialization/arena/index.ts
generated
vendored
Normal file
9
node_modules/capnp-ts/src/serialization/arena/index.ts
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
|
||||
export { AnyArena } from "./any-arena";
|
||||
export { Arena } from "./arena";
|
||||
export { ArenaKind } from "./arena-kind";
|
||||
export { MultiSegmentArena } from "./multi-segment-arena";
|
||||
export { SingleSegmentArena } from "./single-segment-arena";
|
17
node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.d.ts
generated
vendored
Normal file
17
node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
import { ArenaAllocationResult } from "./arena-allocation-result";
|
||||
import { ArenaKind } from "./arena-kind";
|
||||
export declare class MultiSegmentArena {
|
||||
static readonly allocate: typeof allocate;
|
||||
static readonly getBuffer: typeof getBuffer;
|
||||
static readonly getNumSegments: typeof getNumSegments;
|
||||
readonly buffers: ArrayBuffer[];
|
||||
readonly kind = ArenaKind.MULTI_SEGMENT;
|
||||
constructor(buffers?: ArrayBuffer[]);
|
||||
toString(): string;
|
||||
}
|
||||
export declare function allocate(minSize: number, m: MultiSegmentArena): ArenaAllocationResult;
|
||||
export declare function getBuffer(id: number, m: MultiSegmentArena): ArrayBuffer;
|
||||
export declare function getNumSegments(m: MultiSegmentArena): number;
|
47
node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.js
generated
vendored
Normal file
47
node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.js
generated
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
"use strict";
|
||||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getNumSegments = exports.getBuffer = exports.allocate = exports.MultiSegmentArena = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const debug_1 = tslib_1.__importDefault(require("debug"));
|
||||
const constants_1 = require("../../constants");
|
||||
const errors_1 = require("../../errors");
|
||||
const util_1 = require("../../util");
|
||||
const arena_allocation_result_1 = require("./arena-allocation-result");
|
||||
const arena_kind_1 = require("./arena-kind");
|
||||
const trace = debug_1.default("capnp:arena:multi");
|
||||
trace("load");
|
||||
class MultiSegmentArena {
|
||||
constructor(buffers = []) {
|
||||
this.kind = arena_kind_1.ArenaKind.MULTI_SEGMENT;
|
||||
this.buffers = buffers;
|
||||
trace("new %s", this);
|
||||
}
|
||||
toString() {
|
||||
return util_1.format("MultiSegmentArena_segments:%d", getNumSegments(this));
|
||||
}
|
||||
}
|
||||
exports.MultiSegmentArena = MultiSegmentArena;
|
||||
MultiSegmentArena.allocate = allocate;
|
||||
MultiSegmentArena.getBuffer = getBuffer;
|
||||
MultiSegmentArena.getNumSegments = getNumSegments;
|
||||
function allocate(minSize, m) {
|
||||
const b = new ArrayBuffer(util_1.padToWord(Math.max(minSize, constants_1.DEFAULT_BUFFER_SIZE)));
|
||||
m.buffers.push(b);
|
||||
return new arena_allocation_result_1.ArenaAllocationResult(m.buffers.length - 1, b);
|
||||
}
|
||||
exports.allocate = allocate;
|
||||
function getBuffer(id, m) {
|
||||
if (id < 0 || id >= m.buffers.length) {
|
||||
throw new Error(util_1.format(errors_1.SEG_ID_OUT_OF_BOUNDS, id));
|
||||
}
|
||||
return m.buffers[id];
|
||||
}
|
||||
exports.getBuffer = getBuffer;
|
||||
function getNumSegments(m) {
|
||||
return m.buffers.length;
|
||||
}
|
||||
exports.getNumSegments = getNumSegments;
|
||||
//# sourceMappingURL=multi-segment-arena.js.map
|
1
node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"multi-segment-arena.js","sourceRoot":"","sources":["multi-segment-arena.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAC9B,+CAAsD;AACtD,yCAAoD;AACpD,qCAA+C;AAC/C,uEAAkE;AAClE,6CAAyC;AAEzC,MAAM,KAAK,GAAG,eAAS,CAAC,mBAAmB,CAAC,CAAC;AAC7C,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,iBAAiB;IAQ5B,YAAY,UAAyB,EAAE;QAF9B,SAAI,GAAG,sBAAS,CAAC,aAAa,CAAC;QAGtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,QAAQ;QACN,OAAO,aAAM,CAAC,+BAA+B,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;IACvE,CAAC;;AAhBH,8CAiBC;AAhBiB,0BAAQ,GAAG,QAAQ,CAAC;AACpB,2BAAS,GAAG,SAAS,CAAC;AACtB,gCAAc,GAAG,cAAc,CAAC;AAgBlD,SAAgB,QAAQ,CAAC,OAAe,EAAE,CAAoB;IAC5D,MAAM,CAAC,GAAG,IAAI,WAAW,CAAC,gBAAS,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,+BAAmB,CAAC,CAAC,CAAC,CAAC;IAC7E,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAElB,OAAO,IAAI,+CAAqB,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AAC5D,CAAC;AALD,4BAKC;AAED,SAAgB,SAAS,CAAC,EAAU,EAAE,CAAoB;IACxD,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE;QACpC,MAAM,IAAI,KAAK,CAAC,aAAM,CAAC,6BAAoB,EAAE,EAAE,CAAC,CAAC,CAAC;KACnD;IAED,OAAO,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AACvB,CAAC;AAND,8BAMC;AAED,SAAgB,cAAc,CAAC,CAAoB;IACjD,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;AAC1B,CAAC;AAFD,wCAEC"}
|
51
node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.ts
generated
vendored
Normal file
51
node_modules/capnp-ts/src/serialization/arena/multi-segment-arena.ts
generated
vendored
Normal file
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
|
||||
import initTrace from "debug";
|
||||
import { DEFAULT_BUFFER_SIZE } from "../../constants";
|
||||
import { SEG_ID_OUT_OF_BOUNDS } from "../../errors";
|
||||
import { padToWord, format } from "../../util";
|
||||
import { ArenaAllocationResult } from "./arena-allocation-result";
|
||||
import { ArenaKind } from "./arena-kind";
|
||||
|
||||
const trace = initTrace("capnp:arena:multi");
|
||||
trace("load");
|
||||
|
||||
export class MultiSegmentArena {
|
||||
static readonly allocate = allocate;
|
||||
static readonly getBuffer = getBuffer;
|
||||
static readonly getNumSegments = getNumSegments;
|
||||
|
||||
readonly buffers: ArrayBuffer[];
|
||||
readonly kind = ArenaKind.MULTI_SEGMENT;
|
||||
|
||||
constructor(buffers: ArrayBuffer[] = []) {
|
||||
this.buffers = buffers;
|
||||
|
||||
trace("new %s", this);
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return format("MultiSegmentArena_segments:%d", getNumSegments(this));
|
||||
}
|
||||
}
|
||||
|
||||
export function allocate(minSize: number, m: MultiSegmentArena): ArenaAllocationResult {
|
||||
const b = new ArrayBuffer(padToWord(Math.max(minSize, DEFAULT_BUFFER_SIZE)));
|
||||
m.buffers.push(b);
|
||||
|
||||
return new ArenaAllocationResult(m.buffers.length - 1, b);
|
||||
}
|
||||
|
||||
export function getBuffer(id: number, m: MultiSegmentArena): ArrayBuffer {
|
||||
if (id < 0 || id >= m.buffers.length) {
|
||||
throw new Error(format(SEG_ID_OUT_OF_BOUNDS, id));
|
||||
}
|
||||
|
||||
return m.buffers[id];
|
||||
}
|
||||
|
||||
export function getNumSegments(m: MultiSegmentArena): number {
|
||||
return m.buffers.length;
|
||||
}
|
18
node_modules/capnp-ts/src/serialization/arena/single-segment-arena.d.ts
generated
vendored
Normal file
18
node_modules/capnp-ts/src/serialization/arena/single-segment-arena.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
import { Segment } from "../segment";
|
||||
import { ArenaAllocationResult } from "./arena-allocation-result";
|
||||
import { ArenaKind } from "./arena-kind";
|
||||
export declare class SingleSegmentArena {
|
||||
static readonly allocate: typeof allocate;
|
||||
static readonly getBuffer: typeof getBuffer;
|
||||
static readonly getNumSegments: typeof getNumSegments;
|
||||
buffer: ArrayBuffer;
|
||||
readonly kind = ArenaKind.SINGLE_SEGMENT;
|
||||
constructor(buffer?: ArrayBuffer);
|
||||
toString(): string;
|
||||
}
|
||||
export declare function allocate(minSize: number, segments: Segment[], s: SingleSegmentArena): ArenaAllocationResult;
|
||||
export declare function getBuffer(id: number, s: SingleSegmentArena): ArrayBuffer;
|
||||
export declare function getNumSegments(): number;
|
59
node_modules/capnp-ts/src/serialization/arena/single-segment-arena.js
generated
vendored
Normal file
59
node_modules/capnp-ts/src/serialization/arena/single-segment-arena.js
generated
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
"use strict";
|
||||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getNumSegments = exports.getBuffer = exports.allocate = exports.SingleSegmentArena = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const debug_1 = tslib_1.__importDefault(require("debug"));
|
||||
const constants_1 = require("../../constants");
|
||||
const errors_1 = require("../../errors");
|
||||
const util_1 = require("../../util");
|
||||
const arena_allocation_result_1 = require("./arena-allocation-result");
|
||||
const arena_kind_1 = require("./arena-kind");
|
||||
const trace = debug_1.default("capnp:arena:single");
|
||||
trace("load");
|
||||
class SingleSegmentArena {
|
||||
constructor(buffer = new ArrayBuffer(constants_1.DEFAULT_BUFFER_SIZE)) {
|
||||
this.kind = arena_kind_1.ArenaKind.SINGLE_SEGMENT;
|
||||
if ((buffer.byteLength & 7) !== 0) {
|
||||
throw new Error(util_1.format(errors_1.SEG_NOT_WORD_ALIGNED, buffer.byteLength));
|
||||
}
|
||||
this.buffer = buffer;
|
||||
trace("new %s", this);
|
||||
}
|
||||
toString() {
|
||||
return util_1.format("SingleSegmentArena_len:%x", this.buffer.byteLength);
|
||||
}
|
||||
}
|
||||
exports.SingleSegmentArena = SingleSegmentArena;
|
||||
SingleSegmentArena.allocate = allocate;
|
||||
SingleSegmentArena.getBuffer = getBuffer;
|
||||
SingleSegmentArena.getNumSegments = getNumSegments;
|
||||
function allocate(minSize, segments, s) {
|
||||
trace("Allocating %x bytes for segment 0 in %s.", minSize, s);
|
||||
const srcBuffer = segments.length > 0 ? segments[0].buffer : s.buffer;
|
||||
if (minSize < constants_1.MIN_SINGLE_SEGMENT_GROWTH) {
|
||||
minSize = constants_1.MIN_SINGLE_SEGMENT_GROWTH;
|
||||
}
|
||||
else {
|
||||
minSize = util_1.padToWord(minSize);
|
||||
}
|
||||
s.buffer = new ArrayBuffer(srcBuffer.byteLength + minSize);
|
||||
// PERF: Assume that the source and destination buffers are word-aligned and use Float64Array to copy them one word
|
||||
// at a time.
|
||||
new Float64Array(s.buffer).set(new Float64Array(srcBuffer));
|
||||
return new arena_allocation_result_1.ArenaAllocationResult(0, s.buffer);
|
||||
}
|
||||
exports.allocate = allocate;
|
||||
function getBuffer(id, s) {
|
||||
if (id !== 0)
|
||||
throw new Error(util_1.format(errors_1.SEG_GET_NON_ZERO_SINGLE, id));
|
||||
return s.buffer;
|
||||
}
|
||||
exports.getBuffer = getBuffer;
|
||||
function getNumSegments() {
|
||||
return 1;
|
||||
}
|
||||
exports.getNumSegments = getNumSegments;
|
||||
//# sourceMappingURL=single-segment-arena.js.map
|
1
node_modules/capnp-ts/src/serialization/arena/single-segment-arena.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/arena/single-segment-arena.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"single-segment-arena.js","sourceRoot":"","sources":["single-segment-arena.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAC9B,+CAAiF;AACjF,yCAA6E;AAC7E,qCAA+C;AAE/C,uEAAkE;AAClE,6CAAyC;AAEzC,MAAM,KAAK,GAAG,eAAS,CAAC,oBAAoB,CAAC,CAAC;AAC9C,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd,MAAa,kBAAkB;IAQ7B,YAAY,MAAM,GAAG,IAAI,WAAW,CAAC,+BAAmB,CAAC;QAFhD,SAAI,GAAG,sBAAS,CAAC,cAAc,CAAC;QAGvC,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE;YACjC,MAAM,IAAI,KAAK,CAAC,aAAM,CAAC,6BAAoB,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;SAClE;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,QAAQ;QACN,OAAO,aAAM,CAAC,2BAA2B,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACrE,CAAC;;AApBH,gDAqBC;AApBiB,2BAAQ,GAAG,QAAQ,CAAC;AACpB,4BAAS,GAAG,SAAS,CAAC;AACtB,iCAAc,GAAG,cAAc,CAAC;AAoBlD,SAAgB,QAAQ,CAAC,OAAe,EAAE,QAAmB,EAAE,CAAqB;IAClF,KAAK,CAAC,0CAA0C,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAE9D,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAEtE,IAAI,OAAO,GAAG,qCAAyB,EAAE;QACvC,OAAO,GAAG,qCAAyB,CAAC;KACrC;SAAM;QACL,OAAO,GAAG,gBAAS,CAAC,OAAO,CAAC,CAAC;KAC9B;IAED,CAAC,CAAC,MAAM,GAAG,IAAI,WAAW,CAAC,SAAS,CAAC,UAAU,GAAG,OAAO,CAAC,CAAC;IAE3D,mHAAmH;IACnH,aAAa;IACb,IAAI,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC;IAE5D,OAAO,IAAI,+CAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;AAChD,CAAC;AAlBD,4BAkBC;AAED,SAAgB,SAAS,CAAC,EAAU,EAAE,CAAqB;IACzD,IAAI,EAAE,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,aAAM,CAAC,gCAAuB,EAAE,EAAE,CAAC,CAAC,CAAC;IAEnE,OAAO,CAAC,CAAC,MAAM,CAAC;AAClB,CAAC;AAJD,8BAIC;AAED,SAAgB,cAAc;IAC5B,OAAO,CAAC,CAAC;AACX,CAAC;AAFD,wCAEC"}
|
67
node_modules/capnp-ts/src/serialization/arena/single-segment-arena.ts
generated
vendored
Normal file
67
node_modules/capnp-ts/src/serialization/arena/single-segment-arena.ts
generated
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
|
||||
import initTrace from "debug";
|
||||
import { DEFAULT_BUFFER_SIZE, MIN_SINGLE_SEGMENT_GROWTH } from "../../constants";
|
||||
import { SEG_GET_NON_ZERO_SINGLE, SEG_NOT_WORD_ALIGNED } from "../../errors";
|
||||
import { format, padToWord } from "../../util";
|
||||
import { Segment } from "../segment";
|
||||
import { ArenaAllocationResult } from "./arena-allocation-result";
|
||||
import { ArenaKind } from "./arena-kind";
|
||||
|
||||
const trace = initTrace("capnp:arena:single");
|
||||
trace("load");
|
||||
|
||||
export class SingleSegmentArena {
|
||||
static readonly allocate = allocate;
|
||||
static readonly getBuffer = getBuffer;
|
||||
static readonly getNumSegments = getNumSegments;
|
||||
|
||||
buffer: ArrayBuffer;
|
||||
readonly kind = ArenaKind.SINGLE_SEGMENT;
|
||||
|
||||
constructor(buffer = new ArrayBuffer(DEFAULT_BUFFER_SIZE)) {
|
||||
if ((buffer.byteLength & 7) !== 0) {
|
||||
throw new Error(format(SEG_NOT_WORD_ALIGNED, buffer.byteLength));
|
||||
}
|
||||
|
||||
this.buffer = buffer;
|
||||
|
||||
trace("new %s", this);
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return format("SingleSegmentArena_len:%x", this.buffer.byteLength);
|
||||
}
|
||||
}
|
||||
|
||||
export function allocate(minSize: number, segments: Segment[], s: SingleSegmentArena): ArenaAllocationResult {
|
||||
trace("Allocating %x bytes for segment 0 in %s.", minSize, s);
|
||||
|
||||
const srcBuffer = segments.length > 0 ? segments[0].buffer : s.buffer;
|
||||
|
||||
if (minSize < MIN_SINGLE_SEGMENT_GROWTH) {
|
||||
minSize = MIN_SINGLE_SEGMENT_GROWTH;
|
||||
} else {
|
||||
minSize = padToWord(minSize);
|
||||
}
|
||||
|
||||
s.buffer = new ArrayBuffer(srcBuffer.byteLength + minSize);
|
||||
|
||||
// PERF: Assume that the source and destination buffers are word-aligned and use Float64Array to copy them one word
|
||||
// at a time.
|
||||
new Float64Array(s.buffer).set(new Float64Array(srcBuffer));
|
||||
|
||||
return new ArenaAllocationResult(0, s.buffer);
|
||||
}
|
||||
|
||||
export function getBuffer(id: number, s: SingleSegmentArena): ArrayBuffer {
|
||||
if (id !== 0) throw new Error(format(SEG_GET_NON_ZERO_SINGLE, id));
|
||||
|
||||
return s.buffer;
|
||||
}
|
||||
|
||||
export function getNumSegments(): number {
|
||||
return 1;
|
||||
}
|
8
node_modules/capnp-ts/src/serialization/index.d.ts
generated
vendored
Normal file
8
node_modules/capnp-ts/src/serialization/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
export * from "./mask";
|
||||
export { ListElementSize } from "./list-element-size";
|
||||
export { Message, readRawPointer } from "./message";
|
||||
export { ObjectSize } from "./object-size";
|
||||
export * from "./pointers/index";
|
17
node_modules/capnp-ts/src/serialization/index.js
generated
vendored
Normal file
17
node_modules/capnp-ts/src/serialization/index.js
generated
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
"use strict";
|
||||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ObjectSize = exports.readRawPointer = exports.Message = exports.ListElementSize = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./mask"), exports);
|
||||
var list_element_size_1 = require("./list-element-size");
|
||||
Object.defineProperty(exports, "ListElementSize", { enumerable: true, get: function () { return list_element_size_1.ListElementSize; } });
|
||||
var message_1 = require("./message");
|
||||
Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return message_1.Message; } });
|
||||
Object.defineProperty(exports, "readRawPointer", { enumerable: true, get: function () { return message_1.readRawPointer; } });
|
||||
var object_size_1 = require("./object-size");
|
||||
Object.defineProperty(exports, "ObjectSize", { enumerable: true, get: function () { return object_size_1.ObjectSize; } });
|
||||
tslib_1.__exportStar(require("./pointers/index"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
1
node_modules/capnp-ts/src/serialization/index.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/index.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,iDAAuB;AACvB,yDAAsD;AAA7C,oHAAA,eAAe,OAAA;AACxB,qCAAoD;AAA3C,kGAAA,OAAO,OAAA;AAAE,yGAAA,cAAc,OAAA;AAChC,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,2DAAiC"}
|
9
node_modules/capnp-ts/src/serialization/index.ts
generated
vendored
Normal file
9
node_modules/capnp-ts/src/serialization/index.ts
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
|
||||
export * from "./mask";
|
||||
export { ListElementSize } from "./list-element-size";
|
||||
export { Message, readRawPointer } from "./message";
|
||||
export { ObjectSize } from "./object-size";
|
||||
export * from "./pointers/index";
|
14
node_modules/capnp-ts/src/serialization/list-element-size.d.ts
generated
vendored
Normal file
14
node_modules/capnp-ts/src/serialization/list-element-size.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
export declare enum ListElementSize {
|
||||
VOID = 0,
|
||||
BIT = 1,
|
||||
BYTE = 2,
|
||||
BYTE_2 = 3,
|
||||
BYTE_4 = 4,
|
||||
BYTE_8 = 5,
|
||||
POINTER = 6,
|
||||
COMPOSITE = 7
|
||||
}
|
||||
export declare const ListElementOffset: number[];
|
28
node_modules/capnp-ts/src/serialization/list-element-size.js
generated
vendored
Normal file
28
node_modules/capnp-ts/src/serialization/list-element-size.js
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
"use strict";
|
||||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ListElementOffset = exports.ListElementSize = void 0;
|
||||
var ListElementSize;
|
||||
(function (ListElementSize) {
|
||||
ListElementSize[ListElementSize["VOID"] = 0] = "VOID";
|
||||
ListElementSize[ListElementSize["BIT"] = 1] = "BIT";
|
||||
ListElementSize[ListElementSize["BYTE"] = 2] = "BYTE";
|
||||
ListElementSize[ListElementSize["BYTE_2"] = 3] = "BYTE_2";
|
||||
ListElementSize[ListElementSize["BYTE_4"] = 4] = "BYTE_4";
|
||||
ListElementSize[ListElementSize["BYTE_8"] = 5] = "BYTE_8";
|
||||
ListElementSize[ListElementSize["POINTER"] = 6] = "POINTER";
|
||||
ListElementSize[ListElementSize["COMPOSITE"] = 7] = "COMPOSITE";
|
||||
})(ListElementSize = exports.ListElementSize || (exports.ListElementSize = {}));
|
||||
exports.ListElementOffset = [
|
||||
0,
|
||||
0.125,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
8,
|
||||
8,
|
||||
NaN // composite
|
||||
];
|
||||
//# sourceMappingURL=list-element-size.js.map
|
1
node_modules/capnp-ts/src/serialization/list-element-size.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/list-element-size.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"list-element-size.js","sourceRoot":"","sources":["list-element-size.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,IAAY,eASX;AATD,WAAY,eAAe;IACzB,qDAAQ,CAAA;IACR,mDAAO,CAAA;IACP,qDAAQ,CAAA;IACR,yDAAU,CAAA;IACV,yDAAU,CAAA;IACV,yDAAU,CAAA;IACV,2DAAW,CAAA;IACX,+DAAa,CAAA;AACf,CAAC,EATW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAS1B;AAEY,QAAA,iBAAiB,GAAG;IAC/B,CAAC;IACD,KAAK;IACL,CAAC;IACD,CAAC;IACD,CAAC;IACD,CAAC;IACD,CAAC;IACD,GAAG,CAAC,YAAY;CACjB,CAAC"}
|
25
node_modules/capnp-ts/src/serialization/list-element-size.ts
generated
vendored
Normal file
25
node_modules/capnp-ts/src/serialization/list-element-size.ts
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
|
||||
export enum ListElementSize {
|
||||
VOID = 0,
|
||||
BIT = 1,
|
||||
BYTE = 2,
|
||||
BYTE_2 = 3,
|
||||
BYTE_4 = 4,
|
||||
BYTE_8 = 5,
|
||||
POINTER = 6,
|
||||
COMPOSITE = 7
|
||||
}
|
||||
|
||||
export const ListElementOffset = [
|
||||
0, // void
|
||||
0.125, // bit
|
||||
1, // byte
|
||||
2, // two byte
|
||||
4, // four byte
|
||||
8, // eight byte
|
||||
8, // pointer
|
||||
NaN // composite
|
||||
];
|
16
node_modules/capnp-ts/src/serialization/mask.d.ts
generated
vendored
Normal file
16
node_modules/capnp-ts/src/serialization/mask.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
import { Int64, Uint64 } from "../types/index";
|
||||
export declare const getFloat32Mask: (x: number) => DataView;
|
||||
export declare const getFloat64Mask: (x: number) => DataView;
|
||||
export declare const getInt16Mask: (x: number) => DataView;
|
||||
export declare const getInt32Mask: (x: number) => DataView;
|
||||
export declare const getInt8Mask: (x: number) => DataView;
|
||||
export declare const getUint16Mask: (x: number) => DataView;
|
||||
export declare const getUint32Mask: (x: number) => DataView;
|
||||
export declare const getUint8Mask: (x: number) => DataView;
|
||||
export declare function getBitMask(value: boolean, bitOffset: number): DataView;
|
||||
export declare function getInt64Mask(x: Int64): DataView;
|
||||
export declare function getUint64Mask(x: Uint64): DataView;
|
||||
export declare function getVoidMask(): void;
|
45
node_modules/capnp-ts/src/serialization/mask.js
generated
vendored
Normal file
45
node_modules/capnp-ts/src/serialization/mask.js
generated
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
"use strict";
|
||||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getVoidMask = exports.getUint64Mask = exports.getInt64Mask = exports.getBitMask = exports.getUint8Mask = exports.getUint32Mask = exports.getUint16Mask = exports.getInt8Mask = exports.getInt32Mask = exports.getInt16Mask = exports.getFloat64Mask = exports.getFloat32Mask = void 0;
|
||||
const errors_1 = require("../errors");
|
||||
function _makePrimitiveMaskFn(byteLength, setter) {
|
||||
return (x) => {
|
||||
const dv = new DataView(new ArrayBuffer(byteLength));
|
||||
setter.call(dv, 0, x, true);
|
||||
return dv;
|
||||
};
|
||||
}
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
exports.getFloat32Mask = _makePrimitiveMaskFn(4, DataView.prototype.setFloat32);
|
||||
exports.getFloat64Mask = _makePrimitiveMaskFn(8, DataView.prototype.setFloat64);
|
||||
exports.getInt16Mask = _makePrimitiveMaskFn(2, DataView.prototype.setInt16);
|
||||
exports.getInt32Mask = _makePrimitiveMaskFn(4, DataView.prototype.setInt32);
|
||||
exports.getInt8Mask = _makePrimitiveMaskFn(1, DataView.prototype.setInt8);
|
||||
exports.getUint16Mask = _makePrimitiveMaskFn(2, DataView.prototype.setUint16);
|
||||
exports.getUint32Mask = _makePrimitiveMaskFn(4, DataView.prototype.setUint32);
|
||||
exports.getUint8Mask = _makePrimitiveMaskFn(1, DataView.prototype.setUint8);
|
||||
/* eslint-enable */
|
||||
function getBitMask(value, bitOffset) {
|
||||
const dv = new DataView(new ArrayBuffer(1));
|
||||
if (!value)
|
||||
return dv;
|
||||
dv.setUint8(0, 1 << bitOffset % 8);
|
||||
return dv;
|
||||
}
|
||||
exports.getBitMask = getBitMask;
|
||||
function getInt64Mask(x) {
|
||||
return x.toDataView();
|
||||
}
|
||||
exports.getInt64Mask = getInt64Mask;
|
||||
function getUint64Mask(x) {
|
||||
return x.toDataView();
|
||||
}
|
||||
exports.getUint64Mask = getUint64Mask;
|
||||
function getVoidMask() {
|
||||
throw new Error(errors_1.INVARIANT_UNREACHABLE_CODE);
|
||||
}
|
||||
exports.getVoidMask = getVoidMask;
|
||||
//# sourceMappingURL=mask.js.map
|
1
node_modules/capnp-ts/src/serialization/mask.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/mask.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"mask.js","sourceRoot":"","sources":["mask.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,sCAAuD;AAKvD,SAAS,oBAAoB,CAAC,UAAkB,EAAE,MAAsB;IACtE,OAAO,CAAC,CAAS,EAAY,EAAE;QAC7B,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,IAAI,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;QACrD,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;QAC5B,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;AACJ,CAAC;AAED,sDAAsD;AACzC,QAAA,cAAc,GAAG,oBAAoB,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;AACxE,QAAA,cAAc,GAAG,oBAAoB,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;AACxE,QAAA,YAAY,GAAG,oBAAoB,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AACpE,QAAA,YAAY,GAAG,oBAAoB,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AACpE,QAAA,WAAW,GAAG,oBAAoB,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AAClE,QAAA,aAAa,GAAG,oBAAoB,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AACtE,QAAA,aAAa,GAAG,oBAAoB,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AACtE,QAAA,YAAY,GAAG,oBAAoB,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AACjF,mBAAmB;AAEnB,SAAgB,UAAU,CAAC,KAAc,EAAE,SAAiB;IAC1D,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAE5C,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IAEtB,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC;IACnC,OAAO,EAAE,CAAC;AACZ,CAAC;AAPD,gCAOC;AAED,SAAgB,YAAY,CAAC,CAAQ;IACnC,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC;AACxB,CAAC;AAFD,oCAEC;AAED,SAAgB,aAAa,CAAC,CAAS;IACrC,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC;AACxB,CAAC;AAFD,sCAEC;AAED,SAAgB,WAAW;IACzB,MAAM,IAAI,KAAK,CAAC,mCAA0B,CAAC,CAAC;AAC9C,CAAC;AAFD,kCAEC"}
|
48
node_modules/capnp-ts/src/serialization/mask.ts
generated
vendored
Normal file
48
node_modules/capnp-ts/src/serialization/mask.ts
generated
vendored
Normal file
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
|
||||
import { INVARIANT_UNREACHABLE_CODE } from "../errors";
|
||||
import { Int64, Uint64 } from "../types/index";
|
||||
|
||||
type DataViewSetter = (byteOffset: number, value: number, littleEndian?: boolean) => void;
|
||||
|
||||
function _makePrimitiveMaskFn(byteLength: number, setter: DataViewSetter): (x: number) => DataView {
|
||||
return (x: number): DataView => {
|
||||
const dv = new DataView(new ArrayBuffer(byteLength));
|
||||
setter.call(dv, 0, x, true);
|
||||
return dv;
|
||||
};
|
||||
}
|
||||
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
export const getFloat32Mask = _makePrimitiveMaskFn(4, DataView.prototype.setFloat32);
|
||||
export const getFloat64Mask = _makePrimitiveMaskFn(8, DataView.prototype.setFloat64);
|
||||
export const getInt16Mask = _makePrimitiveMaskFn(2, DataView.prototype.setInt16);
|
||||
export const getInt32Mask = _makePrimitiveMaskFn(4, DataView.prototype.setInt32);
|
||||
export const getInt8Mask = _makePrimitiveMaskFn(1, DataView.prototype.setInt8);
|
||||
export const getUint16Mask = _makePrimitiveMaskFn(2, DataView.prototype.setUint16);
|
||||
export const getUint32Mask = _makePrimitiveMaskFn(4, DataView.prototype.setUint32);
|
||||
export const getUint8Mask = _makePrimitiveMaskFn(1, DataView.prototype.setUint8);
|
||||
/* eslint-enable */
|
||||
|
||||
export function getBitMask(value: boolean, bitOffset: number): DataView {
|
||||
const dv = new DataView(new ArrayBuffer(1));
|
||||
|
||||
if (!value) return dv;
|
||||
|
||||
dv.setUint8(0, 1 << bitOffset % 8);
|
||||
return dv;
|
||||
}
|
||||
|
||||
export function getInt64Mask(x: Int64): DataView {
|
||||
return x.toDataView();
|
||||
}
|
||||
|
||||
export function getUint64Mask(x: Uint64): DataView {
|
||||
return x.toDataView();
|
||||
}
|
||||
|
||||
export function getVoidMask(): void {
|
||||
throw new Error(INVARIANT_UNREACHABLE_CODE);
|
||||
}
|
158
node_modules/capnp-ts/src/serialization/message.d.ts
generated
vendored
Normal file
158
node_modules/capnp-ts/src/serialization/message.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,158 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
import { AnyArena } from "./arena";
|
||||
import { Pointer, StructCtor, Struct } from "./pointers";
|
||||
import { Segment } from "./segment";
|
||||
export interface _Message {
|
||||
readonly arena: AnyArena;
|
||||
segments: Segment[];
|
||||
traversalLimit: number;
|
||||
}
|
||||
export declare class Message {
|
||||
static readonly allocateSegment: typeof allocateSegment;
|
||||
static readonly dump: typeof dump;
|
||||
static readonly getRoot: typeof getRoot;
|
||||
static readonly getSegment: typeof getSegment;
|
||||
static readonly initRoot: typeof initRoot;
|
||||
static readonly readRawPointer: typeof readRawPointer;
|
||||
static readonly toArrayBuffer: typeof toArrayBuffer;
|
||||
static readonly toPackedArrayBuffer: typeof toPackedArrayBuffer;
|
||||
readonly _capnp: _Message;
|
||||
/**
|
||||
* A Cap'n Proto message.
|
||||
*
|
||||
* SECURITY WARNING: In nodejs do not pass a Buffer's internal array buffer into this constructor. Pass the buffer
|
||||
* directly and everything will be fine. If not, your message will potentially be initialized with random memory
|
||||
* contents!
|
||||
*
|
||||
* The constructor method creates a new Message, optionally using a provided arena for segment allocation, or a buffer
|
||||
* to read from.
|
||||
*
|
||||
* @constructor {Message}
|
||||
*
|
||||
* @param {AnyArena|ArrayBufferView|ArrayBuffer} [src] The source for the message.
|
||||
* A value of `undefined` will cause the message to initialize with a single segment arena only big enough for the
|
||||
* root pointer; it will expand as you go. This is a reasonable choice for most messages.
|
||||
*
|
||||
* Passing an arena will cause the message to use that arena for its segment allocation. Contents will be accepted
|
||||
* as-is.
|
||||
*
|
||||
* Passing an array buffer view (like `DataView`, `Uint8Array` or `Buffer`) will create a **copy** of the source
|
||||
* buffer; beware of the potential performance cost!
|
||||
*
|
||||
* @param {boolean} [packed] Whether or not the message is packed. If `true` (the default), the message will be
|
||||
* unpacked.
|
||||
*
|
||||
* @param {boolean} [singleSegment] If true, `src` will be treated as a message consisting of a single segment without
|
||||
* a framing header.
|
||||
*
|
||||
*/
|
||||
constructor(src?: AnyArena | ArrayBufferView | ArrayBuffer, packed?: boolean, singleSegment?: boolean);
|
||||
allocateSegment(byteLength: number): Segment;
|
||||
/**
|
||||
* Create a pretty-printed string dump of this message; incredibly useful for debugging.
|
||||
*
|
||||
* WARNING: Do not call this method on large messages!
|
||||
*
|
||||
* @returns {string} A big steaming pile of pretty hex digits.
|
||||
*/
|
||||
dump(): string;
|
||||
/**
|
||||
* Get a struct pointer for the root of this message. This is primarily used when reading a message; it will not
|
||||
* overwrite existing data.
|
||||
*
|
||||
* @template T
|
||||
* @param {StructCtor<T>} RootStruct The struct type to use as the root.
|
||||
* @returns {T} A struct representing the root of the message.
|
||||
*/
|
||||
getRoot<T extends Struct>(RootStruct: StructCtor<T>): T;
|
||||
/**
|
||||
* Get a segment by its id.
|
||||
*
|
||||
* This will lazily allocate the first segment if it doesn't already exist.
|
||||
*
|
||||
* @param {number} id The segment id.
|
||||
* @returns {Segment} The requested segment.
|
||||
*/
|
||||
getSegment(id: number): Segment;
|
||||
/**
|
||||
* Initialize a new message using the provided struct type as the root.
|
||||
*
|
||||
* @template T
|
||||
* @param {StructCtor<T>} RootStruct The struct type to use as the root.
|
||||
* @returns {T} An initialized struct pointing to the root of the message.
|
||||
*/
|
||||
initRoot<T extends Struct>(RootStruct: StructCtor<T>): T;
|
||||
/**
|
||||
* Set the root of the message to a copy of the given pointer. Used internally
|
||||
* to make copies of pointers for default values.
|
||||
*
|
||||
* @param {Pointer} src The source pointer to copy.
|
||||
* @returns {void}
|
||||
*/
|
||||
setRoot(src: Pointer): void;
|
||||
/**
|
||||
* Combine the contents of this message's segments into a single array buffer and prepend a stream framing header
|
||||
* containing information about the following segment data.
|
||||
*
|
||||
* @returns {ArrayBuffer} An ArrayBuffer with the contents of this message.
|
||||
*/
|
||||
toArrayBuffer(): ArrayBuffer;
|
||||
/**
|
||||
* Like `toArrayBuffer()`, but also applies the packing algorithm to the output. This is typically what you want to
|
||||
* use if you're sending the message over a network link or other slow I/O interface where size matters.
|
||||
*
|
||||
* @returns {ArrayBuffer} A packed message.
|
||||
*/
|
||||
toPackedArrayBuffer(): ArrayBuffer;
|
||||
toString(): string;
|
||||
}
|
||||
export interface CreateMessageOptions {
|
||||
packed?: boolean;
|
||||
singleSegment?: boolean;
|
||||
}
|
||||
export declare function initMessage(src?: AnyArena | ArrayBufferView | ArrayBuffer, packed?: boolean, singleSegment?: boolean): _Message;
|
||||
/**
|
||||
* Given an _unpacked_ message with a segment framing header, this will generate an ArrayBuffer for each segment in
|
||||
* the message.
|
||||
*
|
||||
* This method is not typically called directly, but can be useful in certain cases.
|
||||
*
|
||||
* @static
|
||||
* @param {ArrayBuffer} message An unpacked message with a framing header.
|
||||
* @returns {ArrayBuffer[]} An array of buffers containing the segment data.
|
||||
*/
|
||||
export declare function getFramedSegments(message: ArrayBuffer): ArrayBuffer[];
|
||||
/**
|
||||
* This method is called on messages that were constructed with existing data to prepopulate the segments array with
|
||||
* everything we can find in the arena. Each segment will have it's `byteLength` set to the size of its buffer.
|
||||
*
|
||||
* Technically speaking, the message's segments will be "full" after calling this function. Calling this on your own
|
||||
* may void your warranty.
|
||||
*
|
||||
* @param {Message} m The message to allocate.
|
||||
* @returns {void}
|
||||
*/
|
||||
export declare function preallocateSegments(m: Message): void;
|
||||
export declare function allocateSegment(byteLength: number, m: Message): Segment;
|
||||
export declare function dump(m: Message): string;
|
||||
export declare function getRoot<T extends Struct>(RootStruct: StructCtor<T>, m: Message): T;
|
||||
export declare function getSegment(id: number, m: Message): Segment;
|
||||
export declare function initRoot<T extends Struct>(RootStruct: StructCtor<T>, m: Message): T;
|
||||
/**
|
||||
* Read a pointer in raw form (a packed message with framing headers). Does not
|
||||
* care or attempt to validate the input beyond parsing the message
|
||||
* segments.
|
||||
*
|
||||
* This is typically used by the compiler to load default values, but can be
|
||||
* useful to work with messages with an unknown schema.
|
||||
*
|
||||
* @param {ArrayBuffer} data The raw data to read.
|
||||
* @returns {Pointer} A root pointer.
|
||||
*/
|
||||
export declare function readRawPointer(data: ArrayBuffer): Pointer;
|
||||
export declare function setRoot(src: Pointer, m: Message): void;
|
||||
export declare function toArrayBuffer(m: Message): ArrayBuffer;
|
||||
export declare function toPackedArrayBuffer(m: Message): ArrayBuffer;
|
||||
export declare function getStreamFrame(m: Message): ArrayBuffer;
|
392
node_modules/capnp-ts/src/serialization/message.js
generated
vendored
Normal file
392
node_modules/capnp-ts/src/serialization/message.js
generated
vendored
Normal file
|
@ -0,0 +1,392 @@
|
|||
"use strict";
|
||||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getStreamFrame = exports.toPackedArrayBuffer = exports.toArrayBuffer = exports.setRoot = exports.readRawPointer = exports.initRoot = exports.getSegment = exports.getRoot = exports.dump = exports.allocateSegment = exports.preallocateSegments = exports.getFramedSegments = exports.initMessage = exports.Message = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const debug_1 = tslib_1.__importDefault(require("debug"));
|
||||
const constants_1 = require("../constants");
|
||||
const errors_1 = require("../errors");
|
||||
const util_1 = require("../util");
|
||||
const arena_1 = require("./arena");
|
||||
const packing_1 = require("./packing");
|
||||
const pointers_1 = require("./pointers");
|
||||
const segment_1 = require("./segment");
|
||||
const pointer_1 = require("./pointers/pointer");
|
||||
const struct_1 = require("./pointers/struct");
|
||||
const trace = debug_1.default("capnp:message");
|
||||
trace("load");
|
||||
class Message {
|
||||
/**
|
||||
* A Cap'n Proto message.
|
||||
*
|
||||
* SECURITY WARNING: In nodejs do not pass a Buffer's internal array buffer into this constructor. Pass the buffer
|
||||
* directly and everything will be fine. If not, your message will potentially be initialized with random memory
|
||||
* contents!
|
||||
*
|
||||
* The constructor method creates a new Message, optionally using a provided arena for segment allocation, or a buffer
|
||||
* to read from.
|
||||
*
|
||||
* @constructor {Message}
|
||||
*
|
||||
* @param {AnyArena|ArrayBufferView|ArrayBuffer} [src] The source for the message.
|
||||
* A value of `undefined` will cause the message to initialize with a single segment arena only big enough for the
|
||||
* root pointer; it will expand as you go. This is a reasonable choice for most messages.
|
||||
*
|
||||
* Passing an arena will cause the message to use that arena for its segment allocation. Contents will be accepted
|
||||
* as-is.
|
||||
*
|
||||
* Passing an array buffer view (like `DataView`, `Uint8Array` or `Buffer`) will create a **copy** of the source
|
||||
* buffer; beware of the potential performance cost!
|
||||
*
|
||||
* @param {boolean} [packed] Whether or not the message is packed. If `true` (the default), the message will be
|
||||
* unpacked.
|
||||
*
|
||||
* @param {boolean} [singleSegment] If true, `src` will be treated as a message consisting of a single segment without
|
||||
* a framing header.
|
||||
*
|
||||
*/
|
||||
constructor(src, packed = true, singleSegment = false) {
|
||||
this._capnp = initMessage(src, packed, singleSegment);
|
||||
if (src && !isAnyArena(src))
|
||||
preallocateSegments(this);
|
||||
trace("new %s", this);
|
||||
}
|
||||
allocateSegment(byteLength) {
|
||||
return allocateSegment(byteLength, this);
|
||||
}
|
||||
/**
|
||||
* Create a pretty-printed string dump of this message; incredibly useful for debugging.
|
||||
*
|
||||
* WARNING: Do not call this method on large messages!
|
||||
*
|
||||
* @returns {string} A big steaming pile of pretty hex digits.
|
||||
*/
|
||||
dump() {
|
||||
return dump(this);
|
||||
}
|
||||
/**
|
||||
* Get a struct pointer for the root of this message. This is primarily used when reading a message; it will not
|
||||
* overwrite existing data.
|
||||
*
|
||||
* @template T
|
||||
* @param {StructCtor<T>} RootStruct The struct type to use as the root.
|
||||
* @returns {T} A struct representing the root of the message.
|
||||
*/
|
||||
getRoot(RootStruct) {
|
||||
return getRoot(RootStruct, this);
|
||||
}
|
||||
/**
|
||||
* Get a segment by its id.
|
||||
*
|
||||
* This will lazily allocate the first segment if it doesn't already exist.
|
||||
*
|
||||
* @param {number} id The segment id.
|
||||
* @returns {Segment} The requested segment.
|
||||
*/
|
||||
getSegment(id) {
|
||||
return getSegment(id, this);
|
||||
}
|
||||
/**
|
||||
* Initialize a new message using the provided struct type as the root.
|
||||
*
|
||||
* @template T
|
||||
* @param {StructCtor<T>} RootStruct The struct type to use as the root.
|
||||
* @returns {T} An initialized struct pointing to the root of the message.
|
||||
*/
|
||||
initRoot(RootStruct) {
|
||||
return initRoot(RootStruct, this);
|
||||
}
|
||||
/**
|
||||
* Set the root of the message to a copy of the given pointer. Used internally
|
||||
* to make copies of pointers for default values.
|
||||
*
|
||||
* @param {Pointer} src The source pointer to copy.
|
||||
* @returns {void}
|
||||
*/
|
||||
setRoot(src) {
|
||||
setRoot(src, this);
|
||||
}
|
||||
/**
|
||||
* Combine the contents of this message's segments into a single array buffer and prepend a stream framing header
|
||||
* containing information about the following segment data.
|
||||
*
|
||||
* @returns {ArrayBuffer} An ArrayBuffer with the contents of this message.
|
||||
*/
|
||||
toArrayBuffer() {
|
||||
return toArrayBuffer(this);
|
||||
}
|
||||
/**
|
||||
* Like `toArrayBuffer()`, but also applies the packing algorithm to the output. This is typically what you want to
|
||||
* use if you're sending the message over a network link or other slow I/O interface where size matters.
|
||||
*
|
||||
* @returns {ArrayBuffer} A packed message.
|
||||
*/
|
||||
toPackedArrayBuffer() {
|
||||
return toPackedArrayBuffer(this);
|
||||
}
|
||||
toString() {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
return `Message_arena:${this._capnp.arena}`;
|
||||
}
|
||||
}
|
||||
exports.Message = Message;
|
||||
Message.allocateSegment = allocateSegment;
|
||||
Message.dump = dump;
|
||||
Message.getRoot = getRoot;
|
||||
Message.getSegment = getSegment;
|
||||
Message.initRoot = initRoot;
|
||||
Message.readRawPointer = readRawPointer;
|
||||
Message.toArrayBuffer = toArrayBuffer;
|
||||
Message.toPackedArrayBuffer = toPackedArrayBuffer;
|
||||
function initMessage(src, packed = true, singleSegment = false) {
|
||||
if (src === undefined) {
|
||||
return {
|
||||
arena: new arena_1.SingleSegmentArena(),
|
||||
segments: [],
|
||||
traversalLimit: constants_1.DEFAULT_TRAVERSE_LIMIT,
|
||||
};
|
||||
}
|
||||
if (isAnyArena(src)) {
|
||||
return { arena: src, segments: [], traversalLimit: constants_1.DEFAULT_TRAVERSE_LIMIT };
|
||||
}
|
||||
let buf = src;
|
||||
if (isArrayBufferView(buf)) {
|
||||
buf = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
||||
}
|
||||
if (packed)
|
||||
buf = packing_1.unpack(buf);
|
||||
if (singleSegment) {
|
||||
return {
|
||||
arena: new arena_1.SingleSegmentArena(buf),
|
||||
segments: [],
|
||||
traversalLimit: constants_1.DEFAULT_TRAVERSE_LIMIT,
|
||||
};
|
||||
}
|
||||
return {
|
||||
arena: new arena_1.MultiSegmentArena(getFramedSegments(buf)),
|
||||
segments: [],
|
||||
traversalLimit: constants_1.DEFAULT_TRAVERSE_LIMIT,
|
||||
};
|
||||
}
|
||||
exports.initMessage = initMessage;
|
||||
/**
|
||||
* Given an _unpacked_ message with a segment framing header, this will generate an ArrayBuffer for each segment in
|
||||
* the message.
|
||||
*
|
||||
* This method is not typically called directly, but can be useful in certain cases.
|
||||
*
|
||||
* @static
|
||||
* @param {ArrayBuffer} message An unpacked message with a framing header.
|
||||
* @returns {ArrayBuffer[]} An array of buffers containing the segment data.
|
||||
*/
|
||||
function getFramedSegments(message) {
|
||||
const dv = new DataView(message);
|
||||
const segmentCount = dv.getUint32(0, true) + 1;
|
||||
const segments = new Array(segmentCount);
|
||||
trace("reading %d framed segments from stream", segmentCount);
|
||||
let byteOffset = 4 + segmentCount * 4;
|
||||
byteOffset += byteOffset % 8;
|
||||
if (byteOffset + segmentCount * 4 > message.byteLength) {
|
||||
throw new Error(errors_1.MSG_INVALID_FRAME_HEADER);
|
||||
}
|
||||
for (let i = 0; i < segmentCount; i++) {
|
||||
const byteLength = dv.getUint32(4 + i * 4, true) * 8;
|
||||
if (byteOffset + byteLength > message.byteLength) {
|
||||
throw new Error(errors_1.MSG_INVALID_FRAME_HEADER);
|
||||
}
|
||||
segments[i] = message.slice(byteOffset, byteOffset + byteLength);
|
||||
byteOffset += byteLength;
|
||||
}
|
||||
return segments;
|
||||
}
|
||||
exports.getFramedSegments = getFramedSegments;
|
||||
/**
|
||||
* This method is called on messages that were constructed with existing data to prepopulate the segments array with
|
||||
* everything we can find in the arena. Each segment will have it's `byteLength` set to the size of its buffer.
|
||||
*
|
||||
* Technically speaking, the message's segments will be "full" after calling this function. Calling this on your own
|
||||
* may void your warranty.
|
||||
*
|
||||
* @param {Message} m The message to allocate.
|
||||
* @returns {void}
|
||||
*/
|
||||
function preallocateSegments(m) {
|
||||
const numSegments = arena_1.Arena.getNumSegments(m._capnp.arena);
|
||||
if (numSegments < 1)
|
||||
throw new Error(errors_1.MSG_NO_SEGMENTS_IN_ARENA);
|
||||
m._capnp.segments = new Array(numSegments);
|
||||
for (let i = 0; i < numSegments; i++) {
|
||||
// Set up each segment so that they're fully allocated to the extents of the existing buffers.
|
||||
const buffer = arena_1.Arena.getBuffer(i, m._capnp.arena);
|
||||
const segment = new segment_1.Segment(i, m, buffer, buffer.byteLength);
|
||||
m._capnp.segments[i] = segment;
|
||||
}
|
||||
}
|
||||
exports.preallocateSegments = preallocateSegments;
|
||||
function isArrayBufferView(src) {
|
||||
return src.byteOffset !== undefined;
|
||||
}
|
||||
function isAnyArena(o) {
|
||||
return o.kind !== undefined;
|
||||
}
|
||||
function allocateSegment(byteLength, m) {
|
||||
trace("allocating %x bytes for %s", byteLength, m);
|
||||
const res = arena_1.Arena.allocate(byteLength, m._capnp.segments, m._capnp.arena);
|
||||
let s;
|
||||
if (res.id === m._capnp.segments.length) {
|
||||
// Note how we're only allowing new segments in if they're exactly the next one in the array. There is no logical
|
||||
// reason for segments to be created out of order.
|
||||
s = new segment_1.Segment(res.id, m, res.buffer);
|
||||
trace("adding new segment %s", s);
|
||||
m._capnp.segments.push(s);
|
||||
}
|
||||
else if (res.id < 0 || res.id > m._capnp.segments.length) {
|
||||
throw new Error(util_1.format(errors_1.MSG_SEGMENT_OUT_OF_BOUNDS, res.id, m));
|
||||
}
|
||||
else {
|
||||
s = m._capnp.segments[res.id];
|
||||
trace("replacing segment %s with buffer (len:%d)", s, res.buffer.byteLength);
|
||||
s.replaceBuffer(res.buffer);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
exports.allocateSegment = allocateSegment;
|
||||
function dump(m) {
|
||||
let r = "";
|
||||
if (m._capnp.segments.length === 0) {
|
||||
return "================\nNo Segments\n================\n";
|
||||
}
|
||||
for (let i = 0; i < m._capnp.segments.length; i++) {
|
||||
r += `================\nSegment #${i}\n================\n`;
|
||||
const { buffer, byteLength } = m._capnp.segments[i];
|
||||
const b = new Uint8Array(buffer, 0, byteLength);
|
||||
r += util_1.dumpBuffer(b);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
exports.dump = dump;
|
||||
function getRoot(RootStruct, m) {
|
||||
const root = new RootStruct(m.getSegment(0), 0);
|
||||
pointer_1.validate(pointers_1.PointerType.STRUCT, root);
|
||||
const ts = pointer_1.getTargetStructSize(root);
|
||||
// Make sure the underlying pointer is actually big enough to hold the data and pointers as specified in the schema.
|
||||
// If not a shallow copy of the struct contents needs to be made before returning.
|
||||
if (ts.dataByteLength < RootStruct._capnp.size.dataByteLength ||
|
||||
ts.pointerLength < RootStruct._capnp.size.pointerLength) {
|
||||
trace("need to resize root struct %s", root);
|
||||
struct_1.resize(RootStruct._capnp.size, root);
|
||||
}
|
||||
return root;
|
||||
}
|
||||
exports.getRoot = getRoot;
|
||||
function getSegment(id, m) {
|
||||
const segmentLength = m._capnp.segments.length;
|
||||
if (id === 0 && segmentLength === 0) {
|
||||
// Segment zero is special. If we have no segments in the arena we'll want to allocate a new one and leave room
|
||||
// for the root pointer.
|
||||
const arenaSegments = arena_1.Arena.getNumSegments(m._capnp.arena);
|
||||
if (arenaSegments === 0) {
|
||||
allocateSegment(constants_1.DEFAULT_BUFFER_SIZE, m);
|
||||
}
|
||||
else {
|
||||
// Okay, the arena already has a buffer we can use. This is totally fine.
|
||||
m._capnp.segments[0] = new segment_1.Segment(0, m, arena_1.Arena.getBuffer(0, m._capnp.arena));
|
||||
}
|
||||
if (!m._capnp.segments[0].hasCapacity(8)) {
|
||||
throw new Error(errors_1.MSG_SEGMENT_TOO_SMALL);
|
||||
}
|
||||
// This will leave room for the root pointer.
|
||||
m._capnp.segments[0].allocate(8);
|
||||
return m._capnp.segments[0];
|
||||
}
|
||||
if (id < 0 || id >= segmentLength) {
|
||||
throw new Error(util_1.format(errors_1.MSG_SEGMENT_OUT_OF_BOUNDS, id, m));
|
||||
}
|
||||
return m._capnp.segments[id];
|
||||
}
|
||||
exports.getSegment = getSegment;
|
||||
function initRoot(RootStruct, m) {
|
||||
const root = new RootStruct(m.getSegment(0), 0);
|
||||
struct_1.initStruct(RootStruct._capnp.size, root);
|
||||
trace("Initialized root pointer %s for %s.", root, m);
|
||||
return root;
|
||||
}
|
||||
exports.initRoot = initRoot;
|
||||
/**
|
||||
* Read a pointer in raw form (a packed message with framing headers). Does not
|
||||
* care or attempt to validate the input beyond parsing the message
|
||||
* segments.
|
||||
*
|
||||
* This is typically used by the compiler to load default values, but can be
|
||||
* useful to work with messages with an unknown schema.
|
||||
*
|
||||
* @param {ArrayBuffer} data The raw data to read.
|
||||
* @returns {Pointer} A root pointer.
|
||||
*/
|
||||
function readRawPointer(data) {
|
||||
return new pointers_1.Pointer(new Message(data).getSegment(0), 0);
|
||||
}
|
||||
exports.readRawPointer = readRawPointer;
|
||||
function setRoot(src, m) {
|
||||
pointers_1.Pointer.copyFrom(src, new pointers_1.Pointer(m.getSegment(0), 0));
|
||||
}
|
||||
exports.setRoot = setRoot;
|
||||
function toArrayBuffer(m) {
|
||||
const streamFrame = getStreamFrame(m);
|
||||
// Make sure the first segment is allocated.
|
||||
if (m._capnp.segments.length === 0)
|
||||
getSegment(0, m);
|
||||
const segments = m._capnp.segments;
|
||||
// Add space for the stream framing.
|
||||
const totalLength = streamFrame.byteLength + segments.reduce((l, s) => l + util_1.padToWord(s.byteLength), 0);
|
||||
const out = new Uint8Array(new ArrayBuffer(totalLength));
|
||||
let o = streamFrame.byteLength;
|
||||
out.set(new Uint8Array(streamFrame));
|
||||
segments.forEach((s) => {
|
||||
const segmentLength = util_1.padToWord(s.byteLength);
|
||||
out.set(new Uint8Array(s.buffer, 0, segmentLength), o);
|
||||
o += segmentLength;
|
||||
});
|
||||
return out.buffer;
|
||||
}
|
||||
exports.toArrayBuffer = toArrayBuffer;
|
||||
function toPackedArrayBuffer(m) {
|
||||
const streamFrame = packing_1.pack(getStreamFrame(m));
|
||||
// Make sure the first segment is allocated.
|
||||
if (m._capnp.segments.length === 0)
|
||||
m.getSegment(0);
|
||||
// NOTE: A copy operation can be avoided here if we capture the intermediate array and use that directly in the copy
|
||||
// loop below, rather than have `pack()` copy it to an ArrayBuffer just to have to copy it again later. If the
|
||||
// intermediate array can be avoided altogether that's even better!
|
||||
const segments = m._capnp.segments.map((s) => packing_1.pack(s.buffer, 0, util_1.padToWord(s.byteLength)));
|
||||
const totalLength = streamFrame.byteLength + segments.reduce((l, s) => l + s.byteLength, 0);
|
||||
const out = new Uint8Array(new ArrayBuffer(totalLength));
|
||||
let o = streamFrame.byteLength;
|
||||
out.set(new Uint8Array(streamFrame));
|
||||
segments.forEach((s) => {
|
||||
out.set(new Uint8Array(s), o);
|
||||
o += s.byteLength;
|
||||
});
|
||||
return out.buffer;
|
||||
}
|
||||
exports.toPackedArrayBuffer = toPackedArrayBuffer;
|
||||
function getStreamFrame(m) {
|
||||
const length = m._capnp.segments.length;
|
||||
if (length === 0) {
|
||||
// Don't bother allocating the first segment, just return a single zero word for the frame header.
|
||||
return new Float64Array(1).buffer;
|
||||
}
|
||||
const frameLength = 4 + length * 4 + (1 - (length % 2)) * 4;
|
||||
const out = new DataView(new ArrayBuffer(frameLength));
|
||||
trace("Writing message stream frame with segment count: %d.", length);
|
||||
out.setUint32(0, length - 1, true);
|
||||
m._capnp.segments.forEach((s, i) => {
|
||||
trace("Message segment %d word count: %d.", s.id, s.byteLength / 8);
|
||||
out.setUint32(i * 4 + 4, s.byteLength / 8, true);
|
||||
});
|
||||
return out.buffer;
|
||||
}
|
||||
exports.getStreamFrame = getStreamFrame;
|
||||
//# sourceMappingURL=message.js.map
|
1
node_modules/capnp-ts/src/serialization/message.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/message.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
507
node_modules/capnp-ts/src/serialization/message.ts
generated
vendored
Normal file
507
node_modules/capnp-ts/src/serialization/message.ts
generated
vendored
Normal file
|
@ -0,0 +1,507 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
|
||||
import initTrace from "debug";
|
||||
import { DEFAULT_TRAVERSE_LIMIT, DEFAULT_BUFFER_SIZE } from "../constants";
|
||||
import {
|
||||
MSG_INVALID_FRAME_HEADER,
|
||||
MSG_SEGMENT_OUT_OF_BOUNDS,
|
||||
MSG_SEGMENT_TOO_SMALL,
|
||||
MSG_NO_SEGMENTS_IN_ARENA,
|
||||
} from "../errors";
|
||||
import { dumpBuffer, format, padToWord } from "../util";
|
||||
import { AnyArena, Arena, MultiSegmentArena, SingleSegmentArena, ArenaKind } from "./arena";
|
||||
import { pack, unpack } from "./packing";
|
||||
import { Pointer, StructCtor, PointerType, Struct } from "./pointers";
|
||||
import { Segment } from "./segment";
|
||||
import { getTargetStructSize, validate } from "./pointers/pointer";
|
||||
import { resize, initStruct } from "./pointers/struct";
|
||||
|
||||
const trace = initTrace("capnp:message");
|
||||
trace("load");
|
||||
|
||||
export interface _Message {
|
||||
readonly arena: AnyArena;
|
||||
segments: Segment[];
|
||||
traversalLimit: number;
|
||||
}
|
||||
|
||||
export class Message {
|
||||
static readonly allocateSegment = allocateSegment;
|
||||
static readonly dump = dump;
|
||||
static readonly getRoot = getRoot;
|
||||
static readonly getSegment = getSegment;
|
||||
static readonly initRoot = initRoot;
|
||||
static readonly readRawPointer = readRawPointer;
|
||||
static readonly toArrayBuffer = toArrayBuffer;
|
||||
static readonly toPackedArrayBuffer = toPackedArrayBuffer;
|
||||
|
||||
readonly _capnp: _Message;
|
||||
|
||||
/**
|
||||
* A Cap'n Proto message.
|
||||
*
|
||||
* SECURITY WARNING: In nodejs do not pass a Buffer's internal array buffer into this constructor. Pass the buffer
|
||||
* directly and everything will be fine. If not, your message will potentially be initialized with random memory
|
||||
* contents!
|
||||
*
|
||||
* The constructor method creates a new Message, optionally using a provided arena for segment allocation, or a buffer
|
||||
* to read from.
|
||||
*
|
||||
* @constructor {Message}
|
||||
*
|
||||
* @param {AnyArena|ArrayBufferView|ArrayBuffer} [src] The source for the message.
|
||||
* A value of `undefined` will cause the message to initialize with a single segment arena only big enough for the
|
||||
* root pointer; it will expand as you go. This is a reasonable choice for most messages.
|
||||
*
|
||||
* Passing an arena will cause the message to use that arena for its segment allocation. Contents will be accepted
|
||||
* as-is.
|
||||
*
|
||||
* Passing an array buffer view (like `DataView`, `Uint8Array` or `Buffer`) will create a **copy** of the source
|
||||
* buffer; beware of the potential performance cost!
|
||||
*
|
||||
* @param {boolean} [packed] Whether or not the message is packed. If `true` (the default), the message will be
|
||||
* unpacked.
|
||||
*
|
||||
* @param {boolean} [singleSegment] If true, `src` will be treated as a message consisting of a single segment without
|
||||
* a framing header.
|
||||
*
|
||||
*/
|
||||
constructor(src?: AnyArena | ArrayBufferView | ArrayBuffer, packed = true, singleSegment = false) {
|
||||
this._capnp = initMessage(src, packed, singleSegment);
|
||||
|
||||
if (src && !isAnyArena(src)) preallocateSegments(this);
|
||||
|
||||
trace("new %s", this);
|
||||
}
|
||||
|
||||
allocateSegment(byteLength: number): Segment {
|
||||
return allocateSegment(byteLength, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a pretty-printed string dump of this message; incredibly useful for debugging.
|
||||
*
|
||||
* WARNING: Do not call this method on large messages!
|
||||
*
|
||||
* @returns {string} A big steaming pile of pretty hex digits.
|
||||
*/
|
||||
|
||||
dump(): string {
|
||||
return dump(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a struct pointer for the root of this message. This is primarily used when reading a message; it will not
|
||||
* overwrite existing data.
|
||||
*
|
||||
* @template T
|
||||
* @param {StructCtor<T>} RootStruct The struct type to use as the root.
|
||||
* @returns {T} A struct representing the root of the message.
|
||||
*/
|
||||
|
||||
getRoot<T extends Struct>(RootStruct: StructCtor<T>): T {
|
||||
return getRoot(RootStruct, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a segment by its id.
|
||||
*
|
||||
* This will lazily allocate the first segment if it doesn't already exist.
|
||||
*
|
||||
* @param {number} id The segment id.
|
||||
* @returns {Segment} The requested segment.
|
||||
*/
|
||||
|
||||
getSegment(id: number): Segment {
|
||||
return getSegment(id, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a new message using the provided struct type as the root.
|
||||
*
|
||||
* @template T
|
||||
* @param {StructCtor<T>} RootStruct The struct type to use as the root.
|
||||
* @returns {T} An initialized struct pointing to the root of the message.
|
||||
*/
|
||||
|
||||
initRoot<T extends Struct>(RootStruct: StructCtor<T>): T {
|
||||
return initRoot(RootStruct, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the root of the message to a copy of the given pointer. Used internally
|
||||
* to make copies of pointers for default values.
|
||||
*
|
||||
* @param {Pointer} src The source pointer to copy.
|
||||
* @returns {void}
|
||||
*/
|
||||
|
||||
setRoot(src: Pointer): void {
|
||||
setRoot(src, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Combine the contents of this message's segments into a single array buffer and prepend a stream framing header
|
||||
* containing information about the following segment data.
|
||||
*
|
||||
* @returns {ArrayBuffer} An ArrayBuffer with the contents of this message.
|
||||
*/
|
||||
|
||||
toArrayBuffer(): ArrayBuffer {
|
||||
return toArrayBuffer(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Like `toArrayBuffer()`, but also applies the packing algorithm to the output. This is typically what you want to
|
||||
* use if you're sending the message over a network link or other slow I/O interface where size matters.
|
||||
*
|
||||
* @returns {ArrayBuffer} A packed message.
|
||||
*/
|
||||
|
||||
toPackedArrayBuffer(): ArrayBuffer {
|
||||
return toPackedArrayBuffer(this);
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
return `Message_arena:${this._capnp.arena}`;
|
||||
}
|
||||
}
|
||||
|
||||
export interface CreateMessageOptions {
|
||||
packed?: boolean;
|
||||
singleSegment?: boolean;
|
||||
}
|
||||
|
||||
export function initMessage(
|
||||
src?: AnyArena | ArrayBufferView | ArrayBuffer,
|
||||
packed = true,
|
||||
singleSegment = false
|
||||
): _Message {
|
||||
if (src === undefined) {
|
||||
return {
|
||||
arena: new SingleSegmentArena(),
|
||||
segments: [],
|
||||
traversalLimit: DEFAULT_TRAVERSE_LIMIT,
|
||||
};
|
||||
}
|
||||
|
||||
if (isAnyArena(src)) {
|
||||
return { arena: src, segments: [], traversalLimit: DEFAULT_TRAVERSE_LIMIT };
|
||||
}
|
||||
|
||||
let buf: ArrayBuffer = src as ArrayBuffer;
|
||||
|
||||
if (isArrayBufferView(buf)) {
|
||||
buf = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
||||
}
|
||||
|
||||
if (packed) buf = unpack(buf);
|
||||
|
||||
if (singleSegment) {
|
||||
return {
|
||||
arena: new SingleSegmentArena(buf),
|
||||
segments: [],
|
||||
traversalLimit: DEFAULT_TRAVERSE_LIMIT,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
arena: new MultiSegmentArena(getFramedSegments(buf)),
|
||||
segments: [],
|
||||
traversalLimit: DEFAULT_TRAVERSE_LIMIT,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an _unpacked_ message with a segment framing header, this will generate an ArrayBuffer for each segment in
|
||||
* the message.
|
||||
*
|
||||
* This method is not typically called directly, but can be useful in certain cases.
|
||||
*
|
||||
* @static
|
||||
* @param {ArrayBuffer} message An unpacked message with a framing header.
|
||||
* @returns {ArrayBuffer[]} An array of buffers containing the segment data.
|
||||
*/
|
||||
|
||||
export function getFramedSegments(message: ArrayBuffer): ArrayBuffer[] {
|
||||
const dv = new DataView(message);
|
||||
|
||||
const segmentCount = dv.getUint32(0, true) + 1;
|
||||
|
||||
const segments = new Array(segmentCount) as ArrayBuffer[];
|
||||
|
||||
trace("reading %d framed segments from stream", segmentCount);
|
||||
|
||||
let byteOffset = 4 + segmentCount * 4;
|
||||
byteOffset += byteOffset % 8;
|
||||
|
||||
if (byteOffset + segmentCount * 4 > message.byteLength) {
|
||||
throw new Error(MSG_INVALID_FRAME_HEADER);
|
||||
}
|
||||
|
||||
for (let i = 0; i < segmentCount; i++) {
|
||||
const byteLength = dv.getUint32(4 + i * 4, true) * 8;
|
||||
|
||||
if (byteOffset + byteLength > message.byteLength) {
|
||||
throw new Error(MSG_INVALID_FRAME_HEADER);
|
||||
}
|
||||
|
||||
segments[i] = message.slice(byteOffset, byteOffset + byteLength);
|
||||
|
||||
byteOffset += byteLength;
|
||||
}
|
||||
|
||||
return segments;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called on messages that were constructed with existing data to prepopulate the segments array with
|
||||
* everything we can find in the arena. Each segment will have it's `byteLength` set to the size of its buffer.
|
||||
*
|
||||
* Technically speaking, the message's segments will be "full" after calling this function. Calling this on your own
|
||||
* may void your warranty.
|
||||
*
|
||||
* @param {Message} m The message to allocate.
|
||||
* @returns {void}
|
||||
*/
|
||||
|
||||
export function preallocateSegments(m: Message): void {
|
||||
const numSegments = Arena.getNumSegments(m._capnp.arena);
|
||||
|
||||
if (numSegments < 1) throw new Error(MSG_NO_SEGMENTS_IN_ARENA);
|
||||
|
||||
m._capnp.segments = new Array(numSegments) as Segment[];
|
||||
|
||||
for (let i = 0; i < numSegments; i++) {
|
||||
// Set up each segment so that they're fully allocated to the extents of the existing buffers.
|
||||
|
||||
const buffer = Arena.getBuffer(i, m._capnp.arena);
|
||||
const segment = new Segment(i, m, buffer, buffer.byteLength);
|
||||
|
||||
m._capnp.segments[i] = segment;
|
||||
}
|
||||
}
|
||||
|
||||
function isArrayBufferView(src: ArrayBuffer | ArrayBufferView): src is ArrayBufferView {
|
||||
return (src as { byteOffset?: number }).byteOffset !== undefined;
|
||||
}
|
||||
|
||||
function isAnyArena(o: unknown): o is AnyArena {
|
||||
return (o as { kind?: ArenaKind }).kind !== undefined;
|
||||
}
|
||||
|
||||
export function allocateSegment(byteLength: number, m: Message): Segment {
|
||||
trace("allocating %x bytes for %s", byteLength, m);
|
||||
|
||||
const res = Arena.allocate(byteLength, m._capnp.segments, m._capnp.arena);
|
||||
let s: Segment;
|
||||
|
||||
if (res.id === m._capnp.segments.length) {
|
||||
// Note how we're only allowing new segments in if they're exactly the next one in the array. There is no logical
|
||||
// reason for segments to be created out of order.
|
||||
|
||||
s = new Segment(res.id, m, res.buffer);
|
||||
|
||||
trace("adding new segment %s", s);
|
||||
|
||||
m._capnp.segments.push(s);
|
||||
} else if (res.id < 0 || res.id > m._capnp.segments.length) {
|
||||
throw new Error(format(MSG_SEGMENT_OUT_OF_BOUNDS, res.id, m));
|
||||
} else {
|
||||
s = m._capnp.segments[res.id];
|
||||
|
||||
trace("replacing segment %s with buffer (len:%d)", s, res.buffer.byteLength);
|
||||
|
||||
s.replaceBuffer(res.buffer);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
export function dump(m: Message): string {
|
||||
let r = "";
|
||||
|
||||
if (m._capnp.segments.length === 0) {
|
||||
return "================\nNo Segments\n================\n";
|
||||
}
|
||||
|
||||
for (let i = 0; i < m._capnp.segments.length; i++) {
|
||||
r += `================\nSegment #${i}\n================\n`;
|
||||
|
||||
const { buffer, byteLength } = m._capnp.segments[i];
|
||||
const b = new Uint8Array(buffer, 0, byteLength);
|
||||
|
||||
r += dumpBuffer(b);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
export function getRoot<T extends Struct>(RootStruct: StructCtor<T>, m: Message): T {
|
||||
const root = new RootStruct(m.getSegment(0), 0);
|
||||
|
||||
validate(PointerType.STRUCT, root);
|
||||
|
||||
const ts = getTargetStructSize(root);
|
||||
|
||||
// Make sure the underlying pointer is actually big enough to hold the data and pointers as specified in the schema.
|
||||
// If not a shallow copy of the struct contents needs to be made before returning.
|
||||
|
||||
if (
|
||||
ts.dataByteLength < RootStruct._capnp.size.dataByteLength ||
|
||||
ts.pointerLength < RootStruct._capnp.size.pointerLength
|
||||
) {
|
||||
trace("need to resize root struct %s", root);
|
||||
|
||||
resize(RootStruct._capnp.size, root);
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
export function getSegment(id: number, m: Message): Segment {
|
||||
const segmentLength = m._capnp.segments.length;
|
||||
|
||||
if (id === 0 && segmentLength === 0) {
|
||||
// Segment zero is special. If we have no segments in the arena we'll want to allocate a new one and leave room
|
||||
// for the root pointer.
|
||||
|
||||
const arenaSegments = Arena.getNumSegments(m._capnp.arena);
|
||||
|
||||
if (arenaSegments === 0) {
|
||||
allocateSegment(DEFAULT_BUFFER_SIZE, m);
|
||||
} else {
|
||||
// Okay, the arena already has a buffer we can use. This is totally fine.
|
||||
|
||||
m._capnp.segments[0] = new Segment(0, m, Arena.getBuffer(0, m._capnp.arena));
|
||||
}
|
||||
|
||||
if (!m._capnp.segments[0].hasCapacity(8)) {
|
||||
throw new Error(MSG_SEGMENT_TOO_SMALL);
|
||||
}
|
||||
|
||||
// This will leave room for the root pointer.
|
||||
|
||||
m._capnp.segments[0].allocate(8);
|
||||
|
||||
return m._capnp.segments[0];
|
||||
}
|
||||
|
||||
if (id < 0 || id >= segmentLength) {
|
||||
throw new Error(format(MSG_SEGMENT_OUT_OF_BOUNDS, id, m));
|
||||
}
|
||||
|
||||
return m._capnp.segments[id];
|
||||
}
|
||||
|
||||
export function initRoot<T extends Struct>(RootStruct: StructCtor<T>, m: Message): T {
|
||||
const root = new RootStruct(m.getSegment(0), 0);
|
||||
|
||||
initStruct(RootStruct._capnp.size, root);
|
||||
|
||||
trace("Initialized root pointer %s for %s.", root, m);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a pointer in raw form (a packed message with framing headers). Does not
|
||||
* care or attempt to validate the input beyond parsing the message
|
||||
* segments.
|
||||
*
|
||||
* This is typically used by the compiler to load default values, but can be
|
||||
* useful to work with messages with an unknown schema.
|
||||
*
|
||||
* @param {ArrayBuffer} data The raw data to read.
|
||||
* @returns {Pointer} A root pointer.
|
||||
*/
|
||||
|
||||
export function readRawPointer(data: ArrayBuffer): Pointer {
|
||||
return new Pointer(new Message(data).getSegment(0), 0);
|
||||
}
|
||||
|
||||
export function setRoot(src: Pointer, m: Message): void {
|
||||
Pointer.copyFrom(src, new Pointer(m.getSegment(0), 0));
|
||||
}
|
||||
|
||||
export function toArrayBuffer(m: Message): ArrayBuffer {
|
||||
const streamFrame = getStreamFrame(m);
|
||||
|
||||
// Make sure the first segment is allocated.
|
||||
|
||||
if (m._capnp.segments.length === 0) getSegment(0, m);
|
||||
|
||||
const segments = m._capnp.segments;
|
||||
|
||||
// Add space for the stream framing.
|
||||
|
||||
const totalLength = streamFrame.byteLength + segments.reduce((l, s) => l + padToWord(s.byteLength), 0);
|
||||
const out = new Uint8Array(new ArrayBuffer(totalLength));
|
||||
let o = streamFrame.byteLength;
|
||||
|
||||
out.set(new Uint8Array(streamFrame));
|
||||
|
||||
segments.forEach((s) => {
|
||||
const segmentLength = padToWord(s.byteLength);
|
||||
out.set(new Uint8Array(s.buffer, 0, segmentLength), o);
|
||||
|
||||
o += segmentLength;
|
||||
});
|
||||
|
||||
return out.buffer;
|
||||
}
|
||||
|
||||
export function toPackedArrayBuffer(m: Message): ArrayBuffer {
|
||||
const streamFrame = pack(getStreamFrame(m));
|
||||
|
||||
// Make sure the first segment is allocated.
|
||||
|
||||
if (m._capnp.segments.length === 0) m.getSegment(0);
|
||||
|
||||
// NOTE: A copy operation can be avoided here if we capture the intermediate array and use that directly in the copy
|
||||
// loop below, rather than have `pack()` copy it to an ArrayBuffer just to have to copy it again later. If the
|
||||
// intermediate array can be avoided altogether that's even better!
|
||||
const segments = m._capnp.segments.map((s) => pack(s.buffer, 0, padToWord(s.byteLength)));
|
||||
|
||||
const totalLength = streamFrame.byteLength + segments.reduce((l, s) => l + s.byteLength, 0);
|
||||
const out = new Uint8Array(new ArrayBuffer(totalLength));
|
||||
let o = streamFrame.byteLength;
|
||||
|
||||
out.set(new Uint8Array(streamFrame));
|
||||
|
||||
segments.forEach((s) => {
|
||||
out.set(new Uint8Array(s), o);
|
||||
|
||||
o += s.byteLength;
|
||||
});
|
||||
|
||||
return out.buffer;
|
||||
}
|
||||
|
||||
export function getStreamFrame(m: Message): ArrayBuffer {
|
||||
const length = m._capnp.segments.length;
|
||||
|
||||
if (length === 0) {
|
||||
// Don't bother allocating the first segment, just return a single zero word for the frame header.
|
||||
|
||||
return new Float64Array(1).buffer;
|
||||
}
|
||||
|
||||
const frameLength = 4 + length * 4 + (1 - (length % 2)) * 4;
|
||||
const out = new DataView(new ArrayBuffer(frameLength));
|
||||
|
||||
trace("Writing message stream frame with segment count: %d.", length);
|
||||
|
||||
out.setUint32(0, length - 1, true);
|
||||
|
||||
m._capnp.segments.forEach((s, i) => {
|
||||
trace("Message segment %d word count: %d.", s.id, s.byteLength / 8);
|
||||
|
||||
out.setUint32(i * 4 + 4, s.byteLength / 8, true);
|
||||
});
|
||||
|
||||
return out.buffer;
|
||||
}
|
21
node_modules/capnp-ts/src/serialization/object-size.d.ts
generated
vendored
Normal file
21
node_modules/capnp-ts/src/serialization/object-size.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
/**
|
||||
* A simple object that describes the size of a struct.
|
||||
*
|
||||
* @export
|
||||
* @class ObjectSize
|
||||
*/
|
||||
export declare class ObjectSize {
|
||||
/** The number of bytes required for the data section. */
|
||||
readonly dataByteLength: number;
|
||||
/** The number of pointers in the object. */
|
||||
readonly pointerLength: number;
|
||||
constructor(dataByteLength: number, pointerCount: number);
|
||||
toString(): string;
|
||||
}
|
||||
export declare function getByteLength(o: ObjectSize): number;
|
||||
export declare function getDataWordLength(o: ObjectSize): number;
|
||||
export declare function getWordLength(o: ObjectSize): number;
|
||||
export declare function padToWord(o: ObjectSize): ObjectSize;
|
44
node_modules/capnp-ts/src/serialization/object-size.js
generated
vendored
Normal file
44
node_modules/capnp-ts/src/serialization/object-size.js
generated
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
"use strict";
|
||||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.padToWord = exports.getWordLength = exports.getDataWordLength = exports.getByteLength = exports.ObjectSize = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const debug_1 = tslib_1.__importDefault(require("debug"));
|
||||
const _ = tslib_1.__importStar(require("../util"));
|
||||
const trace = debug_1.default("capnp:object-size");
|
||||
trace("load");
|
||||
/**
|
||||
* A simple object that describes the size of a struct.
|
||||
*
|
||||
* @export
|
||||
* @class ObjectSize
|
||||
*/
|
||||
class ObjectSize {
|
||||
constructor(dataByteLength, pointerCount) {
|
||||
this.dataByteLength = dataByteLength;
|
||||
this.pointerLength = pointerCount;
|
||||
}
|
||||
toString() {
|
||||
return _.format("ObjectSize_dw:%d,pc:%d", getDataWordLength(this), this.pointerLength);
|
||||
}
|
||||
}
|
||||
exports.ObjectSize = ObjectSize;
|
||||
function getByteLength(o) {
|
||||
return o.dataByteLength + o.pointerLength * 8;
|
||||
}
|
||||
exports.getByteLength = getByteLength;
|
||||
function getDataWordLength(o) {
|
||||
return o.dataByteLength / 8;
|
||||
}
|
||||
exports.getDataWordLength = getDataWordLength;
|
||||
function getWordLength(o) {
|
||||
return o.dataByteLength / 8 + o.pointerLength;
|
||||
}
|
||||
exports.getWordLength = getWordLength;
|
||||
function padToWord(o) {
|
||||
return new ObjectSize(_.padToWord(o.dataByteLength), o.pointerLength);
|
||||
}
|
||||
exports.padToWord = padToWord;
|
||||
//# sourceMappingURL=object-size.js.map
|
1
node_modules/capnp-ts/src/serialization/object-size.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/object-size.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"object-size.js","sourceRoot":"","sources":["object-size.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0DAA8B;AAE9B,mDAA6B;AAE7B,MAAM,KAAK,GAAG,eAAS,CAAC,mBAAmB,CAAC,CAAC;AAC7C,KAAK,CAAC,MAAM,CAAC,CAAC;AAEd;;;;;GAKG;AAEH,MAAa,UAAU;IASrB,YAAY,cAAsB,EAAE,YAAoB;QACtD,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAED,QAAQ;QACN,OAAO,CAAC,CAAC,MAAM,CACb,wBAAwB,EACxB,iBAAiB,CAAC,IAAI,CAAC,EACvB,IAAI,CAAC,aAAa,CACnB,CAAC;IACJ,CAAC;CACF;AArBD,gCAqBC;AAED,SAAgB,aAAa,CAAC,CAAa;IACzC,OAAO,CAAC,CAAC,cAAc,GAAG,CAAC,CAAC,aAAa,GAAG,CAAC,CAAC;AAChD,CAAC;AAFD,sCAEC;AAED,SAAgB,iBAAiB,CAAC,CAAa;IAC7C,OAAO,CAAC,CAAC,cAAc,GAAG,CAAC,CAAC;AAC9B,CAAC;AAFD,8CAEC;AAED,SAAgB,aAAa,CAAC,CAAa;IACzC,OAAO,CAAC,CAAC,cAAc,GAAG,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC;AAChD,CAAC;AAFD,sCAEC;AAED,SAAgB,SAAS,CAAC,CAAa;IACrC,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC;AACxE,CAAC;AAFD,8BAEC"}
|
56
node_modules/capnp-ts/src/serialization/object-size.ts
generated
vendored
Normal file
56
node_modules/capnp-ts/src/serialization/object-size.ts
generated
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
|
||||
import initTrace from "debug";
|
||||
|
||||
import * as _ from "../util";
|
||||
|
||||
const trace = initTrace("capnp:object-size");
|
||||
trace("load");
|
||||
|
||||
/**
|
||||
* A simple object that describes the size of a struct.
|
||||
*
|
||||
* @export
|
||||
* @class ObjectSize
|
||||
*/
|
||||
|
||||
export class ObjectSize {
|
||||
/** The number of bytes required for the data section. */
|
||||
|
||||
readonly dataByteLength: number;
|
||||
|
||||
/** The number of pointers in the object. */
|
||||
|
||||
readonly pointerLength: number;
|
||||
|
||||
constructor(dataByteLength: number, pointerCount: number) {
|
||||
this.dataByteLength = dataByteLength;
|
||||
this.pointerLength = pointerCount;
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return _.format(
|
||||
"ObjectSize_dw:%d,pc:%d",
|
||||
getDataWordLength(this),
|
||||
this.pointerLength
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function getByteLength(o: ObjectSize): number {
|
||||
return o.dataByteLength + o.pointerLength * 8;
|
||||
}
|
||||
|
||||
export function getDataWordLength(o: ObjectSize): number {
|
||||
return o.dataByteLength / 8;
|
||||
}
|
||||
|
||||
export function getWordLength(o: ObjectSize): number {
|
||||
return o.dataByteLength / 8 + o.pointerLength;
|
||||
}
|
||||
|
||||
export function padToWord(o: ObjectSize): ObjectSize {
|
||||
return new ObjectSize(_.padToWord(o.dataByteLength), o.pointerLength);
|
||||
}
|
78
node_modules/capnp-ts/src/serialization/packing.d.ts
generated
vendored
Normal file
78
node_modules/capnp-ts/src/serialization/packing.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
/**
|
||||
* Compute the Hamming weight (number of bits set to 1) of a number. Used to figure out how many bytes follow a tag byte
|
||||
* while computing the size of a packed message.
|
||||
*
|
||||
* WARNING: Using this with floating point numbers will void your warranty.
|
||||
*
|
||||
* @param {number} x A real integer.
|
||||
* @returns {number} The hamming weight (integer).
|
||||
*/
|
||||
export declare function getHammingWeight(x: number): number;
|
||||
export declare type byte = number;
|
||||
/**
|
||||
* Compute the tag byte from the 8 bytes of a 64-bit word.
|
||||
*
|
||||
* @param {byte} a The first byte.
|
||||
* @param {byte} b The second byte.
|
||||
* @param {byte} c The third byte.
|
||||
* @param {byte} d The fourth byte.
|
||||
* @param {byte} e The fifth byte.
|
||||
* @param {byte} f The sixth byte.
|
||||
* @param {byte} g The seventh byte.
|
||||
* @param {byte} h The eighth byte (phew!).
|
||||
* @returns {number} The tag byte.
|
||||
*/
|
||||
export declare function getTagByte(a: byte, b: byte, c: byte, d: byte, e: byte, f: byte, g: byte, h: byte): number;
|
||||
/**
|
||||
* Efficiently calculate the length of a packed Cap'n Proto message.
|
||||
*
|
||||
* @export
|
||||
* @param {ArrayBuffer} packed The packed message.
|
||||
* @returns {number} The length of the unpacked message in bytes.
|
||||
*/
|
||||
export declare function getUnpackedByteLength(packed: ArrayBuffer): number;
|
||||
/**
|
||||
* Compute the number of zero bytes that occur in a given 64-bit word, provided as eight separate bytes.
|
||||
*
|
||||
* @param {byte} a The first byte.
|
||||
* @param {byte} b The second byte.
|
||||
* @param {byte} c The third byte.
|
||||
* @param {byte} d The fourth byte.
|
||||
* @param {byte} e The fifth byte.
|
||||
* @param {byte} f The sixth byte.
|
||||
* @param {byte} g The seventh byte.
|
||||
* @param {byte} h The eighth byte (phew!).
|
||||
* @returns {number} The number of these bytes that are zero.
|
||||
*/
|
||||
export declare function getZeroByteCount(a: byte, b: byte, c: byte, d: byte, e: byte, f: byte, g: byte, h: byte): number;
|
||||
/**
|
||||
* Pack a section of a Cap'n Proto message into a compressed format. This will efficiently compress zero bytes (which
|
||||
* are common in idiomatic Cap'n Proto messages) into a compact form.
|
||||
*
|
||||
* For stream-framed messages this is called once for the frame header and once again for each segment in the message.
|
||||
*
|
||||
* The returned array buffer is trimmed to the exact size of the packed message with a single copy operation at the end.
|
||||
* This should be decent on CPU time but does require quite a lot of memory (a normal array is filled up with each
|
||||
* packed byte until the packing is complete).
|
||||
*
|
||||
* @export
|
||||
* @param {ArrayBuffer} unpacked The message to pack.
|
||||
* @param {number} [byteOffset] Starting byte offset to read bytes from, defaults to 0.
|
||||
* @param {number} [byteLength] Total number of bytes to read, defaults to the remainder of the buffer contents.
|
||||
* @returns {ArrayBuffer} A packed version of the message.
|
||||
*/
|
||||
export declare function pack(unpacked: ArrayBuffer, byteOffset?: number, byteLength?: number): ArrayBuffer;
|
||||
/**
|
||||
* Unpack a compressed Cap'n Proto message into a new ArrayBuffer.
|
||||
*
|
||||
* Unlike the `pack` function, this is able to efficiently determine the exact size needed for the output buffer and
|
||||
* runs considerably more efficiently.
|
||||
*
|
||||
* @export
|
||||
* @param {ArrayBuffer} packed An array buffer containing the packed message.
|
||||
* @returns {ArrayBuffer} The unpacked message.
|
||||
*/
|
||||
export declare function unpack(packed: ArrayBuffer): ArrayBuffer;
|
274
node_modules/capnp-ts/src/serialization/packing.js
generated
vendored
Normal file
274
node_modules/capnp-ts/src/serialization/packing.js
generated
vendored
Normal file
|
@ -0,0 +1,274 @@
|
|||
"use strict";
|
||||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.unpack = exports.pack = exports.getZeroByteCount = exports.getUnpackedByteLength = exports.getTagByte = exports.getHammingWeight = void 0;
|
||||
const constants_1 = require("../constants");
|
||||
const errors_1 = require("../errors");
|
||||
/**
|
||||
* Compute the Hamming weight (number of bits set to 1) of a number. Used to figure out how many bytes follow a tag byte
|
||||
* while computing the size of a packed message.
|
||||
*
|
||||
* WARNING: Using this with floating point numbers will void your warranty.
|
||||
*
|
||||
* @param {number} x A real integer.
|
||||
* @returns {number} The hamming weight (integer).
|
||||
*/
|
||||
function getHammingWeight(x) {
|
||||
// Thanks, HACKMEM!
|
||||
let w = x - ((x >> 1) & 0x55555555);
|
||||
w = (w & 0x33333333) + ((w >> 2) & 0x33333333);
|
||||
return (((w + (w >> 4)) & 0x0f0f0f0f) * 0x01010101) >> 24;
|
||||
}
|
||||
exports.getHammingWeight = getHammingWeight;
|
||||
/**
|
||||
* Compute the tag byte from the 8 bytes of a 64-bit word.
|
||||
*
|
||||
* @param {byte} a The first byte.
|
||||
* @param {byte} b The second byte.
|
||||
* @param {byte} c The third byte.
|
||||
* @param {byte} d The fourth byte.
|
||||
* @param {byte} e The fifth byte.
|
||||
* @param {byte} f The sixth byte.
|
||||
* @param {byte} g The seventh byte.
|
||||
* @param {byte} h The eighth byte (phew!).
|
||||
* @returns {number} The tag byte.
|
||||
*/
|
||||
function getTagByte(a, b, c, d, e, f, g, h) {
|
||||
// Yes, it's pretty. Don't touch it.
|
||||
return ((a === 0 ? 0 : 0b00000001) |
|
||||
(b === 0 ? 0 : 0b00000010) |
|
||||
(c === 0 ? 0 : 0b00000100) |
|
||||
(d === 0 ? 0 : 0b00001000) |
|
||||
(e === 0 ? 0 : 0b00010000) |
|
||||
(f === 0 ? 0 : 0b00100000) |
|
||||
(g === 0 ? 0 : 0b01000000) |
|
||||
(h === 0 ? 0 : 0b10000000));
|
||||
}
|
||||
exports.getTagByte = getTagByte;
|
||||
/**
|
||||
* Efficiently calculate the length of a packed Cap'n Proto message.
|
||||
*
|
||||
* @export
|
||||
* @param {ArrayBuffer} packed The packed message.
|
||||
* @returns {number} The length of the unpacked message in bytes.
|
||||
*/
|
||||
function getUnpackedByteLength(packed) {
|
||||
const p = new Uint8Array(packed);
|
||||
let wordLength = 0;
|
||||
let lastTag = 0x77;
|
||||
for (let i = 0; i < p.byteLength;) {
|
||||
const tag = p[i];
|
||||
if (lastTag === 0 /* ZERO */) {
|
||||
wordLength += tag;
|
||||
i++;
|
||||
lastTag = 0x77;
|
||||
}
|
||||
else if (lastTag === 255 /* SPAN */) {
|
||||
wordLength += tag;
|
||||
i += tag * 8 + 1;
|
||||
lastTag = 0x77;
|
||||
}
|
||||
else {
|
||||
wordLength++;
|
||||
i += getHammingWeight(tag) + 1;
|
||||
lastTag = tag;
|
||||
}
|
||||
}
|
||||
return wordLength * 8;
|
||||
}
|
||||
exports.getUnpackedByteLength = getUnpackedByteLength;
|
||||
/**
|
||||
* Compute the number of zero bytes that occur in a given 64-bit word, provided as eight separate bytes.
|
||||
*
|
||||
* @param {byte} a The first byte.
|
||||
* @param {byte} b The second byte.
|
||||
* @param {byte} c The third byte.
|
||||
* @param {byte} d The fourth byte.
|
||||
* @param {byte} e The fifth byte.
|
||||
* @param {byte} f The sixth byte.
|
||||
* @param {byte} g The seventh byte.
|
||||
* @param {byte} h The eighth byte (phew!).
|
||||
* @returns {number} The number of these bytes that are zero.
|
||||
*/
|
||||
function getZeroByteCount(a, b, c, d, e, f, g, h) {
|
||||
return ((a === 0 ? 1 : 0) +
|
||||
(b === 0 ? 1 : 0) +
|
||||
(c === 0 ? 1 : 0) +
|
||||
(d === 0 ? 1 : 0) +
|
||||
(e === 0 ? 1 : 0) +
|
||||
(f === 0 ? 1 : 0) +
|
||||
(g === 0 ? 1 : 0) +
|
||||
(h === 0 ? 1 : 0));
|
||||
}
|
||||
exports.getZeroByteCount = getZeroByteCount;
|
||||
/**
|
||||
* Pack a section of a Cap'n Proto message into a compressed format. This will efficiently compress zero bytes (which
|
||||
* are common in idiomatic Cap'n Proto messages) into a compact form.
|
||||
*
|
||||
* For stream-framed messages this is called once for the frame header and once again for each segment in the message.
|
||||
*
|
||||
* The returned array buffer is trimmed to the exact size of the packed message with a single copy operation at the end.
|
||||
* This should be decent on CPU time but does require quite a lot of memory (a normal array is filled up with each
|
||||
* packed byte until the packing is complete).
|
||||
*
|
||||
* @export
|
||||
* @param {ArrayBuffer} unpacked The message to pack.
|
||||
* @param {number} [byteOffset] Starting byte offset to read bytes from, defaults to 0.
|
||||
* @param {number} [byteLength] Total number of bytes to read, defaults to the remainder of the buffer contents.
|
||||
* @returns {ArrayBuffer} A packed version of the message.
|
||||
*/
|
||||
function pack(unpacked, byteOffset = 0, byteLength) {
|
||||
if (unpacked.byteLength % 8 !== 0)
|
||||
throw new Error(errors_1.MSG_PACK_NOT_WORD_ALIGNED);
|
||||
const src = new Uint8Array(unpacked, byteOffset, byteLength);
|
||||
// TODO: Maybe we should do this with buffers? This costs more than 8x the final compressed size in temporary RAM.
|
||||
const dst = [];
|
||||
/* Just have to be sure it's neither ZERO nor SPAN. */
|
||||
let lastTag = 0x77;
|
||||
/** This is where we need to remember to write the SPAN tag (0xff). */
|
||||
let spanTagOffset = NaN;
|
||||
/** How many words have been copied during the current span. */
|
||||
let spanWordLength = 0;
|
||||
/**
|
||||
* When this hits zero, we've had PACK_SPAN_THRESHOLD zero bytes pass by and it's time to bail from the span.
|
||||
*/
|
||||
let spanThreshold = constants_1.PACK_SPAN_THRESHOLD;
|
||||
for (let srcByteOffset = 0; srcByteOffset < src.byteLength; srcByteOffset += 8) {
|
||||
/** Read in the entire word. Yes, this feels silly but it's fast! */
|
||||
const a = src[srcByteOffset];
|
||||
const b = src[srcByteOffset + 1];
|
||||
const c = src[srcByteOffset + 2];
|
||||
const d = src[srcByteOffset + 3];
|
||||
const e = src[srcByteOffset + 4];
|
||||
const f = src[srcByteOffset + 5];
|
||||
const g = src[srcByteOffset + 6];
|
||||
const h = src[srcByteOffset + 7];
|
||||
const tag = getTagByte(a, b, c, d, e, f, g, h);
|
||||
/** If this is true we'll skip the normal word write logic after the switch statement. */
|
||||
let skipWriteWord = true;
|
||||
switch (lastTag) {
|
||||
case 0 /* ZERO */:
|
||||
// We're writing a span of words with all zeroes in them. See if we need to bail out of the fast path.
|
||||
if (tag !== 0 /* ZERO */ || spanWordLength >= 0xff) {
|
||||
// There's a bit in there or we got too many zeroes. Damn, we need to bail.
|
||||
dst.push(spanWordLength);
|
||||
spanWordLength = 0;
|
||||
skipWriteWord = false;
|
||||
}
|
||||
else {
|
||||
// Kay, let's quickly inc this and go.
|
||||
spanWordLength++;
|
||||
}
|
||||
break;
|
||||
case 255 /* SPAN */: {
|
||||
// We're writing a span of nonzero words.
|
||||
const zeroCount = getZeroByteCount(a, b, c, d, e, f, g, h);
|
||||
// See if we need to bail now.
|
||||
spanThreshold -= zeroCount;
|
||||
if (spanThreshold <= 0 || spanWordLength >= 0xff) {
|
||||
// Alright, time to get packing again. Write the number of words we skipped to the beginning of the span.
|
||||
dst[spanTagOffset] = spanWordLength;
|
||||
spanWordLength = 0;
|
||||
spanThreshold = constants_1.PACK_SPAN_THRESHOLD;
|
||||
// We have to write this word normally.
|
||||
skipWriteWord = false;
|
||||
}
|
||||
else {
|
||||
// Just write this word verbatim.
|
||||
dst.push(a, b, c, d, e, f, g, h);
|
||||
spanWordLength++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Didn't get a special tag last time, let's write this as normal.
|
||||
skipWriteWord = false;
|
||||
break;
|
||||
}
|
||||
// A goto is fast, idk why people keep hatin'.
|
||||
if (skipWriteWord)
|
||||
continue;
|
||||
dst.push(tag);
|
||||
lastTag = tag;
|
||||
if (a !== 0)
|
||||
dst.push(a);
|
||||
if (b !== 0)
|
||||
dst.push(b);
|
||||
if (c !== 0)
|
||||
dst.push(c);
|
||||
if (d !== 0)
|
||||
dst.push(d);
|
||||
if (e !== 0)
|
||||
dst.push(e);
|
||||
if (f !== 0)
|
||||
dst.push(f);
|
||||
if (g !== 0)
|
||||
dst.push(g);
|
||||
if (h !== 0)
|
||||
dst.push(h);
|
||||
// Record the span tag offset if needed, making sure to actually leave room for it.
|
||||
if (tag === 255 /* SPAN */) {
|
||||
spanTagOffset = dst.length;
|
||||
dst.push(0);
|
||||
}
|
||||
}
|
||||
// We're done. If we were writing a span let's finish it.
|
||||
if (lastTag === 0 /* ZERO */) {
|
||||
dst.push(spanWordLength);
|
||||
}
|
||||
else if (lastTag === 255 /* SPAN */) {
|
||||
dst[spanTagOffset] = spanWordLength;
|
||||
}
|
||||
return new Uint8Array(dst).buffer;
|
||||
}
|
||||
exports.pack = pack;
|
||||
/**
|
||||
* Unpack a compressed Cap'n Proto message into a new ArrayBuffer.
|
||||
*
|
||||
* Unlike the `pack` function, this is able to efficiently determine the exact size needed for the output buffer and
|
||||
* runs considerably more efficiently.
|
||||
*
|
||||
* @export
|
||||
* @param {ArrayBuffer} packed An array buffer containing the packed message.
|
||||
* @returns {ArrayBuffer} The unpacked message.
|
||||
*/
|
||||
function unpack(packed) {
|
||||
// We have no choice but to read the packed buffer one byte at a time.
|
||||
const src = new Uint8Array(packed);
|
||||
const dst = new Uint8Array(new ArrayBuffer(getUnpackedByteLength(packed)));
|
||||
/** The last tag byte that we've seen - it starts at a "neutral" value. */
|
||||
let lastTag = 0x77;
|
||||
for (let srcByteOffset = 0, dstByteOffset = 0; srcByteOffset < src.byteLength;) {
|
||||
const tag = src[srcByteOffset];
|
||||
if (lastTag === 0 /* ZERO */) {
|
||||
// We have a span of zeroes. New array buffers are guaranteed to be initialized to zero so we just seek ahead.
|
||||
dstByteOffset += tag * 8;
|
||||
srcByteOffset++;
|
||||
lastTag = 0x77;
|
||||
}
|
||||
else if (lastTag === 255 /* SPAN */) {
|
||||
// We have a span of unpacked bytes. Copy them verbatim from the source buffer.
|
||||
const spanByteLength = tag * 8;
|
||||
dst.set(src.subarray(srcByteOffset + 1, srcByteOffset + 1 + spanByteLength), dstByteOffset);
|
||||
dstByteOffset += spanByteLength;
|
||||
srcByteOffset += 1 + spanByteLength;
|
||||
lastTag = 0x77;
|
||||
}
|
||||
else {
|
||||
// Okay, a normal tag. Let's read past the tag and copy bytes that have a bit set in the tag.
|
||||
srcByteOffset++;
|
||||
for (let i = 1; i <= 0b10000000; i <<= 1) {
|
||||
// We only need to actually touch `dst` if there's a nonzero byte (it's already initialized to zeroes).
|
||||
if ((tag & i) !== 0)
|
||||
dst[dstByteOffset] = src[srcByteOffset++];
|
||||
dstByteOffset++;
|
||||
}
|
||||
lastTag = tag;
|
||||
}
|
||||
}
|
||||
return dst.buffer;
|
||||
}
|
||||
exports.unpack = unpack;
|
||||
//# sourceMappingURL=packing.js.map
|
1
node_modules/capnp-ts/src/serialization/packing.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/packing.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
372
node_modules/capnp-ts/src/serialization/packing.ts
generated
vendored
Normal file
372
node_modules/capnp-ts/src/serialization/packing.ts
generated
vendored
Normal file
|
@ -0,0 +1,372 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
|
||||
import { PACK_SPAN_THRESHOLD } from "../constants";
|
||||
import { MSG_PACK_NOT_WORD_ALIGNED } from "../errors";
|
||||
|
||||
/**
|
||||
* When packing a message there are two tags that are interpreted in a special way: `0x00` and `0xff`.
|
||||
*
|
||||
* @enum {number}
|
||||
*/
|
||||
|
||||
const enum PackedTag {
|
||||
/**
|
||||
* The tag is followed by a single byte which indicates a count of consecutive zero-valued words, minus 1. E.g. if the
|
||||
* tag 0x00 is followed by 0x05, the sequence unpacks to 6 words of zero.
|
||||
*
|
||||
* Or, put another way: the tag is first decoded as if it were not special. Since none of the bits are set, it is
|
||||
* followed by no bytes and expands to a word full of zeros. After that, the next byte is interpreted as a count of
|
||||
* additional words that are also all-zero.
|
||||
*/
|
||||
|
||||
ZERO = 0x00,
|
||||
|
||||
/**
|
||||
* The tag is followed by the bytes of the word (as if it weren’t special), but after those bytes is another byte with
|
||||
* value N. Following that byte is N unpacked words that should be copied directly.
|
||||
*
|
||||
* These unpacked words may contain zeroes; in this implementation a minimum of PACK_SPAN_THRESHOLD zero bytes are
|
||||
* written before ending the span.
|
||||
*
|
||||
* The purpose of this rule is to minimize the impact of packing on data that doesn’t contain any zeros – in
|
||||
* particular, long text blobs. Because of this rule, the worst-case space overhead of packing is 2 bytes per 2 KiB of
|
||||
* input (256 words = 2KiB).
|
||||
*/
|
||||
|
||||
SPAN = 0xff,
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the Hamming weight (number of bits set to 1) of a number. Used to figure out how many bytes follow a tag byte
|
||||
* while computing the size of a packed message.
|
||||
*
|
||||
* WARNING: Using this with floating point numbers will void your warranty.
|
||||
*
|
||||
* @param {number} x A real integer.
|
||||
* @returns {number} The hamming weight (integer).
|
||||
*/
|
||||
|
||||
export function getHammingWeight(x: number): number {
|
||||
// Thanks, HACKMEM!
|
||||
|
||||
let w = x - ((x >> 1) & 0x55555555);
|
||||
w = (w & 0x33333333) + ((w >> 2) & 0x33333333);
|
||||
return (((w + (w >> 4)) & 0x0f0f0f0f) * 0x01010101) >> 24;
|
||||
}
|
||||
|
||||
export type byte = number;
|
||||
|
||||
/**
|
||||
* Compute the tag byte from the 8 bytes of a 64-bit word.
|
||||
*
|
||||
* @param {byte} a The first byte.
|
||||
* @param {byte} b The second byte.
|
||||
* @param {byte} c The third byte.
|
||||
* @param {byte} d The fourth byte.
|
||||
* @param {byte} e The fifth byte.
|
||||
* @param {byte} f The sixth byte.
|
||||
* @param {byte} g The seventh byte.
|
||||
* @param {byte} h The eighth byte (phew!).
|
||||
* @returns {number} The tag byte.
|
||||
*/
|
||||
|
||||
export function getTagByte(a: byte, b: byte, c: byte, d: byte, e: byte, f: byte, g: byte, h: byte): number {
|
||||
// Yes, it's pretty. Don't touch it.
|
||||
|
||||
return (
|
||||
(a === 0 ? 0 : 0b00000001) |
|
||||
(b === 0 ? 0 : 0b00000010) |
|
||||
(c === 0 ? 0 : 0b00000100) |
|
||||
(d === 0 ? 0 : 0b00001000) |
|
||||
(e === 0 ? 0 : 0b00010000) |
|
||||
(f === 0 ? 0 : 0b00100000) |
|
||||
(g === 0 ? 0 : 0b01000000) |
|
||||
(h === 0 ? 0 : 0b10000000)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Efficiently calculate the length of a packed Cap'n Proto message.
|
||||
*
|
||||
* @export
|
||||
* @param {ArrayBuffer} packed The packed message.
|
||||
* @returns {number} The length of the unpacked message in bytes.
|
||||
*/
|
||||
|
||||
export function getUnpackedByteLength(packed: ArrayBuffer): number {
|
||||
const p = new Uint8Array(packed);
|
||||
let wordLength = 0;
|
||||
let lastTag = 0x77;
|
||||
|
||||
for (let i = 0; i < p.byteLength; ) {
|
||||
const tag = p[i];
|
||||
|
||||
if (lastTag === PackedTag.ZERO) {
|
||||
wordLength += tag;
|
||||
|
||||
i++;
|
||||
|
||||
lastTag = 0x77;
|
||||
} else if (lastTag === PackedTag.SPAN) {
|
||||
wordLength += tag;
|
||||
|
||||
i += tag * 8 + 1;
|
||||
|
||||
lastTag = 0x77;
|
||||
} else {
|
||||
wordLength++;
|
||||
|
||||
i += getHammingWeight(tag) + 1;
|
||||
|
||||
lastTag = tag;
|
||||
}
|
||||
}
|
||||
|
||||
return wordLength * 8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the number of zero bytes that occur in a given 64-bit word, provided as eight separate bytes.
|
||||
*
|
||||
* @param {byte} a The first byte.
|
||||
* @param {byte} b The second byte.
|
||||
* @param {byte} c The third byte.
|
||||
* @param {byte} d The fourth byte.
|
||||
* @param {byte} e The fifth byte.
|
||||
* @param {byte} f The sixth byte.
|
||||
* @param {byte} g The seventh byte.
|
||||
* @param {byte} h The eighth byte (phew!).
|
||||
* @returns {number} The number of these bytes that are zero.
|
||||
*/
|
||||
|
||||
export function getZeroByteCount(a: byte, b: byte, c: byte, d: byte, e: byte, f: byte, g: byte, h: byte): number {
|
||||
return (
|
||||
(a === 0 ? 1 : 0) +
|
||||
(b === 0 ? 1 : 0) +
|
||||
(c === 0 ? 1 : 0) +
|
||||
(d === 0 ? 1 : 0) +
|
||||
(e === 0 ? 1 : 0) +
|
||||
(f === 0 ? 1 : 0) +
|
||||
(g === 0 ? 1 : 0) +
|
||||
(h === 0 ? 1 : 0)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pack a section of a Cap'n Proto message into a compressed format. This will efficiently compress zero bytes (which
|
||||
* are common in idiomatic Cap'n Proto messages) into a compact form.
|
||||
*
|
||||
* For stream-framed messages this is called once for the frame header and once again for each segment in the message.
|
||||
*
|
||||
* The returned array buffer is trimmed to the exact size of the packed message with a single copy operation at the end.
|
||||
* This should be decent on CPU time but does require quite a lot of memory (a normal array is filled up with each
|
||||
* packed byte until the packing is complete).
|
||||
*
|
||||
* @export
|
||||
* @param {ArrayBuffer} unpacked The message to pack.
|
||||
* @param {number} [byteOffset] Starting byte offset to read bytes from, defaults to 0.
|
||||
* @param {number} [byteLength] Total number of bytes to read, defaults to the remainder of the buffer contents.
|
||||
* @returns {ArrayBuffer} A packed version of the message.
|
||||
*/
|
||||
|
||||
export function pack(unpacked: ArrayBuffer, byteOffset = 0, byteLength?: number): ArrayBuffer {
|
||||
if (unpacked.byteLength % 8 !== 0) throw new Error(MSG_PACK_NOT_WORD_ALIGNED);
|
||||
|
||||
const src = new Uint8Array(unpacked, byteOffset, byteLength);
|
||||
|
||||
// TODO: Maybe we should do this with buffers? This costs more than 8x the final compressed size in temporary RAM.
|
||||
|
||||
const dst: number[] = [];
|
||||
|
||||
/* Just have to be sure it's neither ZERO nor SPAN. */
|
||||
|
||||
let lastTag = 0x77;
|
||||
|
||||
/** This is where we need to remember to write the SPAN tag (0xff). */
|
||||
|
||||
let spanTagOffset = NaN;
|
||||
|
||||
/** How many words have been copied during the current span. */
|
||||
|
||||
let spanWordLength = 0;
|
||||
|
||||
/**
|
||||
* When this hits zero, we've had PACK_SPAN_THRESHOLD zero bytes pass by and it's time to bail from the span.
|
||||
*/
|
||||
|
||||
let spanThreshold = PACK_SPAN_THRESHOLD;
|
||||
|
||||
for (let srcByteOffset = 0; srcByteOffset < src.byteLength; srcByteOffset += 8) {
|
||||
/** Read in the entire word. Yes, this feels silly but it's fast! */
|
||||
|
||||
const a = src[srcByteOffset];
|
||||
const b = src[srcByteOffset + 1];
|
||||
const c = src[srcByteOffset + 2];
|
||||
const d = src[srcByteOffset + 3];
|
||||
const e = src[srcByteOffset + 4];
|
||||
const f = src[srcByteOffset + 5];
|
||||
const g = src[srcByteOffset + 6];
|
||||
const h = src[srcByteOffset + 7];
|
||||
|
||||
const tag = getTagByte(a, b, c, d, e, f, g, h);
|
||||
|
||||
/** If this is true we'll skip the normal word write logic after the switch statement. */
|
||||
|
||||
let skipWriteWord = true;
|
||||
|
||||
switch (lastTag) {
|
||||
case PackedTag.ZERO:
|
||||
// We're writing a span of words with all zeroes in them. See if we need to bail out of the fast path.
|
||||
|
||||
if (tag !== PackedTag.ZERO || spanWordLength >= 0xff) {
|
||||
// There's a bit in there or we got too many zeroes. Damn, we need to bail.
|
||||
|
||||
dst.push(spanWordLength);
|
||||
spanWordLength = 0;
|
||||
|
||||
skipWriteWord = false;
|
||||
} else {
|
||||
// Kay, let's quickly inc this and go.
|
||||
|
||||
spanWordLength++;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case PackedTag.SPAN: {
|
||||
// We're writing a span of nonzero words.
|
||||
|
||||
const zeroCount = getZeroByteCount(a, b, c, d, e, f, g, h);
|
||||
|
||||
// See if we need to bail now.
|
||||
|
||||
spanThreshold -= zeroCount;
|
||||
|
||||
if (spanThreshold <= 0 || spanWordLength >= 0xff) {
|
||||
// Alright, time to get packing again. Write the number of words we skipped to the beginning of the span.
|
||||
|
||||
dst[spanTagOffset] = spanWordLength;
|
||||
spanWordLength = 0;
|
||||
|
||||
spanThreshold = PACK_SPAN_THRESHOLD;
|
||||
|
||||
// We have to write this word normally.
|
||||
|
||||
skipWriteWord = false;
|
||||
} else {
|
||||
// Just write this word verbatim.
|
||||
|
||||
dst.push(a, b, c, d, e, f, g, h);
|
||||
|
||||
spanWordLength++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Didn't get a special tag last time, let's write this as normal.
|
||||
|
||||
skipWriteWord = false;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// A goto is fast, idk why people keep hatin'.
|
||||
if (skipWriteWord) continue;
|
||||
|
||||
dst.push(tag);
|
||||
lastTag = tag;
|
||||
|
||||
if (a !== 0) dst.push(a);
|
||||
if (b !== 0) dst.push(b);
|
||||
if (c !== 0) dst.push(c);
|
||||
if (d !== 0) dst.push(d);
|
||||
if (e !== 0) dst.push(e);
|
||||
if (f !== 0) dst.push(f);
|
||||
if (g !== 0) dst.push(g);
|
||||
if (h !== 0) dst.push(h);
|
||||
|
||||
// Record the span tag offset if needed, making sure to actually leave room for it.
|
||||
|
||||
if (tag === PackedTag.SPAN) {
|
||||
spanTagOffset = dst.length;
|
||||
|
||||
dst.push(0);
|
||||
}
|
||||
}
|
||||
|
||||
// We're done. If we were writing a span let's finish it.
|
||||
|
||||
if (lastTag === PackedTag.ZERO) {
|
||||
dst.push(spanWordLength);
|
||||
} else if (lastTag === PackedTag.SPAN) {
|
||||
dst[spanTagOffset] = spanWordLength;
|
||||
}
|
||||
|
||||
return new Uint8Array(dst).buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack a compressed Cap'n Proto message into a new ArrayBuffer.
|
||||
*
|
||||
* Unlike the `pack` function, this is able to efficiently determine the exact size needed for the output buffer and
|
||||
* runs considerably more efficiently.
|
||||
*
|
||||
* @export
|
||||
* @param {ArrayBuffer} packed An array buffer containing the packed message.
|
||||
* @returns {ArrayBuffer} The unpacked message.
|
||||
*/
|
||||
|
||||
export function unpack(packed: ArrayBuffer): ArrayBuffer {
|
||||
// We have no choice but to read the packed buffer one byte at a time.
|
||||
|
||||
const src = new Uint8Array(packed);
|
||||
const dst = new Uint8Array(new ArrayBuffer(getUnpackedByteLength(packed)));
|
||||
|
||||
/** The last tag byte that we've seen - it starts at a "neutral" value. */
|
||||
|
||||
let lastTag = 0x77;
|
||||
|
||||
for (let srcByteOffset = 0, dstByteOffset = 0; srcByteOffset < src.byteLength; ) {
|
||||
const tag = src[srcByteOffset];
|
||||
|
||||
if (lastTag === PackedTag.ZERO) {
|
||||
// We have a span of zeroes. New array buffers are guaranteed to be initialized to zero so we just seek ahead.
|
||||
|
||||
dstByteOffset += tag * 8;
|
||||
|
||||
srcByteOffset++;
|
||||
|
||||
lastTag = 0x77;
|
||||
} else if (lastTag === PackedTag.SPAN) {
|
||||
// We have a span of unpacked bytes. Copy them verbatim from the source buffer.
|
||||
|
||||
const spanByteLength = tag * 8;
|
||||
|
||||
dst.set(src.subarray(srcByteOffset + 1, srcByteOffset + 1 + spanByteLength), dstByteOffset);
|
||||
|
||||
dstByteOffset += spanByteLength;
|
||||
srcByteOffset += 1 + spanByteLength;
|
||||
|
||||
lastTag = 0x77;
|
||||
} else {
|
||||
// Okay, a normal tag. Let's read past the tag and copy bytes that have a bit set in the tag.
|
||||
|
||||
srcByteOffset++;
|
||||
|
||||
for (let i = 1; i <= 0b10000000; i <<= 1) {
|
||||
// We only need to actually touch `dst` if there's a nonzero byte (it's already initialized to zeroes).
|
||||
|
||||
if ((tag & i) !== 0) dst[dstByteOffset] = src[srcByteOffset++];
|
||||
|
||||
dstByteOffset++;
|
||||
}
|
||||
|
||||
lastTag = tag;
|
||||
}
|
||||
}
|
||||
|
||||
return dst.buffer;
|
||||
}
|
6
node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.d.ts
generated
vendored
Normal file
6
node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
import { ListCtor } from "./list";
|
||||
import { Pointer } from "./pointer";
|
||||
export declare const AnyPointerList: ListCtor<Pointer>;
|
10
node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.js
generated
vendored
Normal file
10
node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.js
generated
vendored
Normal file
|
@ -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
|
1
node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.js.map
generated
vendored
Normal file
|
@ -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"}
|
9
node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.ts
generated
vendored
Normal file
9
node_modules/capnp-ts/src/serialization/pointers/any-pointer-list.ts
generated
vendored
Normal file
|
@ -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);
|
10
node_modules/capnp-ts/src/serialization/pointers/bool-list.d.ts
generated
vendored
Normal file
10
node_modules/capnp-ts/src/serialization/pointers/bool-list.d.ts
generated
vendored
Normal file
|
@ -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;
|
||||
}
|
38
node_modules/capnp-ts/src/serialization/pointers/bool-list.js
generated
vendored
Normal file
38
node_modules/capnp-ts/src/serialization/pointers/bool-list.js
generated
vendored
Normal file
|
@ -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
|
1
node_modules/capnp-ts/src/serialization/pointers/bool-list.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/pointers/bool-list.js.map
generated
vendored
Normal file
|
@ -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"}
|
41
node_modules/capnp-ts/src/serialization/pointers/bool-list.ts
generated
vendored
Normal file
41
node_modules/capnp-ts/src/serialization/pointers/bool-list.ts
generated
vendored
Normal file
|
@ -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()}`;
|
||||
}
|
||||
}
|
6
node_modules/capnp-ts/src/serialization/pointers/composite-list.d.ts
generated
vendored
Normal file
6
node_modules/capnp-ts/src/serialization/pointers/composite-list.d.ts
generated
vendored
Normal file
|
@ -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>;
|
35
node_modules/capnp-ts/src/serialization/pointers/composite-list.js
generated
vendored
Normal file
35
node_modules/capnp-ts/src/serialization/pointers/composite-list.js
generated
vendored
Normal file
|
@ -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
|
1
node_modules/capnp-ts/src/serialization/pointers/composite-list.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/pointers/composite-list.js.map
generated
vendored
Normal file
|
@ -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"}
|
35
node_modules/capnp-ts/src/serialization/pointers/composite-list.ts
generated
vendored
Normal file
35
node_modules/capnp-ts/src/serialization/pointers/composite-list.ts
generated
vendored
Normal file
|
@ -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()}`;
|
||||
}
|
||||
};
|
||||
}
|
6
node_modules/capnp-ts/src/serialization/pointers/data-list.d.ts
generated
vendored
Normal file
6
node_modules/capnp-ts/src/serialization/pointers/data-list.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* @author jdiaz5513
|
||||
*/
|
||||
import { Data } from "./data";
|
||||
import { ListCtor } from "./list";
|
||||
export declare const DataList: ListCtor<Data>;
|
10
node_modules/capnp-ts/src/serialization/pointers/data-list.js
generated
vendored
Normal file
10
node_modules/capnp-ts/src/serialization/pointers/data-list.js
generated
vendored
Normal file
|
@ -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
|
1
node_modules/capnp-ts/src/serialization/pointers/data-list.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/pointers/data-list.js.map
generated
vendored
Normal file
|
@ -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"}
|
9
node_modules/capnp-ts/src/serialization/pointers/data-list.ts
generated
vendored
Normal file
9
node_modules/capnp-ts/src/serialization/pointers/data-list.ts
generated
vendored
Normal file
|
@ -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);
|
67
node_modules/capnp-ts/src/serialization/pointers/data.d.ts
generated
vendored
Normal file
67
node_modules/capnp-ts/src/serialization/pointers/data.d.ts
generated
vendored
Normal file
|
@ -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;
|
||||
}
|
118
node_modules/capnp-ts/src/serialization/pointers/data.js
generated
vendored
Normal file
118
node_modules/capnp-ts/src/serialization/pointers/data.js
generated
vendored
Normal file
|
@ -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
|
1
node_modules/capnp-ts/src/serialization/pointers/data.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/pointers/data.js.map
generated
vendored
Normal file
|
@ -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,MAAM,SAAS,GAAG,GAAG,CAAC,UAAU,CAAC;QAEjC,MAAM,CAAC,GACL,GAAG,YAAY,WAAW;YACxB,CAAC,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC;YACrB,CAAC,CAAC,IAAI,UAAU,CACZ,GAAG,CAAC,MAAM,EACV,GAAG,CAAC,UAAU,EACd,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAC/B,CAAC;QAER,MAAM,CAAC,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QAE3E,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAET,IAAI,SAAS,GAAG,SAAS,EAAE;YACzB,KAAK,CACH,oDAAoD,EACpD,SAAS,GAAG,SAAS,EACrB,IAAI,CACL,CAAC;YAEF,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;SACjC;aAAM,IAAI,SAAS,GAAG,SAAS,EAAE;YAChC,KAAK,CACH,4DAA4D,EAC5D,SAAS,GAAG,SAAS,EACrB,IAAI,CACL,CAAC;SACH;IACH,CAAC;IAED;;;;;OAKG;IAEH,GAAG,CAAC,UAAkB;QACpB,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,GAAG,UAAU,CAAC,CAAC;IACvD,CAAC;IAED;;;;;;OAMG;IAEH,GAAG,CAAC,UAAkB,EAAE,KAAa;QACnC,MAAM,CAAC,GAAG,oBAAU,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,GAAG,UAAU,EAAE,KAAK,CAAC,CAAC;IACvD,CAAC;IAED;;;;;;OAMG;IAEH,aAAa;QACX,MAAM,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"}
|
158
node_modules/capnp-ts/src/serialization/pointers/data.ts
generated
vendored
Normal file
158
node_modules/capnp-ts/src/serialization/pointers/data.ts
generated
vendored
Normal file
|
@ -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());
|
||||
}
|
||||
}
|
10
node_modules/capnp-ts/src/serialization/pointers/float32-list.d.ts
generated
vendored
Normal file
10
node_modules/capnp-ts/src/serialization/pointers/float32-list.d.ts
generated
vendored
Normal file
|
@ -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;
|
||||
}
|
32
node_modules/capnp-ts/src/serialization/pointers/float32-list.js
generated
vendored
Normal file
32
node_modules/capnp-ts/src/serialization/pointers/float32-list.js
generated
vendored
Normal file
|
@ -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
|
1
node_modules/capnp-ts/src/serialization/pointers/float32-list.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/pointers/float32-list.js.map
generated
vendored
Normal file
|
@ -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"}
|
35
node_modules/capnp-ts/src/serialization/pointers/float32-list.ts
generated
vendored
Normal file
35
node_modules/capnp-ts/src/serialization/pointers/float32-list.ts
generated
vendored
Normal file
|
@ -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()}`;
|
||||
}
|
||||
}
|
10
node_modules/capnp-ts/src/serialization/pointers/float64-list.d.ts
generated
vendored
Normal file
10
node_modules/capnp-ts/src/serialization/pointers/float64-list.d.ts
generated
vendored
Normal file
|
@ -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;
|
||||
}
|
32
node_modules/capnp-ts/src/serialization/pointers/float64-list.js
generated
vendored
Normal file
32
node_modules/capnp-ts/src/serialization/pointers/float64-list.js
generated
vendored
Normal file
|
@ -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
|
1
node_modules/capnp-ts/src/serialization/pointers/float64-list.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/pointers/float64-list.js.map
generated
vendored
Normal file
|
@ -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"}
|
35
node_modules/capnp-ts/src/serialization/pointers/float64-list.ts
generated
vendored
Normal file
35
node_modules/capnp-ts/src/serialization/pointers/float64-list.ts
generated
vendored
Normal file
|
@ -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()}`;
|
||||
}
|
||||
}
|
0
node_modules/capnp-ts/src/serialization/pointers/group.d.ts
generated
vendored
Normal file
0
node_modules/capnp-ts/src/serialization/pointers/group.d.ts
generated
vendored
Normal file
2
node_modules/capnp-ts/src/serialization/pointers/group.js
generated
vendored
Normal file
2
node_modules/capnp-ts/src/serialization/pointers/group.js
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
//# sourceMappingURL=group.js.map
|
1
node_modules/capnp-ts/src/serialization/pointers/group.js.map
generated
vendored
Normal file
1
node_modules/capnp-ts/src/serialization/pointers/group.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"group.js","sourceRoot":"","sources":["group.ts"],"names":[],"mappings":""}
|
0
node_modules/capnp-ts/src/serialization/pointers/group.ts
generated
vendored
Normal file
0
node_modules/capnp-ts/src/serialization/pointers/group.ts
generated
vendored
Normal file
30
node_modules/capnp-ts/src/serialization/pointers/index.d.ts
generated
vendored
Normal file
30
node_modules/capnp-ts/src/serialization/pointers/index.d.ts
generated
vendored
Normal file
|
@ -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";
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue