refactor: add multitype support for keys to marshallMapMsgpack

This commit is contained in:
Derrick Hammer 2024-01-05 06:59:55 -05:00
parent 00157e463c
commit 012c90ddae
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 3 deletions

View File

@ -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()