refactor: change FileReference.EncodeMsgpack to use new map wrappers, and don't serialize ext or history if empty

This commit is contained in:
Derrick Hammer 2024-01-05 06:08:55 -05:00
parent c328cb1f1b
commit c5fb8a2c15
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 12 additions and 16 deletions

View File

@ -47,30 +47,26 @@ func (fr *FileReference) Modified() int {
} }
func (fr *FileReference) EncodeMsgpack(enc *msgpack.Encoder) error { func (fr *FileReference) EncodeMsgpack(enc *msgpack.Encoder) error {
data := map[int]interface{}{ tempMap := linkedhashmap.New()
1: fr.Name,
2: fr.Created, tempMap.Put(1, fr.Name)
4: fr.File, tempMap.Put(2, fr.Created)
5: fr.Version, tempMap.Put(4, fr.File)
} tempMap.Put(5, fr.Version)
if fr.MimeType != "" { if fr.MimeType != "" {
data[6] = fr.MimeType tempMap.Put(6, fr.MimeType)
} }
if fr.Ext != nil { if !fr.Ext.Empty() {
data[7] = fr.Ext tempMap.Put(7, fr.Ext)
} }
if fr.History != nil { if !fr.History.Empty() {
historyData := make(map[int]interface{}) tempMap.Put(8, fr.History)
for key, value := range fr.History {
historyData[key] = value
}
data[8] = historyData
} }
return enc.Encode(data) return enc.Encode(tempMap)
} }
func (fr *FileReference) DecodeMsgpack(dec *msgpack.Decoder) error { func (fr *FileReference) DecodeMsgpack(dec *msgpack.Decoder) error {
mapLen, err := dec.DecodeMapLen() mapLen, err := dec.DecodeMapLen()