needle_value.go 884 B

123456789101112131415161718192021222324252627282930
  1. package needle_map
  2. import (
  3. . "github.com/chrislusf/seaweedfs/weed/storage/types"
  4. "github.com/chrislusf/seaweedfs/weed/util"
  5. "github.com/google/btree"
  6. )
  7. type NeedleValue struct {
  8. Key NeedleId
  9. Offset Offset `comment:"Volume offset"` //since aligned to 8 bytes, range is 4G*8=32G
  10. Size uint32 `comment:"Size of the data portion"`
  11. }
  12. func (this NeedleValue) Less(than btree.Item) bool {
  13. that := than.(NeedleValue)
  14. return this.Key < that.Key
  15. }
  16. func (nv NeedleValue) ToBytes() []byte {
  17. return ToBytes(nv.Key, nv.Offset, nv.Size)
  18. }
  19. func ToBytes(key NeedleId, offset Offset, size uint32) []byte {
  20. bytes := make([]byte, NeedleIdSize+OffsetSize+SizeSize)
  21. NeedleIdToBytes(bytes[0:NeedleIdSize], key)
  22. OffsetToBytes(bytes[NeedleIdSize:NeedleIdSize+OffsetSize], offset)
  23. util.Uint32toBytes(bytes[NeedleIdSize+OffsetSize:NeedleIdSize+OffsetSize+SizeSize], size)
  24. return bytes
  25. }