Documentation ¶
Overview ¶
Package record is a package to open, read, and save game records stored in filesystem's format.
We encode states as diffs by default, but if that's not possible (for example, the diff the diffing library gave did not give us a valid diff because applying it to the left input does not provide the right input) then we convert to a full encoding mode, which encodes the entirerty of the blobs. Every time we save we try to revert to a diffed encoding if possible. This allows these files to be relatively resilient to errors in the undelrying diff library and heal as that library improves.
Note that because reading the files from disk is expensive, this library maintains a cache of records by filename that it returns, for a considerable performance boost. This means that changes in the filesystem while the storage layer is running that aren't mediated by this controller will cause undefined behavior.
Index ¶
- type Record
- func (r *Record) AddGameAndCurrentState(game *boardgame.GameStorageRecord, state boardgame.StateStorageRecord, ...) error
- func (r *Record) Compress() error
- func (r *Record) Description() string
- func (r *Record) Expand() error
- func (r *Record) FullStateEncoding() bool
- func (r *Record) Game() *boardgame.GameStorageRecord
- func (r *Record) Move(version int) (*boardgame.MoveStorageRecord, error)
- func (r *Record) Path() string
- func (r *Record) RawMoves() []*boardgame.MoveStorageRecord
- func (r *Record) Save(filename string, fullEncodingErrors bool) error
- func (r *Record) SetDescription(description string)
- func (r *Record) State(version int) (boardgame.StateStorageRecord, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
Record is a record of moves, states, and game. Get a new one based on the contents of a file with New(). If you want a new blank one you can just use a zero value of this.
func EmptyWithFullStateEncoding ¶
func EmptyWithFullStateEncoding() *Record
EmptyWithFullStateEncoding returns a record that will default to full state encoding and will never automatically try to reduce down to fullstateencoding. Primarily useful for testing.
func New ¶
New returns a new record with the data encoded in the file. If you want one that does not yet have a file backing it, you can just use an empty value of Record. If a record with that filename has already been saved, it will return that record.
func (*Record) AddGameAndCurrentState ¶
func (r *Record) AddGameAndCurrentState(game *boardgame.GameStorageRecord, state boardgame.StateStorageRecord, move *boardgame.MoveStorageRecord) error
AddGameAndCurrentState adds the game, state, and move (if non-nil), ready for saving. Designed to be used in a SaveGameAndCurrentState method. If the state cannot be succcesfully encoded as a diffed encoding (due to an underlying issue in the diffing library, for example, that gives an invalid diff) then this will automatically expand the record into a FullStateEncoding mode.
func (*Record) Compress ¶
Compress converts from full state encoding to diff encoding, if possible. Noop if already diff encoded.
func (*Record) Description ¶
Description returns the top-level description string set in the json file. You can call SetDescription to set it.
func (*Record) Expand ¶
Expand converts from diff state encoding to full encoding, if possible. Noop if already full encoded.
func (*Record) FullStateEncoding ¶
FullStateEncoding returns whether the record is using full state encoding instead of the default diff.
func (*Record) Game ¶
func (r *Record) Game() *boardgame.GameStorageRecord
Game returns the GameStorageRecord in that record.
func (*Record) Move ¶
func (r *Record) Move(version int) (*boardgame.MoveStorageRecord, error)
Move returns the move for that version from that record. Note that it might be a copy from the underlying value.
func (*Record) Path ¶
Path returns the string represeting the filename that this record represents (the filename that was passed to New()). Note that if you call Save() on a record, it doesn't update this value.
func (*Record) RawMoves ¶
func (r *Record) RawMoves() []*boardgame.MoveStorageRecord
RawMoves returns the actual raw MoveStorageRecords, which golden needs access to to align timestamps. The moves are 1-indexed, and their Initator, Version, and Timestamp fields might be in relative values that will trip up other logic outside of this package.
func (*Record) Save ¶
Save saves to the given path. Always try to Compress() if possible. If fullEncodingErrors is true then we'll error if we can't compress, otherwise we'll be OK with saving a full encoded version.
func (*Record) SetDescription ¶
SetDescription allows you to set the description that will be written.