etc.go 526 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2014 The kv Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package kv
  5. import (
  6. "bytes"
  7. "fmt"
  8. )
  9. type header struct {
  10. magic []byte
  11. ver byte
  12. reserved []byte
  13. }
  14. func (h *header) rd(b []byte) error {
  15. if len(b) != 16 {
  16. panic("internal error")
  17. }
  18. if h.magic = b[:4]; !bytes.Equal(h.magic, []byte(magic)) {
  19. return fmt.Errorf("Unknown file format")
  20. }
  21. b = b[4:]
  22. h.ver = b[0]
  23. h.reserved = b[1:]
  24. return nil
  25. }