transpage.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * EliasDB
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. */
  10. package pageview
  11. import (
  12. "devt.de/krotik/eliasdb/storage/file"
  13. "devt.de/krotik/eliasdb/storage/paging/view"
  14. )
  15. /*
  16. OffsetTransData is the data offset for translation pages
  17. */
  18. const OffsetTransData = view.OffsetData
  19. /*
  20. TransPage data structure
  21. */
  22. type TransPage struct {
  23. *SlotInfoPage
  24. }
  25. /*
  26. NewTransPage creates a new page which holds data to translate between physical
  27. and logical slots.
  28. */
  29. func NewTransPage(record *file.Record) *DataPage {
  30. checkTransPageMagic(record)
  31. return &DataPage{NewSlotInfoPage(record)}
  32. }
  33. /*
  34. checkTransPageMagic checks if the magic number at the beginning of
  35. the wrapped record is valid.
  36. */
  37. func checkTransPageMagic(record *file.Record) bool {
  38. magic := record.ReadInt16(0)
  39. if magic == view.ViewPageHeader+view.TypeTranslationPage {
  40. return true
  41. }
  42. panic("Unexpected header found in TransPage")
  43. }