-
Notifications
You must be signed in to change notification settings - Fork 11
Add bit and nibble support #6
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
Conversation
Checked commit Fryguy@3115009 with rubocop 0.27.1 lib/binary_struct.rb
spec/binary_struct_spec.rb
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. I like this stuff.
@jerryk55 If you want to try out the branch locally, before it's merged, and see if it helps you:
|
So I read your comment in the README.md file and that does explain the issue we have when trying to use less than 8 bits in any one byte (the entire byte is consumed and the remainder tossed). To me - this seems like a bug in Ruby's unpack. Can you explain to me why this isn't a bug there? |
I'm not sure. It's arguable if it's a bug or intentional, but it's definitely not what you'd expect. That's part of the reason it took me so long to figure out. Our best bet is to add documentation to String#unpack first, and then modify it later with a real code change if it's a bug. cc @tenderlove - thoughts on upstreaming documentation changes vs code fix changes or both? |
I'm not sure if it's intentional. The behavior seems wrong, so it seems like a bug to me. I'll try to track down the origin of the issue and maybe that will give us a clue if we can upstream or not. |
So here's what I've found. Maybe there should be a warning or argument error if the size provided to Funny enough, you can do this:
which seems really confusing. |
I'm assuming that sizeof(char) is typically one, so to determine the bits So, at a minimum, if the full feature of supporting sub-zero bits is b, b1..b7, b9..b15, etc # Exception Same goes for nibbles, but at sizeof(char) * 2 h, h1, h3, h5, etc # Exception
|
I like the exception/warning suggestion. I looked for this support in other languages and found something similar in Perl (meaning you couldn't use less than a byte at a time) The issue is you really can't address anything smaller than a byte. |
Ya, the code assumes it's 8. The weird thing is that it specifically takes in to account lengths that aren't divisible by 8 (if I'm reading that correctly), but I guess chooses to ignore the rest? I mean maybe it's so that people can extract the first N bits of each byte? But I don't understand how that would be useful. |
Going to merge, as there's not more that can be done in this PR. Hopefully, @tenderlove, you can make some headway with upstream. I'd be glad to help out, supply documentation, or whatever, if you could guide me to what you think is best. |
Closes #1
@roliveri @chessbyte @jerryk55 Please review.