-
Notifications
You must be signed in to change notification settings - Fork 2
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
construct from buffer #5
Comments
How do you manage the length of the bit array? |
It has padding at the end, but that's fine - if I write 51 bits of data and actually serialize a bit extra, it's not optimal but it's fine because when I deserialize, I never read whatever went into the padding bits. |
Here's a gist of the code - really what would be ideal is to allow an arbitrary serialization, say something like
the encoding to base64 would just be an instance of this logic. And then of course you'd need So in my particular case, I don't actually want ArrayBuffer -> BitArray, I just use it as a means to an end that could be achieved more optimally. Honestly I don't understand 100% of what the whole proxy thing is doing in the code, but otherwise the logic I'm sure I could implement if you wanted to accept the change. |
I see: you don't actually care the length, because it is pre-determined fixed-size, which is a specific case. Feel free to give it a try (it hopefully does not need to mess up with the proxy thing). If you do so, please include test cases as well! |
Created PR with this change - let me know :) I put it on the 'extension' repo instead of this one, as this one seems to be for matching the exact TypedArray interface only |
Typed array constructors can take an ArrayBuffer instance as single argument. E.g.:
The length of the typed array is the length of the buffer, divided by the TypedArray.BYTES_PER_ELEMENT.
If applied to BitArrays, that would imply the length of BitArrays can only be multiple of 8. However, there is no reason that length of bit arrays should be so. Hence, I have written:
This issue is created to open the discussion.
The text was updated successfully, but these errors were encountered: