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)
| 1150 | // EncodeBitArrayAscending. The remainder of the input buffer and the |
| 1151 | // decoded bit array are returned. |
| 1152 | func DecodeBitArrayAscending(b []byte) ([]byte, bitarray.BitArray, error) { |
| 1153 | if PeekType(b) != BitArray { |
| 1154 | return nil, bitarray.BitArray{}, errors.Errorf("did not find marker %x", b) |
| 1155 | } |
| 1156 | b = b[1:] |
| 1157 | |
| 1158 | // First compute the length. |
| 1159 | numWords, _, err := getBitArrayWordsLen(b, bitArrayDataTerminator) |
| 1160 | if err != nil { |
| 1161 | return b, bitarray.BitArray{}, err |
| 1162 | } |
| 1163 | // Decode the words. |
| 1164 | words := make([]uint64, numWords) |
| 1165 | for i := range words { |
| 1166 | b, words[i], err = DecodeUvarintAscending(b) |
| 1167 | if err != nil { |
| 1168 | return b, bitarray.BitArray{}, err |
| 1169 | } |
| 1170 | } |
| 1171 | // Decode the final part. |
| 1172 | if len(b) == 0 || b[0] != bitArrayDataTerminator { |
| 1173 | return b, bitarray.BitArray{}, errBitArrayTerminatorMissing |
| 1174 | } |
| 1175 | b = b[1:] |
| 1176 | b, lastVal, err := DecodeUvarintAscending(b) |
| 1177 | if err != nil { |
| 1178 | return b, bitarray.BitArray{}, err |
| 1179 | } |
| 1180 | ba, err := bitarray.FromEncodingParts(words, lastVal) |
| 1181 | return b, ba, err |
| 1182 | } |
| 1183 | |
| 1184 | var errBitArrayTerminatorMissing = errors.New("cannot find bit array data terminator") |
| 1185 |
no test coverage detected
searching dependent graphs…