Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CursorToOffset ¶
type CursorToOffset struct {
// contains filtered or unexported fields
}
CursorToOffset is a Cursor that read until the endOffset.
func (*CursorToOffset) Done ¶
func (c *CursorToOffset) Done() bool
Done returns true when there is no more entry to read.
func (*CursorToOffset) Entry ¶
func (c *CursorToOffset) Entry() *Entry
Entry returns the current entry.
func (*CursorToOffset) Next ¶
func (c *CursorToOffset) Next()
Next moves the cursor to the next entry.
type Entry ¶
Entry struct is a key value pair.
func ReadEntry ¶
ReadEntry reads an entry from r.
Example ¶
f := bytes.NewReader([]byte{0, 0, 0, 3, 0, 0, 0, 4, 1, 2, 3, 5, 6, 7, 8}) e, _ := ReadEntry(f) fmt.Println(e)
Output: &{[1 2 3] [5 6 7 8]}
func ReadEntryAt ¶
ReadEntryAt reads an entry from the offset of r.
Example ¶
f := bytes.NewReader([]byte{0, 0, 0, 3, 0, 0, 0, 4, 1, 2, 3, 5, 6, 7, 8}) e, _ := ReadEntryAt(f, 0) fmt.Println(e)
Output: &{[1 2 3] [5 6 7 8]}
func (*Entry) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
Example ¶
e := Entry{ Key: []byte{1, 2, 3}, Value: []byte{5, 6, 7, 8}, } data, err := e.MarshalBinary() if err != nil { fmt.Println(err) } fmt.Println(data)
Output: [0 0 0 3 0 0 0 4 1 2 3 5 6 7 8]
func (*Entry) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
Example ¶
var e Entry err := e.UnmarshalBinary([]byte{0, 0, 0, 3, 0, 0, 0, 4, 1, 2, 3, 5, 6, 7, 8}) if err != nil { fmt.Println(err) } fmt.Println(e)
Output: {[1 2 3] [5 6 7 8]}
type SSTable ¶
type SSTable struct {
// contains filtered or unexported fields
}
SSTable implements read only random access of the SSTable.
Example ¶
f, _ := ioutil.TempFile("", "") name := f.Name() defer os.Remove(name) w := NewWriter(f) entries := []Entry{ {Key: []byte{1, 2, 3}, Value: []byte{5, 6, 7, 8}}, {Key: []byte{2, 2, 3}, Value: []byte{8, 5, 6, 7, 8}}, } for _, entry := range entries { if err := w.Write(entry); err != nil { fmt.Println(err) } } w.Close() f2, _ := os.Open(name) defer f2.Close() s, _ := NewSSTable(f2) c := s.ScanFrom([]byte{1, 2, 3}) if c == nil { fmt.Println(c) return } for !c.Done() { fmt.Println(c.Entry()) c.Next() } fmt.Println("---") c = s.ScanFrom([]byte{1, 2, 3, 0}) for !c.Done() { fmt.Println(c.Entry()) c.Next() }
Output: &{[1 2 3] [5 6 7 8]} &{[2 2 3] [8 5 6 7 8]} --- &{[2 2 3] [8 5 6 7 8]}
Example (Reader) ¶
f, _ := ioutil.TempFile("", "") name := f.Name() defer os.Remove(name) w := NewWriter(f) entries := []Entry{ {Key: []byte{1, 2, 3}, Value: []byte{5, 6, 7, 8}}, {Key: []byte{2, 2, 3}, Value: []byte{8, 5, 6, 7, 8}}, } for _, entry := range entries { if err := w.Write(entry); err != nil { fmt.Println(err) } } w.Close() b, _ := ioutil.ReadFile(name) // bytes.Buffer does not support random access. s, _ := NewSSTable(bytes.NewBuffer(b)) c := s.ScanFrom([]byte{1, 2, 3}) if c == nil { fmt.Println(c) return } for !c.Done() { fmt.Println(c.Entry()) c.Next() }
Output: &{[1 2 3] [5 6 7 8]} &{[2 2 3] [8 5 6 7 8]}
func NewSSTable ¶
NewSSTable creates a SSTable struct
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is used to build a SSTable binary with Write function.
Example ¶
f, _ := ioutil.TempFile("", "") name := f.Name() defer os.Remove(name) w := NewWriter(f) entries := []Entry{ {Key: []byte{1, 2, 3}, Value: []byte{5, 6, 7, 8}}, {Key: []byte{2, 2, 3}, Value: []byte{8, 5, 6, 7, 8}}, } for _, entry := range entries { if err := w.Write(entry); err != nil { fmt.Println(err) } } w.Close() b, _ := ioutil.ReadFile(name) fmt.Print(hex.Dump(b))
Output: 00000000 00 00 00 02 00 00 00 01 00 00 00 00 00 00 00 2f |.............../| 00000010 00 00 00 03 00 00 00 04 01 02 03 05 06 07 08 00 |................| 00000020 00 00 03 00 00 00 05 02 02 03 08 05 06 07 08 00 |................| 00000030 00 00 03 00 00 00 00 00 00 00 10 00 00 00 1f 01 |................| 00000040 02 03 |..|
func NewWriter ¶
NewWriter creates a Writer. The given writer w should be either WriterAt or WriteSeeker for random access.