@nnilky/structo 1.0.4 → 1.0.5

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.
Files changed (70) hide show
  1. package/README.md +1 -1
  2. package/dist/datatypes/containers/array.d.ts +8 -0
  3. package/dist/datatypes/containers/array.js +8 -0
  4. package/dist/datatypes/containers/exhuastiveArray.d.ts +9 -0
  5. package/dist/datatypes/containers/exhuastiveArray.js +24 -0
  6. package/dist/datatypes/containers/exhuastiveArray.test.js +41 -0
  7. package/dist/datatypes/containers/fastObject.test.js +33 -0
  8. package/dist/datatypes/containers/list.d.ts +11 -4
  9. package/dist/datatypes/containers/list.js +17 -9
  10. package/dist/datatypes/containers/list.test.js +6 -8
  11. package/dist/datatypes/containers/object.test.js +1 -1
  12. package/dist/datatypes/containers/sizedbytes.d.ts +2 -0
  13. package/dist/datatypes/containers/{sizedbuffer.js → sizedbytes.js} +1 -1
  14. package/dist/datatypes/containers/{sizedbuffer.test.js → sizedbytes.test.js} +5 -5
  15. package/dist/datatypes/{values → containers}/string.js +10 -8
  16. package/dist/datatypes/{values → containers}/string.test.js +6 -0
  17. package/dist/datatypes/containers/taggedUnion.d.ts +22 -0
  18. package/dist/datatypes/containers/taggedUnion.js +33 -0
  19. package/dist/datatypes/containers/taggedUnion.test.js +63 -0
  20. package/dist/datatypes/index.d.ts +12 -8
  21. package/dist/datatypes/index.js +12 -8
  22. package/dist/datatypes/numbers/bigints.d.ts +10 -0
  23. package/dist/datatypes/numbers/bigints.js +10 -0
  24. package/dist/datatypes/numbers/floats.d.ts +4 -0
  25. package/dist/datatypes/numbers/floats.js +18 -0
  26. package/dist/datatypes/numbers/floats.test.js +49 -47
  27. package/dist/datatypes/numbers/sints.d.ts +4 -0
  28. package/dist/datatypes/numbers/sints.js +4 -0
  29. package/dist/datatypes/numbers/uints.d.ts +4 -0
  30. package/dist/datatypes/numbers/uints.js +4 -0
  31. package/dist/datatypes/transforms/encode.d.ts +2 -0
  32. package/dist/datatypes/transforms/encode.js +7 -0
  33. package/dist/datatypes/transforms/fixedOffset.d.ts +2 -0
  34. package/dist/datatypes/transforms/{readOffset.js → fixedOffset.js} +1 -1
  35. package/dist/datatypes/transforms/modify.d.ts +2 -0
  36. package/dist/datatypes/transforms/modify.js +7 -0
  37. package/dist/datatypes/transforms/noAdvance.d.ts +16 -0
  38. package/dist/datatypes/transforms/noAdvance.js +30 -0
  39. package/dist/datatypes/transforms/pipe.js +12 -0
  40. package/dist/datatypes/utilities/remember.d.ts +11 -1
  41. package/dist/datatypes/utilities/remember.js +15 -5
  42. package/dist/datatypes/utilities/remember.test.js +44 -0
  43. package/dist/datatypes/utils.test.d.ts +2 -1
  44. package/dist/datatypes/utils.test.js +6 -2
  45. package/dist/datatypes/values/byteliteral.d.ts +1 -1
  46. package/dist/datatypes/values/byteliteral.js +1 -1
  47. package/dist/datatypes/values/bytes.d.ts +9 -0
  48. package/dist/datatypes/values/{buffer.js → bytes.js} +8 -1
  49. package/dist/datatypes/values/bytes.test.d.ts +1 -0
  50. package/dist/datatypes/values/{buffer.test.js → bytes.test.js} +6 -6
  51. package/dist/index.d.ts +1 -1
  52. package/dist/index.js +1 -1
  53. package/dist/read.d.ts +1 -1
  54. package/dist/write.d.ts +1 -1
  55. package/package.json +1 -1
  56. package/dist/datatypes/containers/sizedbuffer.d.ts +0 -2
  57. package/dist/datatypes/transforms/pipe.test.js +0 -13
  58. package/dist/datatypes/transforms/readOffset.d.ts +0 -2
  59. package/dist/datatypes/transforms/transform.d.ts +0 -2
  60. package/dist/datatypes/transforms/transform.js +0 -13
  61. package/dist/datatypes/utilities/constant.d.ts +0 -2
  62. package/dist/datatypes/utilities/constant.js +0 -13
  63. package/dist/datatypes/values/buffer.d.ts +0 -2
  64. /package/dist/datatypes/containers/{sizedbuffer.test.d.ts → exhuastiveArray.test.d.ts} +0 -0
  65. /package/dist/datatypes/{lazy.d.ts → containers/fastObject.test.d.ts} +0 -0
  66. /package/dist/datatypes/{lazy.js → containers/sizedbytes.test.d.ts} +0 -0
  67. /package/dist/datatypes/{values → containers}/string.d.ts +0 -0
  68. /package/dist/datatypes/{values → containers}/string.test.d.ts +0 -0
  69. /package/dist/datatypes/{transforms/pipe.test.d.ts → containers/taggedUnion.test.d.ts} +0 -0
  70. /package/dist/datatypes/{values/buffer.test.d.ts → utilities/remember.test.d.ts} +0 -0
package/README.md CHANGED
@@ -94,7 +94,7 @@ export function list<T>(options: {
94
94
  ```ts
95
95
  const Bits = st.pipe(
96
96
  st.u32()
97
- st.transform(v => v * 8)
97
+ st.modify(v => v * 8)
98
98
  )
99
99
  ```
100
100
 
@@ -1,2 +1,10 @@
1
1
  import type { Serializer } from "../../types";
2
+ /**
3
+ * `st.array` is a fixed length array, akin to a C array.
4
+ *
5
+ * ```
6
+ * st.array(16, st.f64())
7
+ * ```
8
+ *
9
+ */
2
10
  export declare function array<T>(size: number, type: Serializer<T>): Serializer<T[]>;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * `st.array` is a fixed length array, akin to a C array.
3
+ *
4
+ * ```
5
+ * st.array(16, st.f64())
6
+ * ```
7
+ *
8
+ */
1
9
  export function array(size, type) {
2
10
  const { read: readType, write: writeType, size: typeSize } = type;
3
11
  return {
@@ -0,0 +1,9 @@
1
+ import * as st from "../..";
2
+ /**
3
+ * exhuastiveArray is read until the end of the data
4
+ *
5
+ * ```py
6
+ * exhuastiveArray(st.u32())
7
+ * ```
8
+ */
9
+ export declare function exhuastiveArray<T>(type: st.Serializer<T>): st.Serializer<T[]>;
@@ -0,0 +1,24 @@
1
+ import * as st from "../..";
2
+ /**
3
+ * exhuastiveArray is read until the end of the data
4
+ *
5
+ * ```py
6
+ * exhuastiveArray(st.u32())
7
+ * ```
8
+ */
9
+ export function exhuastiveArray(type) {
10
+ return {
11
+ read(ctx) {
12
+ let arr = [];
13
+ while (ctx.offset < ctx.view.byteLength) {
14
+ arr.push(type.read(ctx));
15
+ }
16
+ return arr;
17
+ },
18
+ write(ctx, value) {
19
+ for (let i = 0; i < value.length; i++) {
20
+ type.write(ctx, value[i]);
21
+ }
22
+ },
23
+ };
24
+ }
@@ -0,0 +1,41 @@
1
+ import { describe, it } from "bun:test";
2
+ import { expectEncode, expectEncodeSnapshot, expectError } from "../utils.test";
3
+ import * as st from "../../index";
4
+ describe("st.exhuastiveArray", () => {
5
+ it("encode correctly", () => {
6
+ const spec = st.exhuastiveArray(st.u32());
7
+ expectEncode(spec, [1, 2, 3, 4]);
8
+ });
9
+ it("works on empty arrays", () => {
10
+ const spec = st.exhuastiveArray(st.u32());
11
+ expectEncode(spec, []);
12
+ });
13
+ it("accepts large array", () => {
14
+ const spec = st.exhuastiveArray(st.u32());
15
+ expectEncode(spec, Array.from({ length: 10000 }, (_, i) => i));
16
+ });
17
+ it("works composed", () => {
18
+ const spec = st.object({
19
+ a: st.u32(),
20
+ b: st.u8(),
21
+ c: st.exhuastiveArray(st.u32()),
22
+ });
23
+ expectEncode(spec, { a: 1, b: 2, c: [3, 4, 5, 6, 7] });
24
+ });
25
+ it("throws error on invalid value", () => {
26
+ const spec = st.exhuastiveArray(st.u16());
27
+ expectError(() => {
28
+ st.write(spec, [-1]);
29
+ });
30
+ });
31
+ it("nested arrays encode correctly", () => {
32
+ expectEncode(st.exhuastiveArray(st.exhuastiveArray(st.u16())), //
33
+ [[1, 2]]);
34
+ });
35
+ it(`matches snapshots`, () => {
36
+ expectEncodeSnapshot(st.exhuastiveArray(st.string(st.u16())), //
37
+ ["foo", "bar", "baz"]);
38
+ expectEncodeSnapshot(st.exhuastiveArray(st.u8()), //
39
+ [0, 1, 2, 3]);
40
+ });
41
+ });
@@ -0,0 +1,33 @@
1
+ //@ts-ignore TODO
2
+ import { describe, it, expect } from "bun:test";
3
+ import { bytes, expectEncode, expectEncodeSnapshot } from "../utils.test";
4
+ import * as st from "../../index";
5
+ describe("st.fastObject", () => {
6
+ const test = st.fastObject({
7
+ a: st.u8(),
8
+ b: st.u8(),
9
+ });
10
+ it("encodes correctly", () => {
11
+ st.write(test, { b: 2, a: 1 });
12
+ });
13
+ it("encode in correct order", () => {
14
+ const data = st.write(test, { b: 2, a: 1 });
15
+ const arr = new Uint8Array(data);
16
+ expect(arr[0]).toBe(1);
17
+ expect(arr[1]).toBe(2);
18
+ });
19
+ it("encodes empty", () => {
20
+ expectEncode(st.fastObject({}), {});
21
+ });
22
+ it(`matches snapshots`, () => {
23
+ expectEncodeSnapshot(st.fastObject({
24
+ number: st.u32(),
25
+ puppy: st.string(st.s32()),
26
+ buffer: st.bytes(4),
27
+ }), {
28
+ number: 1,
29
+ puppy: "woof woof bark bark",
30
+ buffer: bytes([19, 87, 19, 83]),
31
+ });
32
+ });
33
+ });
@@ -1,5 +1,12 @@
1
1
  import type { Serializer } from "../../types";
2
- export declare function list<T>(options: {
3
- type: Serializer<T>;
4
- length: Serializer<number>;
5
- }): Serializer<T[]>;
2
+ /**
3
+ * `st.list` is a dynamically sized array
4
+ *
5
+ * Note: Length is read/writen first, then the values in order
6
+ *
7
+ * ```
8
+ * st.list(st.u32(), User)
9
+ * ```
10
+ *
11
+ */
12
+ export declare function list<T>(length: Serializer<number>, type: Serializer<T>): Serializer<T[]>;
@@ -1,20 +1,28 @@
1
- export function list(options) {
2
- const { read: readLength, write: writeLength } = options.length;
3
- const { read: readType, write: writeType, size: sizeType } = options.type;
1
+ /**
2
+ * `st.list` is a dynamically sized array
3
+ *
4
+ * Note: Length is read/writen first, then the values in order
5
+ *
6
+ * ```
7
+ * st.list(st.u32(), User)
8
+ * ```
9
+ *
10
+ */
11
+ export function list(length, type) {
4
12
  return {
5
13
  write: (ctx, value) => {
6
- writeLength(ctx, value.length);
7
- if (sizeType)
8
- ctx.alloc(value.length * sizeType);
14
+ length.write(ctx, value.length);
15
+ if (type.size)
16
+ ctx.alloc(value.length * type.size);
9
17
  for (const v of value) {
10
- writeType(ctx, v);
18
+ type.write(ctx, v);
11
19
  }
12
20
  },
13
21
  read: (ctx) => {
14
- const size = readLength(ctx);
22
+ const size = length.read(ctx);
15
23
  const arr = new Array(size);
16
24
  for (let i = 0; i < size; i++) {
17
- arr[i] = readType(ctx);
25
+ arr[i] = type.read(ctx);
18
26
  }
19
27
  return arr;
20
28
  },
@@ -3,29 +3,27 @@ import { expectEncode, expectEncodeSnapshot, expectError } from "../utils.test";
3
3
  import * as st from "../../index";
4
4
  describe("st.list", () => {
5
5
  it("encode correctly", () => {
6
- const spec = st.list({ type: st.u16(), length: st.u8() });
6
+ const spec = st.list(st.u8(), st.u32());
7
7
  expectEncode(spec, [1, 2, 3, 4]);
8
8
  });
9
9
  it("works on empty lists", () => {
10
- const spec = st.list({ type: st.u16(), length: st.u8() });
10
+ const spec = st.list(st.u8(), st.u32());
11
11
  expectEncode(spec, []);
12
12
  });
13
13
  it("throws error on too large array", () => {
14
- const spec = st.list({ type: st.u16(), length: st.u8() });
14
+ const spec = st.list(st.u8(), st.u32());
15
15
  expectError(() => {
16
16
  st.write(spec, Array.from({ length: 10000 }, () => 0));
17
17
  });
18
18
  });
19
19
  it("throws error on invalid value", () => {
20
- const spec = st.list({ type: st.u16(), length: st.u8() });
20
+ const spec = st.list(st.u8(), st.u16());
21
21
  expectError(() => {
22
22
  st.write(spec, [-1]);
23
23
  });
24
24
  });
25
25
  it(`matches snapshots`, () => {
26
- expectEncodeSnapshot(st.list({
27
- type: st.string(st.u16()),
28
- length: st.s32(),
29
- }), ["foo", "bar", "baz"]);
26
+ expectEncodeSnapshot(st.list(st.s32(), st.string(st.u16())), //
27
+ ["foo", "bar", "baz"]);
30
28
  });
31
29
  });
@@ -23,7 +23,7 @@ describe("st.object", () => {
23
23
  expectEncodeSnapshot(st.object({
24
24
  number: st.u32(),
25
25
  puppy: st.string(st.s32()),
26
- buffer: st.buffer(4),
26
+ buffer: st.bytes(4),
27
27
  }), {
28
28
  number: 1,
29
29
  puppy: "woof woof bark bark",
@@ -0,0 +1,2 @@
1
+ import type { Serializer } from "../../types";
2
+ export declare function sizedBytes(length: Serializer<number>): Serializer<ArrayBuffer>;
@@ -1,4 +1,4 @@
1
- export function sizedBuffer(length) {
1
+ export function sizedBytes(length) {
2
2
  return {
3
3
  write: (ctx, value) => {
4
4
  length.write(ctx, value.byteLength);
@@ -1,25 +1,25 @@
1
1
  import { describe, it } from "bun:test";
2
2
  import { bytes, expectEncode, expectError } from "../utils.test";
3
3
  import * as st from "../../index";
4
- describe("st.buffer", () => {
4
+ describe("st.sizedBytes", () => {
5
5
  it("encode correctly", () => {
6
- const buffer = st.sizedBuffer(st.u8());
6
+ const buffer = st.sizedBytes(st.u8());
7
7
  expectEncode(buffer, bytes([1, 2]));
8
8
  });
9
9
  it("encodes empty correctly", () => {
10
- const spec = st.sizedBuffer(st.u8());
10
+ const spec = st.sizedBytes(st.u8());
11
11
  expectEncode(spec, bytes([]));
12
12
  });
13
13
  it("holds large data", () => {
14
14
  const size = 1024 * 1024 * 8; // 8MB
15
- const spec = st.sizedBuffer(st.u32());
15
+ const spec = st.sizedBytes(st.u32());
16
16
  const data = new Uint8Array(size);
17
17
  data.set([3, 4], 1000);
18
18
  data.set([3, 4], 2000);
19
19
  expectEncode(spec, data.buffer);
20
20
  });
21
21
  it("errors on invalid length", () => {
22
- const spec = st.sizedBuffer(st.u8());
22
+ const spec = st.sizedBytes(st.u8());
23
23
  expectError(() => {
24
24
  st.write(spec, bytes(Array.from({ length: 256 }, () => 0)));
25
25
  });
@@ -1,21 +1,23 @@
1
1
  export function string(length) {
2
- const { read: readLength, write: writeLength, size: lengthSize = 0 } = length;
3
2
  const encoder = new TextEncoder();
4
3
  const decoder = new TextDecoder();
4
+ const lengthSize = length.size ?? 0;
5
5
  return {
6
6
  write: (ctx, value) => {
7
+ if (typeof value !== "string")
8
+ throw new Error("Expected String to encoder");
7
9
  const bytes = encoder.encode(value);
8
- const length = bytes.byteLength;
9
- ctx.alloc(length + lengthSize);
10
- writeLength(ctx, length);
10
+ const size = bytes.byteLength;
11
+ ctx.alloc(size + lengthSize);
12
+ length.write(ctx, size);
11
13
  const arr = new Uint8Array(ctx.buffer, ctx.offset);
12
14
  arr.set(bytes);
13
- ctx.offset += length;
15
+ ctx.offset += size;
14
16
  },
15
17
  read: (ctx) => {
16
- const length = readLength(ctx);
17
- const section = ctx.buffer.slice(ctx.offset, ctx.offset + length);
18
- ctx.offset += length;
18
+ const size = length.read(ctx);
19
+ const section = ctx.buffer.slice(ctx.offset, ctx.offset + size);
20
+ ctx.offset += size;
19
21
  return decoder.decode(section);
20
22
  },
21
23
  };
@@ -10,6 +10,12 @@ describe("st.string", () => {
10
10
  it("works on empty strings", () => {
11
11
  expectEncode(string_u32, "");
12
12
  });
13
+ it("errors on numbers", () => {
14
+ expectError(() => {
15
+ //@ts-expect-error, intentional mistake
16
+ st.write(st.string(st.u8()), 8);
17
+ });
18
+ });
13
19
  it("errors on too long strings", () => {
14
20
  expectError(() => {
15
21
  st.write(string_u8, "A".repeat(256));
@@ -0,0 +1,22 @@
1
+ import type { InferInput, InferOutput, Serializer } from "../../types";
2
+ /**
3
+ * `st.taggedUnion` is a union type with a kind
4
+ *
5
+ * Note: `tag` is read/writen first, then the value
6
+ *
7
+ * ```
8
+ * st.taggedUnion(st.u32(), {
9
+ * 0: MovementPacket,
10
+ * 1: ClickPacket,
11
+ * 2: MouseMovePacket,
12
+ * })
13
+ * ```
14
+ *
15
+ */
16
+ export declare function taggedUnion<TTag extends string | number, TType extends Serializer<any>>(tag: Serializer<TTag>, variants: Record<TTag, TType>): Serializer<{
17
+ type: TTag;
18
+ value: InferInput<TType>;
19
+ }, {
20
+ type: TTag;
21
+ value: InferOutput<TType>;
22
+ }>;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * `st.taggedUnion` is a union type with a kind
3
+ *
4
+ * Note: `tag` is read/writen first, then the value
5
+ *
6
+ * ```
7
+ * st.taggedUnion(st.u32(), {
8
+ * 0: MovementPacket,
9
+ * 1: ClickPacket,
10
+ * 2: MouseMovePacket,
11
+ * })
12
+ * ```
13
+ *
14
+ */
15
+ export function taggedUnion(tag, variants) {
16
+ return {
17
+ write: (ctx, value) => {
18
+ if (!(value.type in variants))
19
+ throw new Error(`Unknown type ${value.type}`);
20
+ tag.write(ctx, value.type);
21
+ const variant = variants[value.type];
22
+ variant.write(ctx, value.value);
23
+ },
24
+ read: (ctx) => {
25
+ const type = tag.read(ctx);
26
+ if (!(type in variants))
27
+ throw new Error(`Unknown type ${tag}`);
28
+ const variant = variants[type];
29
+ const value = variant.read(ctx);
30
+ return { type, value };
31
+ },
32
+ };
33
+ }
@@ -0,0 +1,63 @@
1
+ import { describe, it } from "bun:test";
2
+ import { expectEncode, expectEncodeSize, expectEncodeSnapshot, expectError } from "../utils.test";
3
+ import * as st from "../../index";
4
+ describe("st.taggedUnion", () => {
5
+ it("encode correctly", () => {
6
+ const spec = st.taggedUnion(st.u8(), {
7
+ 1: st.string(st.u8()),
8
+ 2: st.u8(),
9
+ });
10
+ expectEncode(spec, { type: 1, value: "s" });
11
+ expectEncode(spec, { type: 2, value: 52 });
12
+ });
13
+ it("encode with string tag", () => {
14
+ const spec = st.taggedUnion(st.string(st.u8()), {
15
+ foo: st.string(st.u8()),
16
+ bar: st.u8(),
17
+ });
18
+ expectEncode(spec, { type: "foo", value: "woof" });
19
+ expectEncode(spec, { type: "bar", value: 52 });
20
+ });
21
+ it("throws error on invalid tag", () => {
22
+ const spec = st.taggedUnion(st.string(st.u8()), {
23
+ foo: st.string(st.u8()),
24
+ bar: st.u8(),
25
+ });
26
+ expectError(() => {
27
+ st.write(spec, { type: "unknown", value: "woof" });
28
+ });
29
+ });
30
+ it("throws error on invalid type", () => {
31
+ const spec = st.taggedUnion(st.string(st.u8()), {
32
+ foo: st.string(st.u8()),
33
+ bar: st.u8(),
34
+ });
35
+ expectError(() => {
36
+ st.write(spec, { type: "unknown", value: "woof" });
37
+ });
38
+ });
39
+ it("throws error on invalid value", () => {
40
+ const spec = st.taggedUnion(st.string(st.u8()), {
41
+ foo: st.string(st.u8()),
42
+ });
43
+ expectError(() => {
44
+ //@ts-expect-error
45
+ st.write(spec, { type: "foo", value: 0 });
46
+ });
47
+ });
48
+ it("encodes varying sizes", () => {
49
+ const spec = st.taggedUnion(st.u8(), {
50
+ 1: st.string(st.u8()),
51
+ 2: st.u8(),
52
+ });
53
+ expectEncode(spec, { type: 1, value: "s" });
54
+ expectEncodeSize(spec, 5, { type: 1, value: "foo" });
55
+ expectEncodeSize(spec, 2, { type: 2, value: 52 });
56
+ });
57
+ it("encodes snapshots", () => {
58
+ expectEncodeSnapshot(st.taggedUnion(st.u32(), {
59
+ 0: st.list(st.u8(), st.f64()),
60
+ 3: st.u32(),
61
+ }), { type: 0, value: [1] });
62
+ });
63
+ });
@@ -1,16 +1,20 @@
1
1
  export { u64Bigint, s64Bigint } from "./numbers/bigints";
2
- export { f32, f64 } from "./numbers/floats";
2
+ export { f16, f32, f64 } from "./numbers/floats";
3
3
  export { s8, s16, s32, s64 } from "./numbers/sints";
4
4
  export { u8, u16, u32, u64 } from "./numbers/uints";
5
5
  export { array } from "./containers/array";
6
6
  export { fastObject } from "./containers/fastObject";
7
7
  export { object } from "./containers/object";
8
8
  export { list } from "./containers/list";
9
- export { sizedBuffer } from "./containers/sizedbuffer";
10
- export { string } from "./values/string";
11
- export { buffer } from "./values/buffer";
12
- export { byteLiteral } from "./values/byteliteral";
13
- export { createRememberedValue } from "./utilities/remember";
9
+ export { sizedBytes } from "./containers/sizedbytes";
10
+ export { taggedUnion } from "./containers/taggedUnion";
11
+ export { exhuastiveArray } from "./containers/exhuastiveArray";
12
+ export { string } from "./containers/string";
13
+ export { bytes } from "./values/bytes";
14
+ export { bytesLiteral } from "./values/byteliteral";
14
15
  export { type Transform as Pipeline, pipe } from "./transforms/pipe";
15
- export { positionOffset } from "./transforms/readOffset";
16
- export { transform } from "./transforms/transform";
16
+ export { fixedOffset } from "./transforms/fixedOffset";
17
+ export { modify } from "./transforms/modify";
18
+ export { encode } from "./transforms/encode";
19
+ export { noAdvance } from "./transforms/noAdvance";
20
+ export { createRememberedValue } from "./utilities/remember";
@@ -1,16 +1,20 @@
1
1
  export { u64Bigint, s64Bigint } from "./numbers/bigints";
2
- export { f32, f64 } from "./numbers/floats";
2
+ export { f16, f32, f64 } from "./numbers/floats";
3
3
  export { s8, s16, s32, s64 } from "./numbers/sints";
4
4
  export { u8, u16, u32, u64 } from "./numbers/uints";
5
5
  export { array } from "./containers/array";
6
6
  export { fastObject } from "./containers/fastObject";
7
7
  export { object } from "./containers/object";
8
8
  export { list } from "./containers/list";
9
- export { sizedBuffer } from "./containers/sizedbuffer";
10
- export { string } from "./values/string";
11
- export { buffer } from "./values/buffer";
12
- export { byteLiteral } from "./values/byteliteral";
13
- export { createRememberedValue } from "./utilities/remember";
9
+ export { sizedBytes } from "./containers/sizedbytes";
10
+ export { taggedUnion } from "./containers/taggedUnion";
11
+ export { exhuastiveArray } from "./containers/exhuastiveArray";
12
+ export { string } from "./containers/string";
13
+ export { bytes } from "./values/bytes";
14
+ export { bytesLiteral } from "./values/byteliteral";
14
15
  export { pipe } from "./transforms/pipe";
15
- export { positionOffset } from "./transforms/readOffset";
16
- export { transform } from "./transforms/transform";
16
+ export { fixedOffset } from "./transforms/fixedOffset";
17
+ export { modify } from "./transforms/modify";
18
+ export { encode } from "./transforms/encode";
19
+ export { noAdvance } from "./transforms/noAdvance";
20
+ export { createRememberedValue } from "./utilities/remember";
@@ -1,3 +1,13 @@
1
1
  import type { Serializer } from "../../types";
2
+ /**
3
+ * 64bit unsigned interger
4
+ *
5
+ * This version uses bigints to ensure accuracy is not lost
6
+ */
2
7
  export declare function u64Bigint(endian?: "little" | "big"): Serializer<number | bigint, bigint>;
8
+ /**
9
+ * 64bit signed interger
10
+ *
11
+ * This version uses bigints to ensure accuracy is not lost
12
+ */
3
13
  export declare function s64Bigint(endian?: "little" | "big"): Serializer<number | bigint, bigint>;
@@ -3,6 +3,11 @@ const checkValue = (value, start, end) => {
3
3
  throw new Error("Out of Range");
4
4
  }
5
5
  };
6
+ /**
7
+ * 64bit unsigned interger
8
+ *
9
+ * This version uses bigints to ensure accuracy is not lost
10
+ */
6
11
  export function u64Bigint(endian = "little") {
7
12
  return {
8
13
  size: 8,
@@ -19,6 +24,11 @@ export function u64Bigint(endian = "little") {
19
24
  },
20
25
  };
21
26
  }
27
+ /**
28
+ * 64bit signed interger
29
+ *
30
+ * This version uses bigints to ensure accuracy is not lost
31
+ */
22
32
  export function s64Bigint(endian = "little") {
23
33
  return {
24
34
  size: 8,
@@ -1,3 +1,7 @@
1
1
  import type { Serializer } from "../../types";
2
+ /** 16bit float */
3
+ export declare function f16(endian?: "little" | "big"): Serializer<number>;
4
+ /** 32bit float */
2
5
  export declare function f32(endian?: "little" | "big"): Serializer<number>;
6
+ /** 64bit float */
3
7
  export declare function f64(endian?: "little" | "big"): Serializer<number>;
@@ -1,3 +1,20 @@
1
+ /** 16bit float */
2
+ export function f16(endian = "little") {
3
+ return {
4
+ size: 2,
5
+ write: (ctx, value) => {
6
+ ctx.alloc(2);
7
+ ctx.view.setFloat16(ctx.offset, value, endian === "little");
8
+ ctx.offset += 2;
9
+ },
10
+ read: (ctx) => {
11
+ const value = ctx.view.getFloat16(ctx.offset, endian === "little");
12
+ ctx.offset += 2;
13
+ return value;
14
+ },
15
+ };
16
+ }
17
+ /** 32bit float */
1
18
  export function f32(endian = "little") {
2
19
  return {
3
20
  size: 4,
@@ -13,6 +30,7 @@ export function f32(endian = "little") {
13
30
  },
14
31
  };
15
32
  }
33
+ /** 64bit float */
16
34
  export function f64(endian = "little") {
17
35
  return {
18
36
  size: 8,