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

Method encodeBitmap

structure/bitmap_1.go:392–413  ·  view source on GitHub ↗

encodeBitmap encodes the value format: [type][length][value] length: the number of bits to save value: bitmap data

(data []byte, length uint)

Source from the content-addressed store, hash-verified

390// length: the number of bits to save
391// value: bitmap data
392func (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]

Callers 1

setBitmapToDBMethod · 0.95

Calls 1

len2SizeFunction · 0.85

Tested by

no test coverage detected