refactor: add a map wrapper for FileReference serialization
This commit is contained in:
parent
7ad63aea3a
commit
b1c7c8a9fd
|
@ -3,6 +3,7 @@ package metadata
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
|
||||||
"github.com/emirpasic/gods/maps/linkedhashmap"
|
"github.com/emirpasic/gods/maps/linkedhashmap"
|
||||||
"github.com/vmihailenco/msgpack/v5"
|
"github.com/vmihailenco/msgpack/v5"
|
||||||
)
|
)
|
||||||
|
@ -13,7 +14,9 @@ type directoryReferenceMap struct {
|
||||||
type fileReferenceMap struct {
|
type fileReferenceMap struct {
|
||||||
linkedhashmap.Map
|
linkedhashmap.Map
|
||||||
}
|
}
|
||||||
|
type fileReferenceSerializationMap struct {
|
||||||
|
linkedhashmap.Map
|
||||||
|
}
|
||||||
type directoryReferenceSerializationMap struct {
|
type directoryReferenceSerializationMap struct {
|
||||||
linkedhashmap.Map
|
linkedhashmap.Map
|
||||||
}
|
}
|
||||||
|
@ -32,6 +35,7 @@ var _ SerializableMetadata = (*directoryReferenceMap)(nil)
|
||||||
var _ SerializableMetadata = (*fileReferenceMap)(nil)
|
var _ SerializableMetadata = (*fileReferenceMap)(nil)
|
||||||
var _ msgpack.CustomEncoder = (*directoryReferenceSerializationMap)(nil)
|
var _ msgpack.CustomEncoder = (*directoryReferenceSerializationMap)(nil)
|
||||||
var _ msgpack.CustomEncoder = (*fileVersionSerializationMap)(nil)
|
var _ msgpack.CustomEncoder = (*fileVersionSerializationMap)(nil)
|
||||||
|
var _ msgpack.CustomEncoder = (*fileReferenceSerializationMap)(nil)
|
||||||
|
|
||||||
func unmarshalMapMsgpack(dec *msgpack.Decoder, m *linkedhashmap.Map, placeholder interface{}, intMap bool) error {
|
func unmarshalMapMsgpack(dec *msgpack.Decoder, m *linkedhashmap.Map, placeholder interface{}, intMap bool) error {
|
||||||
*m = *linkedhashmap.New()
|
*m = *linkedhashmap.New()
|
||||||
|
@ -210,6 +214,10 @@ func (frm directoryReferenceSerializationMap) EncodeMsgpack(enc *msgpack.Encoder
|
||||||
return marshallMapMsgpack(enc, &frm.Map)
|
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 {
|
func (fvs fileVersionSerializationMap) EncodeMsgpack(enc *msgpack.Encoder) error {
|
||||||
return marshallMapMsgpack(enc, &fvs.Map)
|
return marshallMapMsgpack(enc, &fvs.Map)
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ func (fr *FileReference) Modified() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fr *FileReference) EncodeMsgpack(enc *msgpack.Encoder) error {
|
func (fr *FileReference) EncodeMsgpack(enc *msgpack.Encoder) error {
|
||||||
tempMap := linkedhashmap.New()
|
tempMap := &fileReferenceSerializationMap{*linkedhashmap.New()}
|
||||||
|
|
||||||
tempMap.Put(1, fr.Name)
|
tempMap.Put(1, fr.Name)
|
||||||
tempMap.Put(2, fr.Created)
|
tempMap.Put(2, fr.Created)
|
||||||
|
|
Loading…
Reference in New Issue