refactor: create constructors for FileHistoryMap and ExtMap

This commit is contained in:
Derrick Hammer 2024-01-17 14:22:43 -05:00
parent 47048ed2ab
commit e034e1096f
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 27 additions and 19 deletions

View File

@ -35,14 +35,14 @@ func (frm fileReferenceMap) Equal(other fileReferenceMap) bool {
return isEqual(frm.Size, other.Size, frm.Iterator, other.Iterator)
}
func (frm fileHistoryMap) Equal(other fileHistoryMap) bool {
func (frm FileHistoryMap) Equal(other FileHistoryMap) bool {
return isEqual(frm.Size, other.Size, frm.Iterator, other.Iterator)
}
func (drm directoryReferenceMap) Equal(other directoryReferenceMap) bool {
return isEqual(drm.Size, other.Size, drm.Iterator, other.Iterator)
}
func (ext extMap) Equal(other extMap) bool {
func (ext ExtMap) Equal(other ExtMap) bool {
return isEqual(ext.Size, other.Size, ext.Iterator, other.Iterator)
}

View File

@ -6,29 +6,37 @@ import (
)
var _ SerializableMetadata = (*FileReference)(nil)
var _ SerializableMetadata = (*fileHistoryMap)(nil)
var _ SerializableMetadata = (*extMap)(nil)
var _ SerializableMetadata = (*FileHistoryMap)(nil)
var _ SerializableMetadata = (*ExtMap)(nil)
type fileHistoryMap struct {
type FileHistoryMap struct {
linkedhashmap.Map
}
type extMap struct {
type ExtMap struct {
linkedhashmap.Map
}
func NewExtMap() ExtMap {
return ExtMap{*linkedhashmap.New()}
}
func NewFileHistoryMap() FileHistoryMap {
return FileHistoryMap{*linkedhashmap.New()}
}
type FileReference struct {
Name string `json:"name"`
Created uint64 `json:"created"`
Version uint64 `json:"version"`
File *FileVersion `json:"file"`
Ext extMap `json:"ext"`
History fileHistoryMap `json:"history"`
Ext ExtMap `json:"ext"`
History FileHistoryMap `json:"history"`
MimeType string `json:"mimeType"`
URI string `json:"uri"`
Key string `json:"key"`
}
func NewFileReference(name string, created, version uint64, file *FileVersion, ext extMap, history fileHistoryMap, mimeType string) *FileReference {
func NewFileReference(name string, created, version uint64, file *FileVersion, ext ExtMap, history FileHistoryMap, mimeType string) *FileReference {
return &FileReference{
Name: name,
Created: created,
@ -130,30 +138,30 @@ func (fr *FileReference) DecodeMsgpack(dec *msgpack.Decoder) error {
}
if !hasExt {
fr.Ext = extMap{*linkedhashmap.New()}
fr.Ext = ExtMap{*linkedhashmap.New()}
}
if !hasHistory {
fr.History = fileHistoryMap{*linkedhashmap.New()}
fr.History = FileHistoryMap{*linkedhashmap.New()}
}
return nil
}
func (ext extMap) EncodeMsgpack(enc *msgpack.Encoder) error {
func (ext ExtMap) EncodeMsgpack(enc *msgpack.Encoder) error {
return marshallMapMsgpack(enc, &ext.Map)
}
func (ext *extMap) DecodeMsgpack(dec *msgpack.Decoder) error {
return unmarshalMapMsgpack(dec, &ext.Map, &extMap{}, true)
func (ext *ExtMap) DecodeMsgpack(dec *msgpack.Decoder) error {
return unmarshalMapMsgpack(dec, &ext.Map, &ExtMap{}, true)
}
func (fhm fileHistoryMap) EncodeMsgpack(enc *msgpack.Encoder) error {
func (fhm FileHistoryMap) EncodeMsgpack(enc *msgpack.Encoder) error {
return marshallMapMsgpack(enc, &fhm.Map)
}
func (fhm *fileHistoryMap) DecodeMsgpack(dec *msgpack.Decoder) error {
return unmarshalMapMsgpack(dec, &fhm.Map, &extMap{}, false)
func (fhm *FileHistoryMap) DecodeMsgpack(dec *msgpack.Decoder) error {
return unmarshalMapMsgpack(dec, &fhm.Map, &ExtMap{}, false)
}
func (m *fileHistoryMap) UnmarshalJSON(bytes []byte) error {
func (m *FileHistoryMap) UnmarshalJSON(bytes []byte) error {
if string(bytes) == "null" {
m.Map = *linkedhashmap.New()
return nil
@ -161,7 +169,7 @@ func (m *fileHistoryMap) UnmarshalJSON(bytes []byte) error {
return m.FromJSON(bytes)
}
func (m *extMap) UnmarshalJSON(bytes []byte) error {
func (m *ExtMap) UnmarshalJSON(bytes []byte) error {
if string(bytes) == "null" {
m.Map = *linkedhashmap.New()
return nil