Helper method that re-interprets a sub-bucket value from a parent into a Bucket
(value []byte)
| 113 | // Helper method that re-interprets a sub-bucket value |
| 114 | // from a parent into a Bucket |
| 115 | func (b *Bucket) openBucket(value []byte) *Bucket { |
| 116 | var child = newBucket(b.tx) |
| 117 | |
| 118 | // Unaligned access requires a copy to be made. |
| 119 | const unalignedMask = unsafe.Alignof(struct { |
| 120 | common.InBucket |
| 121 | common.Page |
| 122 | }{}) - 1 |
| 123 | unaligned := uintptr(unsafe.Pointer(&value[0]))&unalignedMask != 0 |
| 124 | if unaligned { |
| 125 | value = cloneBytes(value) |
| 126 | } |
| 127 | |
| 128 | // If this is a writable transaction then we need to copy the bucket entry. |
| 129 | // Read-only transactions can point directly at the mmap entry. |
| 130 | if b.tx.writable && !unaligned { |
| 131 | child.InBucket = &common.InBucket{} |
| 132 | *child.InBucket = *(*common.InBucket)(unsafe.Pointer(&value[0])) |
| 133 | } else { |
| 134 | child.InBucket = (*common.InBucket)(unsafe.Pointer(&value[0])) |
| 135 | } |
| 136 | |
| 137 | // Save a reference to the inline page if the bucket is inline. |
| 138 | if child.RootPage() == 0 { |
| 139 | child.page = (*common.Page)(unsafe.Pointer(&value[common.BucketHeaderSize])) |
| 140 | } |
| 141 | |
| 142 | return &child |
| 143 | } |
| 144 | |
| 145 | // CreateBucket creates a new bucket at the given key and returns the new bucket. |
| 146 | // Returns an error if the key already exists, if the bucket name is blank, or if the bucket name is too long. |
no test coverage detected