decodeBitmap decodes the value format: [type][length][value] length: the number of bits to save value: bitmap data
(value []byte)
| 417 | // length: the number of bits to save |
| 418 | // value: bitmap data |
| 419 | func (b *BitMapStructure) decodeBitmap(value []byte) ([]byte, uint, error) { |
| 420 | // Check the length of the value |
| 421 | if len(value) < 2 { |
| 422 | return nil, 0, ErrInvalidValue |
| 423 | } |
| 424 | |
| 425 | // Check the type of the value |
| 426 | if value[0] != Bitmap { |
| 427 | return nil, 0, ErrInvalidType |
| 428 | } |
| 429 | |
| 430 | valueLen := len(value) |
| 431 | |
| 432 | nowIndex := 1 |
| 433 | |
| 434 | length, lenOfLen := binary.Varint(value[nowIndex:]) |
| 435 | |
| 436 | // Check the number of bytes read |
| 437 | if lenOfLen <= 0 { |
| 438 | return nil, 0, ErrInvalidValue |
| 439 | } |
| 440 | |
| 441 | nowIndex += lenOfLen |
| 442 | |
| 443 | // Actual size |
| 444 | dataSize := len2Size(uint(length)) |
| 445 | |
| 446 | // Either data or length is invalid |
| 447 | if int(dataSize) > valueLen-nowIndex { |
| 448 | return nil, 0, ErrInvalidValue |
| 449 | } |
| 450 | |
| 451 | // Create an array to store the bitmap result |
| 452 | result := make([]byte, dataSize) |
| 453 | |
| 454 | copy(result, value[nowIndex:]) |
| 455 | |
| 456 | return result, uint(length), nil |
| 457 | } |
| 458 | |
| 459 | func len2Size(len uint) uint { |
| 460 |
no test coverage detected