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

added ability to export array as raw data #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rulk
Copy link

@rulk rulk commented Jul 17, 2019

Hi, just needed something like this to persist bool arrays, but it lacked ability to export

@@ -265,3 +265,23 @@ func (bits *BitArray) ToArray() []int {

return ints
}

func (bits *BitArray) ToByteArray() []byte {
return bits.bytes
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Bytes() is more precise since there is no copy or conversion, and we need some doc comment to clarify that the changes to the bytes will affect the result of future operations from BitArray.

return nil, errors.New("data can't be nil")
}
lenpad := nwords(length) * _BytesPW
if len(data) != lenpad {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should create a new bytes slice with lenpad then copy content from the origin slice, also the length should be greater or equal to len(data).

@damnever
Copy link
Owner

Thanks for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants