refactor: change FileReference.DecodeMsgpack to use an empty map wrapper for exp and history if they were not decoded, we don't want them nil

This commit is contained in:
Derrick Hammer 2024-01-05 06:10:29 -05:00
parent c5fb8a2c15
commit 0e2ef0969a
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 15 additions and 2 deletions

View File

@ -75,6 +75,9 @@ func (fr *FileReference) DecodeMsgpack(dec *msgpack.Decoder) error {
return err
}
hasExt := false
hasHistory := false
for i := 0; i < mapLen; i++ {
key, err := dec.DecodeInt8()
if err != nil {
@ -114,6 +117,8 @@ func (fr *FileReference) DecodeMsgpack(dec *msgpack.Decoder) error {
if err != nil {
return err
}
hasExt = true
case int8(8):
historyDataLen, err := dec.DecodeMapLen()
if err != nil {
@ -132,10 +137,18 @@ func (fr *FileReference) DecodeMsgpack(dec *msgpack.Decoder) error {
return err
}
fr.History[k] = &fileVersion
}
hasHistory = true
}
}
if !hasExt {
fr.Ext = extMap{*linkedhashmap.New()}
}
if !hasHistory {
fr.History = fileHistoryMap{*linkedhashmap.New()}
}
return nil
}