@amodx/binary 0.0.14 → 0.0.16

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.
@@ -1,4 +1,4 @@
1
- import { BinaryNumberTypes } from "../../Constants/BinaryTypes";
1
+ import { BinaryNumberTypes } from "../../Constants/BinaryTypes.js";
2
2
  export declare enum BinaryObjectMarkers {
3
3
  Name = 0,
4
4
  Object = 1,
@@ -22,6 +22,7 @@ export declare enum BinaryObjectMarkers {
22
22
  ArrayBuffer = 19,
23
23
  TypedArray = 20,
24
24
  Json = 21,
25
- Blob = 22
25
+ Blob = 22,
26
+ Null = 23
26
27
  }
27
28
  export declare const MappedMarkertoPrimitive: Partial<Record<BinaryObjectMarkers, BinaryNumberTypes>>;
@@ -1,4 +1,4 @@
1
- import { BinaryNumberTypes } from "../../Constants/BinaryTypes";
1
+ import { BinaryNumberTypes } from "../../Constants/BinaryTypes.js";
2
2
  export var BinaryObjectMarkers;
3
3
  (function (BinaryObjectMarkers) {
4
4
  BinaryObjectMarkers[BinaryObjectMarkers["Name"] = 0] = "Name";
@@ -24,6 +24,7 @@ export var BinaryObjectMarkers;
24
24
  BinaryObjectMarkers[BinaryObjectMarkers["TypedArray"] = 20] = "TypedArray";
25
25
  BinaryObjectMarkers[BinaryObjectMarkers["Json"] = 21] = "Json";
26
26
  BinaryObjectMarkers[BinaryObjectMarkers["Blob"] = 22] = "Blob";
27
+ BinaryObjectMarkers[BinaryObjectMarkers["Null"] = 23] = "Null";
27
28
  })(BinaryObjectMarkers || (BinaryObjectMarkers = {}));
28
29
  export const MappedMarkertoPrimitive = {
29
30
  [BinaryObjectMarkers.Int8]: BinaryNumberTypes.Int8,
@@ -1,8 +1,8 @@
1
1
  import { BinaryObjectMarkers } from "../Constants/BinaryObjectMarkers.js";
2
2
  import { BinaryNumberTypes, ByteCounts, MappedByteCounts, } from "../../Constants/BinaryTypes.js";
3
3
  import { TypedNode } from "../Classes/TypedNode.js";
4
- import { ByteDataGet } from "../../Util/ByteDataGet";
5
- import { TypedArrayCreate } from "../../Util/TypedArrayCreate";
4
+ import { ByteDataGet } from "../../Util/ByteDataGet.js";
5
+ import { TypedArrayCreate } from "../../Util/TypedArrayCreate.js";
6
6
  export class BufferToObject {
7
7
  static _mode = "object";
8
8
  static _sharedMemory = false;
@@ -108,6 +108,15 @@ export class BufferToObject {
108
108
  }
109
109
  return ByteCounts.Uint8 + index;
110
110
  },
111
+ [BinaryObjectMarkers.Null]: (dv, index) => {
112
+ if (this._mode != "type-node") {
113
+ this._assign(null);
114
+ }
115
+ else {
116
+ this._assign(this._newTypedNode(BinaryObjectMarkers.Null, null));
117
+ }
118
+ return ByteCounts.Uint8 + index;
119
+ },
111
120
  [BinaryObjectMarkers.Int8]: (dv, index) => {
112
121
  const value = ByteDataGet[BinaryNumberTypes.Int8](dv, index + 1);
113
122
  if (this._mode != "type-node") {
@@ -308,18 +317,18 @@ export class BufferToObject {
308
317
  }
309
318
  static toObject(buffer, byteOffSet = 0, byteOffSetEnd = 0) {
310
319
  this._mode = "object";
311
- let legnth;
320
+ let byteEnd;
312
321
  if (byteOffSetEnd == 0) {
313
- legnth = buffer.byteLength;
322
+ byteEnd = buffer.byteLength;
314
323
  }
315
324
  else {
316
- legnth = byteOffSetEnd;
325
+ byteEnd = byteOffSet + byteOffSetEnd;
317
326
  }
318
327
  const dv = new DataView(buffer);
319
328
  this._objCount = 0;
320
329
  let index = byteOffSet;
321
330
  let markType = BinaryObjectMarkers.Object;
322
- while (index < legnth) {
331
+ while (index < byteEnd) {
323
332
  markType = ByteDataGet[BinaryNumberTypes.Uint8](dv, index);
324
333
  index = this.markFunctions[markType](dv, index);
325
334
  }
@@ -327,18 +336,18 @@ export class BufferToObject {
327
336
  }
328
337
  static toJSON(buffer, byteOffSet = 0, byteOffSetEnd = 0) {
329
338
  this._mode = "json";
330
- let legnth;
339
+ let byteEnd;
331
340
  if (byteOffSetEnd == 0) {
332
- legnth = buffer.byteLength;
341
+ byteEnd = buffer.byteLength;
333
342
  }
334
343
  else {
335
- legnth = byteOffSetEnd;
344
+ byteEnd = byteOffSet + byteOffSetEnd;
336
345
  }
337
346
  const dv = new DataView(buffer);
338
347
  this._objCount = 0;
339
348
  let index = byteOffSet;
340
349
  let markType = BinaryObjectMarkers.Object;
341
- while (index < legnth) {
350
+ while (index < byteEnd) {
342
351
  markType = ByteDataGet[BinaryNumberTypes.Uint8](dv, index);
343
352
  index = this.markFunctions[markType](dv, index);
344
353
  }
@@ -346,19 +355,19 @@ export class BufferToObject {
346
355
  }
347
356
  static toTypedNodes(buffer, byteOffSet = 0, byteOffSetEnd = 0) {
348
357
  this._mode = "type-node";
349
- let legnth;
358
+ let byteEnd;
350
359
  if (byteOffSetEnd == 0) {
351
- legnth = buffer.byteLength;
360
+ byteEnd = buffer.byteLength;
352
361
  }
353
362
  else {
354
- legnth = byteOffSetEnd;
363
+ byteEnd = byteOffSet + byteOffSetEnd;
355
364
  }
356
365
  this._mode = "object";
357
366
  const dv = new DataView(buffer);
358
367
  this._objCount = 0;
359
368
  let index = byteOffSet;
360
369
  let markType = BinaryObjectMarkers.Object;
361
- while (index < legnth) {
370
+ while (index < byteEnd) {
362
371
  markType = ByteDataGet[BinaryNumberTypes.Uint8](dv, index);
363
372
  index = this.markFunctions[markType](dv, index);
364
373
  }
@@ -9,6 +9,10 @@ export class ObjectToTypedNodes {
9
9
  for (const key of Object.keys(obj)) {
10
10
  const value = obj[key];
11
11
  this._name = key;
12
+ if (typeof value == "undefined" || value === null) {
13
+ node.value[key] = this._addPrimitive(value);
14
+ continue;
15
+ }
12
16
  if (value instanceof TypedNode) {
13
17
  node.value[key] = value;
14
18
  continue;
@@ -40,6 +44,10 @@ export class ObjectToTypedNodes {
40
44
  static _traverseArray(array) {
41
45
  const node = TypedNodes.array([]);
42
46
  for (const value of array) {
47
+ if (typeof value == "undefined" || value === null) {
48
+ node.value.push(this._addPrimitive(value));
49
+ continue;
50
+ }
43
51
  if (value instanceof TypedNode) {
44
52
  node.value.push(value);
45
53
  continue;
@@ -63,6 +71,9 @@ export class ObjectToTypedNodes {
63
71
  return node;
64
72
  }
65
73
  static _addPrimitive(node) {
74
+ if (node === null) {
75
+ return TypedNodes.null();
76
+ }
66
77
  if (typeof node == "string") {
67
78
  return TypedNodes.string(node);
68
79
  }
@@ -38,6 +38,10 @@ export class TypedNodesToBuffer {
38
38
  //for object array start and end marks
39
39
  const array = data.value;
40
40
  for (const node of array) {
41
+ if (typeof node.value == "undefined" || node.value === null) {
42
+ this._tokenizePrimiives(node);
43
+ continue;
44
+ }
41
45
  if (typeof node.value == "object" &&
42
46
  !Array.isArray(node.value) &&
43
47
  !ArrayBuffer.isView(node.value)) {
@@ -73,6 +77,10 @@ export class TypedNodesToBuffer {
73
77
  this._addToken(BinaryNumberTypes.Uint8, node.value ? 0 : 1);
74
78
  return;
75
79
  }
80
+ if (node.value == null) {
81
+ this._addMarker(BinaryObjectMarkers.Null);
82
+ return;
83
+ }
76
84
  if (typeof node.value == "undefined") {
77
85
  this._addMarker(BinaryObjectMarkers.Undefined);
78
86
  return;
@@ -117,8 +125,7 @@ export class TypedNodesToBuffer {
117
125
  !Array.isArray(node.value)) {
118
126
  this._traverseObj(node);
119
127
  }
120
- if (node.marker == BinaryObjectMarkers.Array &&
121
- Array.isArray(node.value)) {
128
+ if (node.marker == BinaryObjectMarkers.Array && Array.isArray(node.value)) {
122
129
  this._traverseArray(node);
123
130
  }
124
131
  }
@@ -17,6 +17,7 @@ export declare class TypedNodes {
17
17
  static bigUint(value: number): TypedNode<number>;
18
18
  static boolean(value: boolean): TypedNode<boolean>;
19
19
  static undefined(): TypedNode<undefined>;
20
+ static null(): TypedNode<null>;
20
21
  static arrayBuffer(value: ArrayBuffer | SharedArrayBuffer): TypedNode<ArrayBuffer>;
21
22
  static typedArray(type: BinaryNumberTypes, value: number[] | ArrayBufferView): TypedNode<TypedArrays>;
22
23
  static string(value: string): TypedNode<string>;
@@ -48,6 +48,9 @@ export class TypedNodes {
48
48
  static undefined() {
49
49
  return new TypedNode(BinaryObjectMarkers.Undefined, undefined);
50
50
  }
51
+ static null() {
52
+ return new TypedNode(BinaryObjectMarkers.Null, null);
53
+ }
51
54
  static arrayBuffer(value) {
52
55
  return new TypedNode(BinaryObjectMarkers.ArrayBuffer, value);
53
56
  }
@@ -12,7 +12,7 @@ export declare class BinraryStructBase {
12
12
  indexMap: Record<string, number>;
13
13
  index: DataView<ArrayBuffer>;
14
14
  constructor(id: string);
15
- setData(data: DataView): void;
15
+ setData(data: DataView<any>): void;
16
16
  setBuffer(data: BufferTypes): void;
17
17
  getBuffer(): ArrayBuffer;
18
18
  setStructArrayIndex(index: number): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amodx/binary",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "module": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "type": "module",