1
// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
2
// All rights reserved.
4
// Use of this source code is governed by a BSD-style license that can be
5
// found in the LICENSE file.
16
func (t vType) String() string {
26
// Value types encoded as the last component of internal keys.
27
// Don't modify; this value are saved to disk.
33
// tSeek defines the vType that should be passed when constructing an
34
// internal key for seeking to a particular sequence number (since we
35
// sort sequence numbers in decreasing order and the value type is
36
// embedded as the low 8 bits in the sequence number in internal keys,
37
// we need to use the highest-numbered ValueType, not the lowest).
41
// Maximum value possible for sequence number; the 8-bits are
42
// used by value type, so its can packed together in single
44
kMaxSeq uint64 = (uint64(1) << 56) - 1
45
// Maximum value possible for packed sequence number and type.
46
kMaxNum uint64 = (kMaxSeq << 8) | uint64(tSeek)
49
// Maximum number encoded in bytes.
50
var kMaxNumBytes = make([]byte, 8)
53
binary.LittleEndian.PutUint64(kMaxNumBytes, kMaxNum)
58
func newIKey(ukey []byte, seq uint64, t vType) iKey {
59
if seq > kMaxSeq || t > tVal {
60
panic("invalid seq number or value type")
63
b := make(iKey, len(ukey)+8)
65
binary.LittleEndian.PutUint64(b[len(ukey):], (seq<<8)|uint64(t))
69
func parseIkey(p []byte) (ukey []byte, seq uint64, t vType, ok bool) {
73
num := binary.LittleEndian.Uint64(p[len(p)-8:])
74
seq, t = uint64(num>>8), vType(num&0xff)
83
func (p iKey) assert() {
88
panic(fmt.Sprintf("invalid iKey %q, len=%d", []byte(p), len(p)))
92
func (p iKey) ukey() []byte {
97
func (p iKey) num() uint64 {
99
return binary.LittleEndian.Uint64(p[len(p)-8:])
102
func (p iKey) parseNum() (seq uint64, t vType, ok bool) {
110
seq, t = uint64(num>>8), vType(num&0xff)
118
func (p iKey) String() string {
122
if seq, t, ok := p.parseNum(); ok {
123
return fmt.Sprintf("%s,%s%d", shorten(string(p.ukey())), t, seq)