2018-07-08 09:28:04 +00:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
2018-07-22 00:39:10 +00:00
|
|
|
"fmt"
|
2018-07-08 09:28:04 +00:00
|
|
|
"strconv"
|
2020-08-19 00:04:28 +00:00
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2018-07-08 09:28:04 +00:00
|
|
|
)
|
|
|
|
|
2019-04-09 02:40:56 +00:00
|
|
|
type Offset struct {
|
2019-04-09 04:44:06 +00:00
|
|
|
OffsetHigher
|
|
|
|
OffsetLower
|
|
|
|
}
|
|
|
|
|
2020-08-19 02:22:16 +00:00
|
|
|
type Size int32
|
2020-08-19 00:04:28 +00:00
|
|
|
|
2020-08-19 00:35:19 +00:00
|
|
|
func (s Size) IsDeleted() bool {
|
2020-08-19 02:22:16 +00:00
|
|
|
return s < 0 || s == TombstoneFileSize
|
2020-08-19 00:35:19 +00:00
|
|
|
}
|
2020-08-19 01:01:37 +00:00
|
|
|
func (s Size) IsValid() bool {
|
2020-08-30 05:28:33 +00:00
|
|
|
return s > 0 && s != TombstoneFileSize
|
2020-08-19 01:01:37 +00:00
|
|
|
}
|
2020-08-19 00:35:19 +00:00
|
|
|
|
2019-04-09 04:44:06 +00:00
|
|
|
type OffsetLower struct {
|
2019-04-09 02:40:56 +00:00
|
|
|
b3 byte
|
|
|
|
b2 byte
|
|
|
|
b1 byte
|
|
|
|
b0 byte // the smaller byte
|
|
|
|
}
|
|
|
|
|
2018-07-08 09:28:04 +00:00
|
|
|
type Cookie uint32
|
|
|
|
|
|
|
|
const (
|
2019-04-19 07:39:34 +00:00
|
|
|
SizeSize = 4 // uint32 size
|
|
|
|
NeedleHeaderSize = CookieSize + NeedleIdSize + SizeSize
|
|
|
|
NeedleMapEntrySize = NeedleIdSize + OffsetSize + SizeSize
|
|
|
|
TimestampSize = 8 // int64 size
|
|
|
|
NeedlePaddingSize = 8
|
2020-08-19 02:22:16 +00:00
|
|
|
TombstoneFileSize = Size(-1)
|
2019-04-19 07:39:34 +00:00
|
|
|
CookieSize = 4
|
2018-07-08 09:28:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func CookieToBytes(bytes []byte, cookie Cookie) {
|
|
|
|
util.Uint32toBytes(bytes, uint32(cookie))
|
|
|
|
}
|
2018-07-22 00:39:10 +00:00
|
|
|
func Uint32ToCookie(cookie uint32) Cookie {
|
2018-07-08 09:28:04 +00:00
|
|
|
return Cookie(cookie)
|
|
|
|
}
|
|
|
|
|
2018-07-22 00:39:10 +00:00
|
|
|
func BytesToCookie(bytes []byte) Cookie {
|
2018-07-08 09:28:04 +00:00
|
|
|
return Cookie(util.BytesToUint32(bytes[0:4]))
|
|
|
|
}
|
|
|
|
|
2018-07-09 07:22:50 +00:00
|
|
|
func ParseCookie(cookieString string) (Cookie, error) {
|
|
|
|
cookie, err := strconv.ParseUint(cookieString, 16, 32)
|
|
|
|
if err != nil {
|
|
|
|
return 0, fmt.Errorf("needle cookie %s format error: %v", cookieString, err)
|
|
|
|
}
|
|
|
|
return Cookie(cookie), nil
|
|
|
|
}
|
2020-08-19 00:04:28 +00:00
|
|
|
|
|
|
|
func BytesToSize(bytes []byte) Size {
|
|
|
|
return Size(util.BytesToUint32(bytes))
|
|
|
|
}
|
|
|
|
|
|
|
|
func SizeToBytes(bytes []byte, size Size) {
|
|
|
|
util.Uint32toBytes(bytes, uint32(size))
|
|
|
|
}
|