openacid / slim

Surprisingly space efficient trie in Golang(11 bits/key; 100 ns/get).

Home Page:https://openacid.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

support multiple versions of impl for one data-type

drmingdrmer opened this issue · comments

Add version constrained marshal/unmarshal to array

A data-type such as array would evolve and finally there are several implementation in a package.
A versionizing mechanism should be introduced to:

  • During serialize, dump version.
  • During deserialize, check version and de-serialize data to correct data-type.

TODO

  • Introduce version API to let data-types implement it and provide its version.
type Version string
type VersionGetter interface {
   func GetVer() Version
}
  • Introduce Marshaller interface to let data-types provides versioned marshal API.
    Marshaller.Marshal() should call serialize.xxx to dump version.
    And also Marshaller.Unmarshal() should check version and choose a data type with correct version.
type Marshaller interface {
    Marshal(w io.Writer) (written int64, o interface{}, err error)
}

type UnMarshaller interface {
    Unmarshal(r io.Reader) (read int64, o interface{}, err error)
}

type MarshallerAt interface {
    MarshalAt(w io.Writer, offset int64) (written int64, o interface{}, err error)
}

type UnMarshallerAt interface {
    UnmarshalAt(r io.Reader, offset int64) (read int64, o interface{}, err error)
}
  • Introduce MarshalHelper struct to simplify Marshaling by converting MarshalAt to Marshal(see iohelper).
type MarshalHelper struct {
    Marshaller
    UnMarshaller
}
func (m *MarshalHelper) MarshalAt(offset int64) (written int64, err error)
  • array should then implement 4 marshal interface.

Array is not directly used. do not need version.