aboutsummaryrefslogtreecommitdiff
path: root/lnode.go
blob: 9e457b6538008f759f0c224188b2fa4b882c0117 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package bolt

import (
	"unsafe"
)

type nodeid uint16

// lnode represents a node on a leaf page.
type lnode struct {
	flags    uint16
	keySize  uint16
	dataSize uint32
	data     uintptr // Pointer to the beginning of the data.
}

// key returns a byte slice that of the node key.
func (n *lnode) key() []byte {
	return (*[MaxKeySize]byte)(unsafe.Pointer(&n.data))[:n.keySize]
}

// data returns a byte slice that of the node data.
func (n *lnode) data() []byte {
	return (*[MaxKeySize]byte)(unsafe.Pointer(&n.data))[n.keySize : n.keySize+n.dataSize]
}

// lnodeSize returns the number of bytes required to store a key+data as a leaf node.
func lnodeSize(key []byte, data []byte) int {
	return int(unsafe.Offsetof((*lnode)(nil)).data) + len(key) + len(data)
}