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

add missing short types #18

Closed
shevernitskiy opened this issue May 5, 2023 · 9 comments
Closed

add missing short types #18

shevernitskiy opened this issue May 5, 2023 · 9 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@shevernitskiy
Copy link

shevernitskiy commented May 5, 2023

I planned to parse PE headers, that contains 2-4 bit fields, but lib missing those types. I suggest to add it:)

@eliassjogreen eliassjogreen added enhancement New feature or request good first issue Good for newcomers labels May 5, 2023
@eliassjogreen
Copy link
Member

Sure that sounds like a good idea! I suggest the following new types be added:

  • U2
  • I2
  • U4
  • I4

This should be a rather easy issue to solve and get started with, I won't have to implement it for a little while but as a pointer for the person that decides to implement it:

Read

  1. dataView.getUint8
  2. Bitmask the relevant 2 or 4 bits
  3. If it is a signed integers it is two's complement convert it from unsigned to signed then

Write

Writing is the same but in reverse.

@MierenManz
Copy link
Collaborator

@eliassjogreen does it make sense to have a 2 bit and 4 bit int value? Bitfield I can get. But I don't really see the use for a signed 0 | 1 or a signed 0 to 7?

@eliassjogreen
Copy link
Member

I mean the use is mostly for parsing things like file headers and other such things. But I also don't see any issue implementing it if there is a use for it and it doesn't damage the rest of the module.

@nhrones
Copy link

nhrones commented Jan 15, 2024

I can understand supporting nibble (4-bits) but 2-bits?

@eliassjogreen
Copy link
Member

It's very much an esoteric thing I guess, but maybe if someone has 4x 2-bits packed together for stuff like ternary choices (yes, no, maybe)?

@MierenManz
Copy link
Collaborator

How would these eve be implemented? I assume it just consumed a full byte? Because it's pretty hard to read 1.25 bytes for example

@eliassjogreen
Copy link
Member

Yeah, you're right. I was thinking adding support for quarter bytes using floats and shifting but that is probably just a mess.

@MierenManz
Copy link
Collaborator

If someone needs to have a compound type that uses bit indices then I feel like we should help them write that component, but I don't think we should have it in byte_type itself. It feels like such a unique case that only one or two people will need it.

@eliassjogreen
Copy link
Member

Yep, agreed. Closing the issue

@eliassjogreen eliassjogreen closed this as not planned Won't fix, can't repro, duplicate, stale Jan 17, 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 good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants