From 3bb0703abafa5c98131d018b7d2ca6f8d957f035 Mon Sep 17 00:00:00 2001 From: Vizonex Date: Sat, 26 Jul 2025 13:14:24 -0500 Subject: [PATCH 1/2] add Unpack to frontend --- src/code/index.ts | 1 + src/code/unpack.ts | 13 +++++++++++++ src/container/index.ts | 1 + src/frontend.ts | 8 ++++++-- src/implementation/code.ts | 1 + 5 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/code/unpack.ts diff --git a/src/code/index.ts b/src/code/index.ts index c7d5c69..ab1f576 100644 --- a/src/code/index.ts +++ b/src/code/index.ts @@ -12,4 +12,5 @@ export * from './span'; export * from './store'; export * from './test'; export * from './update'; +export * from './unpack'; export * from './value'; diff --git a/src/code/unpack.ts b/src/code/unpack.ts new file mode 100644 index 0000000..33c3aee --- /dev/null +++ b/src/code/unpack.ts @@ -0,0 +1,13 @@ +import { Field } from "./field"; + +export class Unpack extends Field { + constructor ( + name: string, + field:string, + public readonly bigEndian:boolean + ){ + const endian_str = bigEndian ? 'be': 'le'; + super('match', `unpack_${endian_str}_${field}`, name, field); + } +} + diff --git a/src/container/index.ts b/src/container/index.ts index a62aac8..eccfc94 100644 --- a/src/container/index.ts +++ b/src/container/index.ts @@ -37,6 +37,7 @@ export class Container { Store: this.combine((impl) => impl.code.Store), Test: this.combine((impl) => impl.code.Test), Update: this.combine((impl) => impl.code.Update), + Unpack: this.combine((impl) => impl.code.Unpack), Value: this.combine((impl) => impl.code.Value), }; } diff --git a/src/frontend.ts b/src/frontend.ts index 91c5224..8270f56 100644 --- a/src/frontend.ts +++ b/src/frontend.ts @@ -470,9 +470,13 @@ export class Frontend { } else if (code instanceof source.code.Update) { res = new codeImpl.Update( new frontend.code.Update(prefixed, code.field, code.value)); - + + } else if (code instanceof source.code.Unpack) { + res = new codeImpl.Unpack( + new frontend.code.Unpack(prefixed, code.field, code.bigEndian)); + } // External callbacks - } else if (code instanceof source.code.Span) { + else if (code instanceof source.code.Span) { res = new codeImpl.Span(new frontend.code.Span(code.name)); } else if (code instanceof source.code.Match) { res = new codeImpl.Match(new frontend.code.Match(code.name)); diff --git a/src/implementation/code.ts b/src/implementation/code.ts index c467ced..03d844c 100644 --- a/src/implementation/code.ts +++ b/src/implementation/code.ts @@ -11,6 +11,7 @@ export interface ICodeImplementation { readonly Span: new(c: code.Span) => IWrap; readonly Store: new(c: code.Store) => IWrap; readonly Test: new(c: code.Test) => IWrap; + readonly Unpack: new(c: code.Unpack) => IWrap; readonly Update: new(c: code.Update) => IWrap; readonly Value: new(c: code.Value) => IWrap; } From 1708dd0b4e5221f1d1f9a9ae98c63e748a451346 Mon Sep 17 00:00:00 2001 From: Vizonex Date: Sat, 26 Jul 2025 13:18:32 -0500 Subject: [PATCH 2/2] add Unpack to test & fixtures --- test/fixtures/a-implementation/code/unpack.ts | 8 ++++++++ test/fixtures/implementation/code/unpack.ts | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 test/fixtures/a-implementation/code/unpack.ts create mode 100644 test/fixtures/implementation/code/unpack.ts diff --git a/test/fixtures/a-implementation/code/unpack.ts b/test/fixtures/a-implementation/code/unpack.ts new file mode 100644 index 0000000..8b3bedb --- /dev/null +++ b/test/fixtures/a-implementation/code/unpack.ts @@ -0,0 +1,8 @@ +import { code } from '../../../../src/frontend'; +import { Code } from './base'; + +export class Unpack extends Code { + public build(): string { + return ''; + } +} diff --git a/test/fixtures/implementation/code/unpack.ts b/test/fixtures/implementation/code/unpack.ts new file mode 100644 index 0000000..8b3bedb --- /dev/null +++ b/test/fixtures/implementation/code/unpack.ts @@ -0,0 +1,8 @@ +import { code } from '../../../../src/frontend'; +import { Code } from './base'; + +export class Unpack extends Code { + public build(): string { + return ''; + } +}