Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a way to describe computed schemas. #24

Open
iwoplaza opened this issue Sep 9, 2024 · 0 comments
Open

Create a way to describe computed schemas. #24

iwoplaza opened this issue Sep 9, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@iwoplaza
Copy link
Owner

iwoplaza commented Sep 9, 2024

An example use-case would be an image format, whose size is defined in the header, then the rest of the bytes are dedicated to the bitmap.

import bin from 'typed-binary';

const Size = bin.tupleOf([bin.u32, bin.u32]);

const Bitmap = (width, height) => bin.u8ClampedArray(width * height);

const Image = bin.pipe(
  // -- Header
  bin.object({ size: Size }),
  // -- Body
  ({ size }) =>
    bin.object({
      size: bin.inherent(size),
      bitmap: Bitmap(...size),
    }),
);
@iwoplaza iwoplaza added the enhancement New feature or request label Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant