Consolidate subtyp and typ debug

This commit is contained in:
lash
2024-12-01 23:12:58 +00:00
parent 35cf3a1cd1
commit 6d4f3109f8
5 changed files with 105 additions and 61 deletions

View File

@@ -8,6 +8,10 @@ import (
"git.grassecon.net/urdt/ussd/common"
)
var (
dbTypStr map[common.DataTyp]string = make(map[common.DataTyp]string)
)
type KeyInfo struct {
SessionId string
Typ uint8
@@ -19,6 +23,7 @@ type KeyInfo struct {
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")
}
@@ -35,8 +40,10 @@ func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) {
}
v := binary.BigEndian.Uint16(k[:2])
o.SubTyp = common.DataTyp(v)
o.Label = typToString(o.SubTyp)
o.Label = subTypToString(o.SubTyp)
k = k[2:]
} else {
o.Label = typToString(o.Typ)
}
if len(k) != 0 {
@@ -45,3 +52,11 @@ func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) {
return o, nil
}
func subTypToString(v common.DataTyp) string {
return dbTypStr[v + storage.DATATYPE_USERSUB + 1]
}
func typToString(v uint8) string {
return dbTypStr[common.DataTyp(uint16(v))]
}