Files
realy/ratel/keys/fullid/fullid.go
mleku bbebbe2b02 Add tracing with lol.Tracer in multiple functions.
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.
2025-06-29 07:32:24 +01:00

57 lines
1.0 KiB
Go

// Package fullid implements a keys.Element for a complete 32 byte event Ids.
package fullid
import (
"fmt"
"io"
"realy.lol/chk"
"realy.lol/lol"
"realy.lol/ratel/keys"
"realy.lol/sha256"
"realy.lol/eventid"
)
const Len = sha256.Size
type T struct {
Val []byte
}
var _ keys.Element = &T{}
func New(evID ...*eventid.T) (p *T) {
lol.Tracer("New", evID)
defer func() { lol.Tracer("end New", p) }()
if len(evID) < 1 {
return &T{make([]byte, Len)}
}
return &T{Val: evID[0].Bytes()}
}
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) }()
// allow uninitialized struct
if len(p.Val) != Len {
p.Val = make([]byte, Len)
}
if n, err := buf.Read(p.Val); chk.E(err) || n != Len {
return nil
}
el = p
return
}
func (p *T) Len() int { return Len }