From 62b7adb9671eaaf5b78b953e1c7c7b680941dfc9 Mon Sep 17 00:00:00 2001 From: lash Date: Thu, 5 Sep 2024 15:41:27 +0100 Subject: [PATCH] Fix missing byte allocation for typ serialize --- internal/utils/db.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/internal/utils/db.go b/internal/utils/db.go index bd8c5ee..1104452 100644 --- a/internal/utils/db.go +++ b/internal/utils/db.go @@ -18,10 +18,9 @@ const ( ) func typToBytes(typ DataTyp) []byte { - //var b []byte - b := make([]byte, 2) - binary.BigEndian.PutUint16(b, uint16(typ)) - return b + var b [2]byte + binary.BigEndian.PutUint16(b[:], uint16(typ)) + return b[:] } func packKey(typ DataTyp, data []byte) []byte { @@ -31,9 +30,8 @@ func packKey(typ DataTyp, data []byte) []byte { func ReadEntry(ctx context.Context, store db.Db, sessionId string, typ DataTyp) ([]byte, error) { store.SetPrefix(db.DATATYPE_USERDATA) - store.SetSession(sessionId) - k := packKey(typ, []byte(sessionId)) - //k := []byte(sessionId) + store.SetSession(sessionId) + k := packKey(typ, []byte(sessionId)) b, err := store.Get(ctx, k) if err != nil { return nil, err @@ -45,7 +43,6 @@ func ReadEntry(ctx context.Context, store db.Db, sessionId string, typ DataTyp) func WriteEntry(ctx context.Context, store db.Db, sessionId string, typ DataTyp, value []byte) error { store.SetPrefix(db.DATATYPE_USERDATA) store.SetSession(sessionId) - //k := packKey(typ, []byte(sessionId)) - k := []byte(sessionId) + k := packKey(typ, []byte(sessionId)) return store.Put(ctx, k, value) -} \ No newline at end of file +}