refactor: add a map wrapper for FileReference serialization

This commit is contained in:
Derrick Hammer 2024-01-05 07:31:54 -05:00
parent 7ad63aea3a
commit b1c7c8a9fd
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 10 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package metadata
import (
"encoding/json"
"fmt"
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
"github.com/emirpasic/gods/maps/linkedhashmap"
"github.com/vmihailenco/msgpack/v5"
)
@ -13,7 +14,9 @@ type directoryReferenceMap struct {
type fileReferenceMap struct {
linkedhashmap.Map
}
type fileReferenceSerializationMap struct {
linkedhashmap.Map
}
type directoryReferenceSerializationMap struct {
linkedhashmap.Map
}
@ -32,6 +35,7 @@ var _ SerializableMetadata = (*directoryReferenceMap)(nil)
var _ SerializableMetadata = (*fileReferenceMap)(nil)
var _ msgpack.CustomEncoder = (*directoryReferenceSerializationMap)(nil)
var _ msgpack.CustomEncoder = (*fileVersionSerializationMap)(nil)
var _ msgpack.CustomEncoder = (*fileReferenceSerializationMap)(nil)
func unmarshalMapMsgpack(dec *msgpack.Decoder, m *linkedhashmap.Map, placeholder interface{}, intMap bool) error {
*m = *linkedhashmap.New()
@ -210,6 +214,10 @@ func (frm directoryReferenceSerializationMap) EncodeMsgpack(enc *msgpack.Encoder
return marshallMapMsgpack(enc, &frm.Map)
}
func (frt fileReferenceSerializationMap) EncodeMsgpack(enc *msgpack.Encoder) error {
return marshallMapMsgpack(enc, &frt.Map)
}
func (fvs fileVersionSerializationMap) EncodeMsgpack(enc *msgpack.Encoder) error {
return marshallMapMsgpack(enc, &fvs.Map)
}

View File

@ -47,7 +47,7 @@ func (fr *FileReference) Modified() int {
}
func (fr *FileReference) EncodeMsgpack(enc *msgpack.Encoder) error {
tempMap := linkedhashmap.New()
tempMap := &fileReferenceSerializationMap{*linkedhashmap.New()}
tempMap.Put(1, fr.Name)
tempMap.Put(2, fr.Created)