@rotu/structview 0.10.0 → 0.10.2

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 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"}
@@ -0,0 +1,6 @@
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";
package/esm/core.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Tools for declaring a binary struct as a class with properties
3
3
  * @module
4
4
  */
5
- import type { AnyStruct, MixinFromProps, StructConstructor, StructPropertyDescriptor, SubclassWithProperties } from "./types.js";
5
+ import type { AnyStruct, MixinFromProps, StructConstructor, SubclassWithProperties } from "./types.js";
6
6
  export declare const dataViewSymbol: unique symbol;
7
7
  /**
8
8
  * Get the underlying DataView of a struct
@@ -18,12 +18,6 @@ export declare function structDataView(struct: AnyStruct): DataView;
18
18
  * @returns region of the given struct.
19
19
  */
20
20
  export declare function structBytes(struct: AnyStruct, start?: number, end?: number): Uint8Array;
21
- /**
22
- * Define a descriptor based on a dataview of the struct
23
- * @param fieldGetter function which, given a dataview, returns
24
- * @returns
25
- */
26
- export declare function fromDataView<Fn extends (dv: DataView) => unknown>(fieldGetter: Fn): StructPropertyDescriptor<ReturnType<Fn>>;
27
21
  /**
28
22
  * Base class for a structured binary object
29
23
  * Note there are no predeclared string-keyed properties - all property names are reserved for user-defined fields
@@ -37,6 +31,9 @@ export declare class Struct {
37
31
  * @param arg options for creating the struct.
38
32
  * If options has a `.buffer` property, we will use that as the backing memory (e.g. any TypedArray or DataView).
39
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.
40
37
  */
41
38
  constructor(arg: {
42
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,SAA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C,EAAE,MAAM,CAAA;KAC7B,GACC;QACA,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAA;QAC3B,QAAQ,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
@@ -36,20 +36,6 @@ export function structBytes(struct, start, end) {
36
36
  console.assert(end <= dv.byteLength);
37
37
  return new Uint8Array(dv.buffer, dv.byteOffset + start, end - start);
38
38
  }
39
- /**
40
- * Define a descriptor based on a dataview of the struct
41
- * @param fieldGetter function which, given a dataview, returns
42
- * @returns
43
- */
44
- export function fromDataView(fieldGetter) {
45
- return {
46
- enumerable: true,
47
- get() {
48
- const dv = this[dataViewSymbol];
49
- return fieldGetter(dv);
50
- },
51
- };
52
- }
53
39
  /**
54
40
  * Base class for a structured binary object
55
41
  * Note there are no predeclared string-keyed properties - all property names are reserved for user-defined fields
@@ -66,6 +52,9 @@ export class Struct {
66
52
  * @param arg options for creating the struct.
67
53
  * If options has a `.buffer` property, we will use that as the backing memory (e.g. any TypedArray or DataView).
68
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.
69
58
  */
70
59
  constructor(arg) {
71
60
  Object.defineProperty(this, _a, {
@@ -120,6 +109,9 @@ export function defineStruct(propertyDescriptors) {
120
109
  export function defineArray(arrayOptions) {
121
110
  var _StructArray_struct, _StructArray_length, _StructArray_byteStride;
122
111
  const { struct, byteStride, length } = arrayOptions;
112
+ /**
113
+ * Class representing an array of structs.
114
+ */
123
115
  class StructArray extends Struct {
124
116
  constructor() {
125
117
  super(...arguments);
@@ -144,6 +136,8 @@ export function defineArray(arrayOptions) {
144
136
  * A view of the item at the given index
145
137
  * @param index
146
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.
147
141
  */
148
142
  item(index) {
149
143
  const ctor = __classPrivateFieldGet(this, _StructArray_struct, "f");
package/esm/fields.d.ts CHANGED
@@ -68,6 +68,12 @@ export declare function string(fieldOffset: number, byteLength: number): StructP
68
68
  * True will be stored as 1
69
69
  */
70
70
  export declare function bool(fieldOffset: number): StructPropertyDescriptor<boolean>;
71
+ /**
72
+ * Define a descriptor based on a dataview of the struct
73
+ * @param fieldGetter function which, given a dataview, returns
74
+ * @returns
75
+ */
76
+ export declare function fromDataView<T>(fieldGetter: (dv: DataView) => T): StructPropertyDescriptor<T>;
71
77
  /**
72
78
  * Field for an embedded struct
73
79
  * @param ctor constructor for the inner struct
@@ -1 +1 @@
1
- {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,O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AwB,CAAC,MAAM,CAAC,CAU3E;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAU3E"}
package/esm/fields.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Factories for property descriptors representing fields in a binary struct
3
3
  * @module
4
4
  */
5
- import { fromDataView, structBytes, structDataView } from "./core.js";
5
+ import { structBytes, structDataView } from "./core.js";
6
6
  /**
7
7
  * Field for a 8-bit unsigned integer
8
8
  */
@@ -243,6 +243,20 @@ export function bool(fieldOffset) {
243
243
  },
244
244
  };
245
245
  }
246
+ /**
247
+ * Define a descriptor based on a dataview of the struct
248
+ * @param fieldGetter function which, given a dataview, returns
249
+ * @returns
250
+ */
251
+ export function fromDataView(fieldGetter) {
252
+ return {
253
+ enumerable: true,
254
+ get() {
255
+ const dv = structDataView(this);
256
+ return fieldGetter(dv);
257
+ },
258
+ };
259
+ }
246
260
  /**
247
261
  * Field for an embedded struct
248
262
  * @param ctor constructor for the inner struct
package/esm/mod.d.ts CHANGED
@@ -5,4 +5,5 @@
5
5
  export type * from "./types.js";
6
6
  export * from "./core.js";
7
7
  export * from "./fields.js";
8
+ export * as bigendian from "./bigendian.js";
8
9
  //# sourceMappingURL=mod.d.ts.map
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
@@ -4,3 +4,4 @@
4
4
  */
5
5
  export * from "./core.js";
6
6
  export * from "./fields.js";
7
+ export * as bigendian from "./bigendian.js";
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;
@@ -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;CACz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AE;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.0+dnt",
3
+ "version": "0.10.2+dnt",
4
4
  "description": "Read and write structured binary data with typesafe views",
5
5
  "repository": {
6
6
  "type": "git",