encodeBitmap encodes the value format: [type][length][value] length: the number of bits to save value: bitmap data
(data []byte, length uint)
| 390 | // length: the number of bits to save |
| 391 | // value: bitmap data |
| 392 | func (b *BitMapStructure) encodeBitmap(data []byte, length uint) ([]byte, error) { |
| 393 | // Calculate the actual length to save |
| 394 | dataSize := len2Size(length) |
| 395 | |
| 396 | // Either data or length is invalid |
| 397 | if uint(len(data)) < dataSize { |
| 398 | return nil, ErrInvalidValue |
| 399 | } |
| 400 | |
| 401 | buf := make([]byte, 1+binary.MaxVarintLen64+int(dataSize)) |
| 402 | |
| 403 | // Set the first element of buf to represent the data structure type as Bitmap. |
| 404 | buf[0] = Bitmap |
| 405 | |
| 406 | bufIndex := 1 |
| 407 | bufIndex += binary.PutVarint(buf[bufIndex:], int64(length)) |
| 408 | |
| 409 | // Append the data to the end |
| 410 | bufIndex += copy(buf[bufIndex:], data[:dataSize]) |
| 411 | |
| 412 | return buf[:bufIndex], nil |
| 413 | } |
| 414 | |
| 415 | // decodeBitmap decodes the value |
| 416 | // format: [type][length][value] |
no test coverage detected