2025-01-12 10:59:36 +01:00
|
|
|
package debug
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
2025-01-21 16:43:26 +01:00
|
|
|
"fmt"
|
2025-01-12 10:59:36 +01:00
|
|
|
|
|
|
|
visedb "git.defalsify.org/vise.git/db"
|
2025-01-21 16:43:26 +01:00
|
|
|
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
2025-01-12 10:59:36 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
dbTypStr map[storedb.DataTyp]string = make(map[storedb.DataTyp]string)
|
|
|
|
)
|
|
|
|
|
|
|
|
type KeyInfo struct {
|
2025-01-21 16:43:26 +01:00
|
|
|
SessionId string
|
|
|
|
Typ uint8
|
|
|
|
SubTyp storedb.DataTyp
|
|
|
|
Label string
|
2025-01-12 10:59:36 +01:00
|
|
|
Description string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (k KeyInfo) String() string {
|
|
|
|
v := uint16(k.SubTyp)
|
|
|
|
s := subTypToString(k.SubTyp)
|
|
|
|
if s == "" {
|
|
|
|
v = uint16(k.Typ)
|
|
|
|
s = typToString(k.Typ)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("Session Id: %s\nTyp: %s (%d)\n", k.SessionId, s, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) {
|
|
|
|
o := KeyInfo{}
|
2025-01-21 14:44:32 +01:00
|
|
|
|
2025-01-12 10:59:36 +01:00
|
|
|
o.SessionId = sessionId
|
|
|
|
o.Typ = uint8(k[0])
|
|
|
|
k = k[1:]
|
|
|
|
|
|
|
|
if o.Typ == visedb.DATATYPE_USERDATA {
|
|
|
|
if len(k) == 0 {
|
|
|
|
return o, fmt.Errorf("missing subtype key")
|
|
|
|
}
|
|
|
|
v := binary.BigEndian.Uint16(k[:2])
|
|
|
|
o.SubTyp = storedb.DataTyp(v)
|
|
|
|
o.Label = subTypToString(o.SubTyp)
|
|
|
|
k = k[2:]
|
2025-01-17 11:36:02 +01:00
|
|
|
if len(k) != 0 {
|
|
|
|
return o, fmt.Errorf("excess key information: %x", k)
|
|
|
|
}
|
2025-01-12 10:59:36 +01:00
|
|
|
} else {
|
|
|
|
o.Label = typToString(o.Typ)
|
2025-01-17 11:36:02 +01:00
|
|
|
k = k[2:]
|
2025-01-12 10:59:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return o, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func subTypToString(v storedb.DataTyp) string {
|
2025-01-21 16:43:26 +01:00
|
|
|
return dbTypStr[v+visedb.DATATYPE_USERDATA+1]
|
2025-01-12 10:59:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func typToString(v uint8) string {
|
|
|
|
return dbTypStr[storedb.DataTyp(uint16(v))]
|
|
|
|
}
|