Documentation
¶
Overview ¶
Package storage provides the basic data structures, indexing, persistency and low leve API for oracles and vectors.
Index ¶
- Constants
- Variables
- func Flush(m proto.Message, fileName string) error
- func ListPath(dataPath string) (string, map[string]string, error)
- func Load(fileName string, m proto.Message) error
- type Driver
- type Index
- func (i *Index) Create(record proto.Message) error
- func (i *Index) Delete(id uint64) proto.Message
- func (i *Index) Find(id uint64) proto.Message
- func (i *Index) ForEach(cb func(record proto.Message) error) error
- func (i *Index) Load() error
- func (i *Index) NextID(next uint64)
- func (i *Index) Objects() []proto.Message
- func (i *Index) Size() int
- func (i *Index) Update(record proto.Message) error
- type OracleDriver
- type Oracles
- type RecordDriver
- type Records
Constants ¶
const (
// DatFileExt holds the default file extension for data files.
DatFileExt = ".dat"
)
Variables ¶
var ( // ErrInvalidID is returned when the system detects a collision of // identifiers, usually due to multiple Sum instances running on the // same data path. ErrInvalidID = errors.New("identifier is not unique") // ErrRecordNotFound is the 404 of Sum, it is returned when the storage // manager can't find an object mapped to the queried identifier. ErrRecordNotFound = errors.New("record not found") )
Functions ¶
func Flush ¶
Flush serializes and saves to file a generic protobuf message. It returns an error if unsuccessful.
Types ¶
type Driver ¶
type Driver interface { // Make must allocate and return a new protobuf object // when the index needs to. Make() proto.Message // GetID must access the protobuf message and return a // unique integer identifier that the index will use to // map that type of messages. GetID(m proto.Message) uint64 // SetID must access the protobuf message and set its // unique integer identifier. This is generally called // by instances of storage.Index when a new object is // created and a unique id is associated to it for the // first time. SetID(m proto.Message, id uint64) // Copy must copy the contents of the src message into // the dst message. An error can be returned to signal // the index that something went wrong during the copy. Copy(dst proto.Message, src proto.Message) error }
Driver is the generic interface for a module handling internal details of a specific protobuf object. It is used by the storage.Index in order to access object identifiers and internal fields.
type Index ¶
Index is a generic data structure used to map any types of protobuf encoded messages to unique integer identifiers and persist them on disk transparently.
func WithDriver ¶
WithDriver creates a new Index object with the specified storage.Driver used to handle the specifics of the protobuf messages being handled but this instance of the index.
func (*Index) Create ¶
Create stores the profobuf message in the index, setting its identifier to a new, unique value. Once created the object will be used in memory and persisted on disk.
func (*Index) Delete ¶
Delete removes a stored object from the index given its identifier, it will return the removed object itself if found, or nil. This operation will also remove the object data file from disk.
func (*Index) Find ¶
Find returns the instance of a stored object given its identifier, or nil if the object can not be found.
func (*Index) ForEach ¶
ForEach executes a callback passing as argument every element of the index, it interrupts the loop if the callback returns an error, the same error will be returned.
func (*Index) Load ¶
Load enumerates files in the data folder while deserializing them and mapping them into the index by their identifiers.
func (*Index) NextID ¶
NextID sets the value for the integer identifier to use every future record. NOTE: This method is just for internal use and the only reason why it's exposed is because of unit tests, do not use.
type OracleDriver ¶
type OracleDriver struct { }
OracleDriver is the specialized implementation of a storage.Driver interface, used to access the internal fields of pb.Oracle objects in the index.
func (OracleDriver) Copy ¶
Copy copies the Name and Code fields from the source object to the destination one.
func (OracleDriver) GetID ¶
func (d OracleDriver) GetID(m proto.Message) uint64
GetID returns the unique identifier of the pb.Oracle object.
func (OracleDriver) Make ¶
func (d OracleDriver) Make() proto.Message
Make returns a new pb.Oracle object.
type Oracles ¶
type Oracles struct {
*Index
}
Oracles is specialized version of a storage.Index used to map, store and persist pb.Oracle objects.
func LoadOracles ¶
LoadOracles loads raw protobuf oracles from the data files found in a given path.
type RecordDriver ¶
type RecordDriver struct { }
RecordDriver is the specialized implementation of a storage.Driver interface, used to access the internal fields of pb.Record objects in the index.
func (RecordDriver) Copy ¶
Copy copies the Meta and Data fields, if filled, from the source object to the destination one.
func (RecordDriver) GetID ¶
func (d RecordDriver) GetID(m proto.Message) uint64
GetID returns the unique identifier of the pb.Record object.
func (RecordDriver) Make ¶
func (d RecordDriver) Make() proto.Message
Make returns a new pb.Record object.
type Records ¶
type Records struct { *Index // contains filtered or unexported fields }
Records is specialized version of a storage.Index used to map, store and persist pb.Record objects.
func LoadRecords ¶
LoadRecords loads and indexes raw protobuf records from the data files found in a given path.
func (*Records) Delete ¶
Delete removes a stored pb.Record from the index given its identifier, it will return the removed object itself if found, or nil.
func (*Records) Find ¶
Find returns the instance of a stored pb.Record given its identifier or nil if the object can not be found.