Rehabilitate debug db tets, improve dump format

This commit is contained in:
lash 2025-01-17 11:09:30 +00:00
parent 9b66146ef1
commit ab03e6d529
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 8 additions and 23 deletions

View File

@ -32,17 +32,10 @@ func (k KeyInfo) String() string {
func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) {
o := KeyInfo{}
//b := []byte(sessionId)
// if len(k) <= len(b) {
// return o, fmt.Errorf("storage key missing")
// }
o.SessionId = sessionId
o.Typ = uint8(k[0])
k = k[1:]
//o.SessionId = string(k[:len(b)])
//k = k[len(b):]
if o.Typ == visedb.DATATYPE_USERDATA {
if len(k) == 0 {
@ -64,17 +57,6 @@ func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) {
return o, nil
}
func FromKey(k []byte) (KeyInfo, error) {
o := KeyInfo{}
if len(k) < 3 {
return o, fmt.Errorf("insufficient key length: %d", len(k))
}
sessionIdBytes := k[1:len(k)-2]
return ToKeyInfo(k, string(sessionIdBytes))
}
func subTypToString(v storedb.DataTyp) string {
return dbTypStr[v + visedb.DATATYPE_USERDATA + 1]
}

View File

@ -10,7 +10,6 @@ import (
func TestDebugDbSubKeyInfo(t *testing.T) {
s := "foo"
b := []byte{0x20}
b = append(b, []byte(s)...)
b = append(b, []byte{0x00, 0x02}...)
r, err := ToKeyInfo(b, s)
if err != nil {
@ -56,7 +55,6 @@ func TestDebugDbKeyInfo(t *testing.T) {
func TestDebugDbKeyInfoRestore(t *testing.T) {
s := "bar"
b := []byte{visedb.DATATYPE_USERDATA}
b = append(b, []byte(s)...)
k := storedb.ToBytes(storedb.DATA_ACTIVE_SYM)
b = append(b, k...)

View File

@ -20,12 +20,12 @@ var (
)
func formatItem(k []byte, v []byte, sessionId string) (string, error) {
//o, err := debug.FromKey(k)
o, err := debug.ToKeyInfo(k, sessionId)
if err != nil {
return "", err
}
s := fmt.Sprintf("%vValue: %v\n\n", o, string(v))
s := fmt.Sprintf("%v\t%v\n", o.Label, string(v))
return s, nil
}
@ -37,6 +37,7 @@ func main() {
var database string
var engineDebug bool
var err error
var first bool
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
flag.StringVar(&connStr, "c", "", "connection string")
@ -80,6 +81,10 @@ func main() {
if k == nil {
break
}
if !first {
fmt.Printf("Session ID: %s\n---\n", sessionId)
first = true
}
r, err := formatItem(append([]byte{db.DATATYPE_USERDATA}, k...), v, sessionId)
if err != nil {
fmt.Fprintf(os.Stderr, "format db item error: %v\n", err)