MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / decodeBitmap

Method decodeBitmap

structure/bitmap_1.go:419–457  ·  view source on GitHub ↗

decodeBitmap decodes the value format: [type][length][value] length: the number of bits to save value: bitmap data

(value []byte)

Source from the content-addressed store, hash-verified

417// length: the number of bits to save
418// value: bitmap data
419func (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
459func len2Size(len uint) uint {
460

Callers 1

getBitmapFromDBMethod · 0.95

Calls 1

len2SizeFunction · 0.85

Tested by

no test coverage detected