Files
seaweedfs/weed/storage/needle_map/needle_value.go

31 lines
890 B
Go
Raw Normal View History

2019-04-18 21:43:36 -07:00
package needle_map
2017-05-26 22:51:25 -07:00
import (
. "github.com/chrislusf/seaweedfs/weed/storage/types"
"github.com/chrislusf/seaweedfs/weed/util"
2018-07-21 17:39:10 -07:00
"github.com/google/btree"
2017-05-26 22:51:25 -07:00
)
type NeedleValue struct {
Key NeedleId
Offset Offset `comment:"Volume offset"` //since aligned to 8 bytes, range is 4G*8=32G
2020-08-29 22:28:33 -07:00
Size Size `comment:"Size of the data portion"`
2017-05-26 22:51:25 -07:00
}
func (this NeedleValue) Less(than btree.Item) bool {
that := than.(NeedleValue)
return this.Key < that.Key
}
func (nv NeedleValue) ToBytes() []byte {
return ToBytes(nv.Key, nv.Offset, nv.Size)
}
func ToBytes(key NeedleId, offset Offset, size Size) []byte {
bytes := make([]byte, NeedleIdSize+OffsetSize+SizeSize)
NeedleIdToBytes(bytes[0:NeedleIdSize], key)
OffsetToBytes(bytes[NeedleIdSize:NeedleIdSize+OffsetSize], offset)
util.Uint32toBytes(bytes[NeedleIdSize+OffsetSize:NeedleIdSize+OffsetSize+SizeSize], uint32(size))
return bytes
}