DecodeBitArrayAscending decodes a bit array which was encoded using EncodeBitArrayAscending. The remainder of the input buffer and the decoded bit array are returned.
(b []byte)
| 1634 | // EncodeBitArrayAscending. The remainder of the input buffer and the |
| 1635 | // decoded bit array are returned. |
| 1636 | func DecodeBitArrayAscending(b []byte) ([]byte, bitarray.BitArray, error) { |
| 1637 | if PeekType(b) != BitArray { |
| 1638 | return nil, bitarray.BitArray{}, errors.Errorf("did not find marker %x", b) |
| 1639 | } |
| 1640 | b = b[1:] |
| 1641 | |
| 1642 | // First compute the length. |
| 1643 | numWords, _, err := getBitArrayWordsLen(b, bitArrayDataTerminator) |
| 1644 | if err != nil { |
| 1645 | return b, bitarray.BitArray{}, err |
| 1646 | } |
| 1647 | // Decode the words. |
| 1648 | words := make([]uint64, numWords) |
| 1649 | for i := range words { |
| 1650 | b, words[i], err = DecodeUvarintAscending(b) |
| 1651 | if err != nil { |
| 1652 | return b, bitarray.BitArray{}, err |
| 1653 | } |
| 1654 | } |
| 1655 | // Decode the final part. |
| 1656 | if len(b) == 0 || b[0] != bitArrayDataTerminator { |
| 1657 | return b, bitarray.BitArray{}, errBitArrayTerminatorMissing |
| 1658 | } |
| 1659 | b = b[1:] |
| 1660 | b, lastVal, err := DecodeUvarintAscending(b) |
| 1661 | if err != nil { |
| 1662 | return b, bitarray.BitArray{}, err |
| 1663 | } |
| 1664 | ba, err := bitarray.FromEncodingParts(words, lastVal) |
| 1665 | return b, ba, err |
| 1666 | } |
| 1667 | |
| 1668 | var errBitArrayTerminatorMissing = errors.New("cannot find bit array data terminator") |
| 1669 |
no test coverage detected
searching dependent graphs…