refactor: create constructors for FileHistoryMap and ExtMap
This commit is contained in:
parent
47048ed2ab
commit
e034e1096f
|
@ -35,14 +35,14 @@ func (frm fileReferenceMap) Equal(other fileReferenceMap) bool {
|
||||||
return isEqual(frm.Size, other.Size, frm.Iterator, other.Iterator)
|
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)
|
return isEqual(frm.Size, other.Size, frm.Iterator, other.Iterator)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (drm directoryReferenceMap) Equal(other directoryReferenceMap) bool {
|
func (drm directoryReferenceMap) Equal(other directoryReferenceMap) bool {
|
||||||
return isEqual(drm.Size, other.Size, drm.Iterator, other.Iterator)
|
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)
|
return isEqual(ext.Size, other.Size, ext.Iterator, other.Iterator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,29 +6,37 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ SerializableMetadata = (*FileReference)(nil)
|
var _ SerializableMetadata = (*FileReference)(nil)
|
||||||
var _ SerializableMetadata = (*fileHistoryMap)(nil)
|
var _ SerializableMetadata = (*FileHistoryMap)(nil)
|
||||||
var _ SerializableMetadata = (*extMap)(nil)
|
var _ SerializableMetadata = (*ExtMap)(nil)
|
||||||
|
|
||||||
type fileHistoryMap struct {
|
type FileHistoryMap struct {
|
||||||
linkedhashmap.Map
|
linkedhashmap.Map
|
||||||
}
|
}
|
||||||
type extMap struct {
|
type ExtMap struct {
|
||||||
linkedhashmap.Map
|
linkedhashmap.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewExtMap() ExtMap {
|
||||||
|
return ExtMap{*linkedhashmap.New()}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFileHistoryMap() FileHistoryMap {
|
||||||
|
return FileHistoryMap{*linkedhashmap.New()}
|
||||||
|
}
|
||||||
|
|
||||||
type FileReference struct {
|
type FileReference struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Created uint64 `json:"created"`
|
Created uint64 `json:"created"`
|
||||||
Version uint64 `json:"version"`
|
Version uint64 `json:"version"`
|
||||||
File *FileVersion `json:"file"`
|
File *FileVersion `json:"file"`
|
||||||
Ext extMap `json:"ext"`
|
Ext ExtMap `json:"ext"`
|
||||||
History fileHistoryMap `json:"history"`
|
History FileHistoryMap `json:"history"`
|
||||||
MimeType string `json:"mimeType"`
|
MimeType string `json:"mimeType"`
|
||||||
URI string `json:"uri"`
|
URI string `json:"uri"`
|
||||||
Key string `json:"key"`
|
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{
|
return &FileReference{
|
||||||
Name: name,
|
Name: name,
|
||||||
Created: created,
|
Created: created,
|
||||||
|
@ -130,30 +138,30 @@ func (fr *FileReference) DecodeMsgpack(dec *msgpack.Decoder) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !hasExt {
|
if !hasExt {
|
||||||
fr.Ext = extMap{*linkedhashmap.New()}
|
fr.Ext = ExtMap{*linkedhashmap.New()}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !hasHistory {
|
if !hasHistory {
|
||||||
fr.History = fileHistoryMap{*linkedhashmap.New()}
|
fr.History = FileHistoryMap{*linkedhashmap.New()}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ext extMap) EncodeMsgpack(enc *msgpack.Encoder) error {
|
func (ext ExtMap) EncodeMsgpack(enc *msgpack.Encoder) error {
|
||||||
return marshallMapMsgpack(enc, &ext.Map)
|
return marshallMapMsgpack(enc, &ext.Map)
|
||||||
}
|
}
|
||||||
func (ext *extMap) DecodeMsgpack(dec *msgpack.Decoder) error {
|
func (ext *ExtMap) DecodeMsgpack(dec *msgpack.Decoder) error {
|
||||||
return unmarshalMapMsgpack(dec, &ext.Map, &extMap{}, true)
|
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)
|
return marshallMapMsgpack(enc, &fhm.Map)
|
||||||
}
|
}
|
||||||
func (fhm *fileHistoryMap) DecodeMsgpack(dec *msgpack.Decoder) error {
|
func (fhm *FileHistoryMap) DecodeMsgpack(dec *msgpack.Decoder) error {
|
||||||
return unmarshalMapMsgpack(dec, &fhm.Map, &extMap{}, false)
|
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" {
|
if string(bytes) == "null" {
|
||||||
m.Map = *linkedhashmap.New()
|
m.Map = *linkedhashmap.New()
|
||||||
return nil
|
return nil
|
||||||
|
@ -161,7 +169,7 @@ func (m *fileHistoryMap) UnmarshalJSON(bytes []byte) error {
|
||||||
return m.FromJSON(bytes)
|
return m.FromJSON(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *extMap) UnmarshalJSON(bytes []byte) error {
|
func (m *ExtMap) UnmarshalJSON(bytes []byte) error {
|
||||||
if string(bytes) == "null" {
|
if string(bytes) == "null" {
|
||||||
m.Map = *linkedhashmap.New()
|
m.Map = *linkedhashmap.New()
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue