@rotu/structview 0.10.1 → 0.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/esm/bigendian.d.ts +7 -0
- package/esm/bigendian.d.ts.map +1 -0
- package/esm/bigendian.js +6 -0
- package/esm/core.d.ts +3 -0
- package/esm/core.d.ts.map +1 -1
- package/esm/core.js +8 -0
- package/esm/mod.d.ts +1 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +1 -0
- package/esm/types.d.ts +6 -0
- package/esm/types.d.ts.map +1 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -85,3 +85,21 @@ for (const dish of myMenu) {
|
|
|
85
85
|
console.log(`${dish.name} costs \$${dish.price}`)
|
|
86
86
|
}
|
|
87
87
|
```
|
|
88
|
+
|
|
89
|
+
# Gotchas and rough edges
|
|
90
|
+
|
|
91
|
+
1. Resizable structs are not yet implemented. Resizable `Arraybuffer`s only
|
|
92
|
+
allow you to add or remove bytes at the end which is not the best experience.
|
|
93
|
+
You can still create a `Struct` on top of a resizable `ArrayBuffer` at your
|
|
94
|
+
own risk.
|
|
95
|
+
2. Struct fields have a byte offset specified in bytes from the beginning of the
|
|
96
|
+
declaring struct. This is a bit verbose but is a deliberate choice.
|
|
97
|
+
- It prevents changes to the struct from accidentally changing other fields
|
|
98
|
+
- It implicitly allows C-style `union`s for free.
|
|
99
|
+
- Different languages and compilers have different expectations for alignment
|
|
100
|
+
and spacing of fields.
|
|
101
|
+
3. Be careful using `TypedArray`s. They have an alignment requirement relative
|
|
102
|
+
to their underlying `ArrayBuffer`.
|
|
103
|
+
4. `Struct` classes define properties on the prototype, _not_ on the instance.
|
|
104
|
+
That means spread syntax (`x = {...s}`) and `JSON.stringify(s)` will _not_
|
|
105
|
+
reflect inherited fields.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Property descriptor factories for big-endian numbers
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/** @deprecated Import from `fields.ts` instead */
|
|
6
|
+
export { f16be, f32be, f64be, i16be, i32be, i64be, u16be, u32be, u64be, } from "./fields.js";
|
|
7
|
+
//# sourceMappingURL=bigendian.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bigendian.d.ts","sourceRoot":"","sources":["../src/bigendian.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,kDAAkD;AAClD,OAAO,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,GACN,MAAM,aAAa,CAAA"}
|
package/esm/bigendian.js
ADDED
package/esm/core.d.ts
CHANGED
|
@@ -31,6 +31,9 @@ export declare class Struct {
|
|
|
31
31
|
* @param arg options for creating the struct.
|
|
32
32
|
* If options has a `.buffer` property, we will use that as the backing memory (e.g. any TypedArray or DataView).
|
|
33
33
|
* If options has no `.buffer` property but has a `.byteLength`, we will allocate a new buffer for the object.
|
|
34
|
+
* @remarks
|
|
35
|
+
* The reason we don't use a positional argument for `byteLength` is because it's confusing - TypedArray constructors take a `length` argument that is in elements, not bytes.
|
|
36
|
+
* Another reason is because this allows you to pass in a `DataView` or a `TypedArray` directly to reinterpret its memory as a struct.
|
|
34
37
|
*/
|
|
35
38
|
constructor(arg: {
|
|
36
39
|
readonly buffer: ArrayBufferLike;
|
package/esm/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,SAAS,EAET,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,cAAc,eAAgC,CAAA;AAE3D;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,C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CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;QAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;KAC5B;CAyBN;AAsBD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,CAAC,KAAK,SAAS,qBAAqB,EACpE,mBAAmB,EAAE,KAAK,GACzB,sBAAsB,CAAC,OAAO,MAAM,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,CAE9D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,SAAS,MAAM,EAC7C,YAAY,EAAE;IACZ,kDAAkD;IAClD,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAA;IACxC,6DAA6D;IAC7D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,oIAAoI;IACpI,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CACzB,GACA,iBAAiB,CAClB;IACE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACzB,GAAG,QAAQ,CAAC,IAAI,CAAC,CACnB,CAqDA"}
|
package/esm/core.js
CHANGED
|
@@ -52,6 +52,9 @@ export class Struct {
|
|
|
52
52
|
* @param arg options for creating the struct.
|
|
53
53
|
* If options has a `.buffer` property, we will use that as the backing memory (e.g. any TypedArray or DataView).
|
|
54
54
|
* If options has no `.buffer` property but has a `.byteLength`, we will allocate a new buffer for the object.
|
|
55
|
+
* @remarks
|
|
56
|
+
* The reason we don't use a positional argument for `byteLength` is because it's confusing - TypedArray constructors take a `length` argument that is in elements, not bytes.
|
|
57
|
+
* Another reason is because this allows you to pass in a `DataView` or a `TypedArray` directly to reinterpret its memory as a struct.
|
|
55
58
|
*/
|
|
56
59
|
constructor(arg) {
|
|
57
60
|
Object.defineProperty(this, _a, {
|
|
@@ -106,6 +109,9 @@ export function defineStruct(propertyDescriptors) {
|
|
|
106
109
|
export function defineArray(arrayOptions) {
|
|
107
110
|
var _StructArray_struct, _StructArray_length, _StructArray_byteStride;
|
|
108
111
|
const { struct, byteStride, length } = arrayOptions;
|
|
112
|
+
/**
|
|
113
|
+
* Class representing an array of structs.
|
|
114
|
+
*/
|
|
109
115
|
class StructArray extends Struct {
|
|
110
116
|
constructor() {
|
|
111
117
|
super(...arguments);
|
|
@@ -130,6 +136,8 @@ export function defineArray(arrayOptions) {
|
|
|
130
136
|
* A view of the item at the given index
|
|
131
137
|
* @param index
|
|
132
138
|
* @returns a new struct instance viewing the item at the given index
|
|
139
|
+
* @remarks
|
|
140
|
+
* Items are gettable but not settable. It is assumed that you will mutate the struct in place.
|
|
133
141
|
*/
|
|
134
142
|
item(index) {
|
|
135
143
|
const ctor = __classPrivateFieldGet(this, _StructArray_struct, "f");
|
package/esm/mod.d.ts
CHANGED
package/esm/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,mBAAmB,YAAY,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,mBAAmB,YAAY,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAE3B,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA"}
|
package/esm/mod.js
CHANGED
package/esm/types.d.ts
CHANGED
|
@@ -24,6 +24,9 @@ export type TPropertyDescriptor<T> = {
|
|
|
24
24
|
value?: T;
|
|
25
25
|
writable?: boolean;
|
|
26
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Object type that would result from Object.defineProperties(p:Props)
|
|
29
|
+
*/
|
|
27
30
|
export type MixinFromProps<Props extends object> = {
|
|
28
31
|
-readonly [K in keyof Props]: Props[K] extends TPropertyDescriptor<infer V> ? V : unknown;
|
|
29
32
|
};
|
|
@@ -38,6 +41,9 @@ export type StructConstructor<T extends object> = {
|
|
|
38
41
|
readonly byteLength: number;
|
|
39
42
|
}): T;
|
|
40
43
|
};
|
|
44
|
+
/**
|
|
45
|
+
* Type of a TypedArray subclass constructor
|
|
46
|
+
*/
|
|
41
47
|
export type TypedArraySpecies<T> = {
|
|
42
48
|
new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): T;
|
|
43
49
|
readonly BYTES_PER_ELEMENT: number;
|
package/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE/C,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAA;CACpC,CAAA;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;CAAE,CAAA;AAExD,MAAM,MAAM,sBAAsB,CAChC,IAAI,SAAS,WAAW,CAAC,MAAM,CAAC,EAChC,KAAK,IAEH;KAAG,CAAC,IAAI,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC;CAAE,GAC9B;IACA,KACE,GAAG,IAAI,EAAE,qBAAqB,CAAC,IAAI,CAAC,GACnC,YAAY,CAAC,IAAI,CAAC,GAAG;SAAG,CAAC,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;KAAE,CAAA;CACzD,CAAA;AAEH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI;IACnC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,GAAG,CAAC,IAAI,CAAC,CAAA;IACT,GA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AY,CAAC,EAAE,OAAO,CAAA;IACtB,GAAG,CAAC,IAAI,CAAC,CAAA;IACT,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,CAAA;IACrB,KAAK,CAAC,EAAE,CAAC,CAAA;IACT,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,KAAK,SAAS,MAAM,IAAI;IACjD,CAAC,UAAU,CAAC,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,mBAAmB,CAAC,MAAM,CAAC,CAAC,GACvE,CAAC,GACD,OAAO;CACZ,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,wBAAwB,CAAC,CAAC,IAClC,QAAQ,CAAC,SAAS,CAAC,GACnB,mBAAmB,CAAC,CAAC,CAAC,CAAA;AAC1B,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,MAAM,IAAI;IAChD,KAAK,GAAG,EAAE;QACR,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAA;QAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;QAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;KAC5B,GAAG,CAAC,CAAA;CACN,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI;IACjC,KACE,MAAM,EAAE,eAAe,EACvB,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,GACd,CAAC,CAAA;IACJ,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAA;CACnC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rotu/structview",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.3+dnt",
|
|
4
4
|
"description": "Read and write structured binary data with typesafe views",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
13
|
"import": "./esm/mod.js"
|
|
14
|
+
},
|
|
15
|
+
"./bigendian": {
|
|
16
|
+
"import": "./esm/bigendian.js"
|
|
14
17
|
}
|
|
15
18
|
},
|
|
16
19
|
"scripts": {
|