diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-05-05 07:56:54 -0600 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-05-05 07:56:54 -0600 |
commit | c3903d38a10fda3c9a366d62705e06ddc558eb2d (patch) | |
tree | 504e0dcfc35536f7f9023aca59895c653bf68bee /meta.go | |
parent | Merge pull request #152 from benbjohnson/remove-bolt-set (diff) | |
download | dedo-c3903d38a10fda3c9a366d62705e06ddc558eb2d.tar.gz dedo-c3903d38a10fda3c9a366d62705e06ddc558eb2d.tar.xz |
Consolidate code for clarity.
This commit consolidates some of the smaller files into some of the larger files.
The smaller files cluttered the file tree and made it harder to see the logical
groupings of structs.
Diffstat (limited to 'meta.go')
-rw-r--r-- | meta.go | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/meta.go b/meta.go deleted file mode 100644 index 4212252..0000000 --- a/meta.go +++ /dev/null @@ -1,69 +0,0 @@ -package bolt - -import ( - "errors" - "hash/fnv" - "unsafe" -) - -const magic uint32 = 0xED0CDAED - -var ( - // ErrInvalid is returned when a data file is not a Bolt-formatted database. - ErrInvalid = errors.New("invalid database") - - // ErrVersionMismatch is returned when the data file was created with a - // different version of Bolt. - ErrVersionMismatch = errors.New("version mismatch") - - // ErrChecksum is returned when either meta page checksum does not match. - ErrChecksum = errors.New("checksum error") -) - -type meta struct { - magic uint32 - version uint32 - pageSize uint32 - flags uint32 - root bucket - freelist pgid - pgid pgid - txid txid - checksum uint64 -} - -// validate checks the marker bytes and version of the meta page to ensure it matches this binary. -func (m *meta) validate() error { - if m.checksum != 0 && m.checksum != m.sum64() { - return ErrChecksum - } else if m.magic != magic { - return ErrInvalid - } else if m.version != version { - return ErrVersionMismatch - } - return nil -} - -// copy copies one meta object to another. -func (m *meta) copy(dest *meta) { - *dest = *m -} - -// write writes the meta onto a page. -func (m *meta) write(p *page) { - // Page id is either going to be 0 or 1 which we can determine by the transaction ID. - p.id = pgid(m.txid % 2) - p.flags |= metaPageFlag - - // Calculate the checksum. - m.checksum = m.sum64() - - m.copy(p.meta()) -} - -// generates the checksum for the meta. -func (m *meta) sum64() uint64 { - var h = fnv.New64a() - _, _ = h.Write((*[unsafe.Offsetof(meta{}.checksum)]byte)(unsafe.Pointer(m))[:]) - return h.Sum64() -} |