Introduced `lol.Tracer` for function entry/exit logging across various packages. This improves traceability and debugging of function executions while preserving existing behavior. Removed unused files `doc.go` and `nothing.go` to clean up the repository.
65 lines
1.2 KiB
Go
65 lines
1.2 KiB
Go
// Package index implements the single byte prefix of the database keys. This
|
|
// means a limit of 256 tables but is plenty for a single purpose nostr event
|
|
// store.
|
|
package index
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
|
|
"realy.lol/chk"
|
|
"realy.lol/lol"
|
|
"realy.lol/ratel/keys"
|
|
)
|
|
|
|
const Len = 1
|
|
|
|
type T struct {
|
|
Val []byte
|
|
}
|
|
|
|
var _ keys.Element = &T{}
|
|
|
|
func New[V byte | P | int](code ...V) (p *T) {
|
|
lol.Tracer("New", code)
|
|
defer func() { lol.Tracer("end New", p) }()
|
|
var cod []byte
|
|
switch len(code) {
|
|
case 0:
|
|
cod = []byte{0}
|
|
default:
|
|
cod = []byte{byte(code[0])}
|
|
}
|
|
p = &T{Val: cod}
|
|
return
|
|
}
|
|
|
|
func Empty() (p *T) {
|
|
lol.Tracer("Empty")
|
|
defer func() { lol.Tracer("end Empty", p) }()
|
|
p = &T{Val: []byte{0}}
|
|
return
|
|
}
|
|
|
|
func (p *T) Write(buf io.Writer) {
|
|
lol.Tracer("Write")
|
|
defer func() { lol.Tracer("end Write") }()
|
|
if len(p.Val) != Len {
|
|
panic(fmt.Sprintln("must use New or initialize Val with len", Len))
|
|
}
|
|
buf.Write(p.Val)
|
|
}
|
|
|
|
func (p *T) Read(buf io.Reader) (el keys.Element) {
|
|
lol.Tracer("Read")
|
|
defer func() { lol.Tracer("end Read", el) }()
|
|
p.Val = make([]byte, Len)
|
|
if n, err := buf.Read(p.Val); chk.E(err) || n != Len {
|
|
return
|
|
}
|
|
el = p
|
|
return
|
|
}
|
|
|
|
func (p *T) Len() int { return Len }
|