seaweedfs/weed/storage/types/needle_types.go

51 lines
977 B
Go
Raw Normal View History

package types
import (
2018-07-22 00:39:10 +00:00
"fmt"
"github.com/chrislusf/seaweedfs/weed/util"
2018-07-22 00:39:10 +00:00
"math"
"strconv"
)
2019-04-09 02:40:56 +00:00
type Offset struct {
OffsetHigher
OffsetLower
}
type OffsetLower struct {
2019-04-09 02:40:56 +00:00
b3 byte
b2 byte
b1 byte
b0 byte // the smaller byte
}
type Cookie uint32
const (
2019-04-18 07:19:18 +00:00
SizeSize = 4 // uint32 size
NeedleEntrySize = CookieSize + NeedleIdSize + SizeSize
TimestampSize = 8 // int64 size
NeedlePaddingSize = 8
TombstoneFileSize = math.MaxUint32
CookieSize = 4
)
func CookieToBytes(bytes []byte, cookie Cookie) {
util.Uint32toBytes(bytes, uint32(cookie))
}
2018-07-22 00:39:10 +00:00
func Uint32ToCookie(cookie uint32) Cookie {
return Cookie(cookie)
}
2018-07-22 00:39:10 +00:00
func BytesToCookie(bytes []byte) Cookie {
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
}