Skip to content

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.

2 participants