refactor: need to export storage structs

This commit is contained in:
Derrick Hammer 2024-01-07 04:33:40 -05:00
parent 1950edf181
commit ef86db2bd0
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 15 additions and 15 deletions

View File

@ -157,8 +157,8 @@ func (n *NodeImpl) GetCachedStorageLocations(hash *encoding.Multihash, types []i
}
return locations, nil
}
func (n *NodeImpl) readStorageLocationsFromDB(hash *encoding.Multihash) (storage.storageLocationMap, error) {
locationMap := storage.newStorageLocationMap()
func (n *NodeImpl) readStorageLocationsFromDB(hash *encoding.Multihash) (storage.StorageLocationMap, error) {
locationMap := storage.NewStorageLocationMap()
bytes := n.cacheBucket.Get(hash.FullBytes())
if bytes == nil {
@ -187,8 +187,8 @@ func (n *NodeImpl) AddStorageLocation(hash *encoding.Multihash, nodeId *encoding
// Get or create the inner map for the specific type
innerMap, exists := locationDb[location.Type()]
if !exists {
innerMap = make(storage.nodeStorage, 1)
innerMap[nodeIdStr] = make(storage.nodeDetailsStorage, 1)
innerMap = make(storage.NodeStorage, 1)
innerMap[nodeIdStr] = make(storage.NodeDetailsStorage, 1)
}
// Create location map with new data

View File

@ -10,9 +10,9 @@ import (
)
var (
_ msgpack.CustomDecoder = (*storageLocationMap)(nil)
_ msgpack.CustomDecoder = (*StorageLocationMap)(nil)
_ msgpack.CustomEncoder = (*storageLocationMap)(nil)
_ msgpack.CustomEncoder = (*StorageLocationMap)(nil)
_ interfaces.StorageLocation = (*StorageLocationImpl)(nil)
)
@ -111,21 +111,21 @@ func (ssl *SignedStorageLocationImpl) String() string {
return "SignedStorageLocationImpl(" + ssl.Location.String() + ", " + nodeString + ")"
}
type storageLocationMap map[int]nodeStorage
type nodeStorage map[string]nodeDetailsStorage
type nodeDetailsStorage map[int]interface{}
type StorageLocationMap map[int]NodeStorage
type NodeStorage map[string]NodeDetailsStorage
type NodeDetailsStorage map[int]interface{}
func (s *storageLocationMap) DecodeMsgpack(dec *msgpack.Decoder) error {
func (s *StorageLocationMap) DecodeMsgpack(dec *msgpack.Decoder) error {
temp, err := dec.DecodeUntypedMap()
if err != nil {
return err
}
if *s == nil {
*s = make(map[int]nodeStorage)
*s = make(map[int]NodeStorage)
}
tempMap, ok := interface{}(temp).(storageLocationMap)
tempMap, ok := interface{}(temp).(StorageLocationMap)
if !ok {
return fmt.Errorf("unexpected data format from msgpack decoding")
}
@ -135,7 +135,7 @@ func (s *storageLocationMap) DecodeMsgpack(dec *msgpack.Decoder) error {
return nil
}
func (s storageLocationMap) EncodeMsgpack(enc *msgpack.Encoder) error {
func (s StorageLocationMap) EncodeMsgpack(enc *msgpack.Encoder) error {
// Create a temporary map to hold the encoded data
tempMap := make(map[int]map[string]map[int]interface{})
@ -152,6 +152,6 @@ func (s storageLocationMap) EncodeMsgpack(enc *msgpack.Encoder) error {
return enc.Encode(tempMap)
}
func newStorageLocationMap() storageLocationMap {
return storageLocationMap{}
func NewStorageLocationMap() StorageLocationMap {
return StorageLocationMap{}
}