From 012c90ddae58a5c7bc6be7f18f010979900074ec Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 5 Jan 2024 06:59:55 -0500 Subject: [PATCH] refactor: add multitype support for keys to marshallMapMsgpack --- metadata/directory_map.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/metadata/directory_map.go b/metadata/directory_map.go index cd9ab76..4ec3e30 100644 --- a/metadata/directory_map.go +++ b/metadata/directory_map.go @@ -79,9 +79,20 @@ func marshallMapMsgpack(enc *msgpack.Encoder, m *linkedhashmap.Map) error { iter := m.Iterator() for iter.Next() { - key := iter.Key().(string) - if err := enc.EncodeString(key); err != nil { - return err + key := iter.Key() + + // Determine the type of the key and encode it + switch k := key.(type) { + case string: + if err := enc.EncodeString(k); err != nil { + return err + } + case int: + if err := enc.EncodeInt(int64(k)); err != nil { + return err + } + default: + return fmt.Errorf("unsupported key type for encoding") } value := iter.Value()