recording

package
v0.0.0-...-34b2563 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package recording handles the encoding and decoding of recorded games to files.

Index

Constants

View Source
const FormatVersion = 8

FormatVersion is the version number of the recording format. As of right now, recording formats are not forwards or backwards compatible.

Variables

View Source
var (
	ErrMissingData         = errors.New("recording: missing data")
	ErrCannotModify        = errors.New("recording: cannot modify read-only data")
	ErrCorruptRecording    = errors.New("recording: corrupt recording")
	ErrIncompatibleVersion = errors.New("recording: incompatible or invalid format version")
	ErrHeaderTooLarge      = errors.New("recording: header is too large")
)

Error variables to check what errors have occurred.

Functions

This section is empty.

Types

type ChunkInfo

type ChunkInfo struct {
	CurrentChunk    int `json:"chunkId"`
	AvailableSince  int `json:"availableSince"`
	NextUpdate      int `json:"nextAvailableChunk"`
	CurrentKeyFrame int `json:"keyFrameId"`
	NextChunk       int `json:"nextChunkId"`
	EndStartupChunk int `json:"endStartupChunkId"`
	StartGameChunk  int `json:"startGameChunkId"`
	EndGameChunk    int `json:"endGameChunkId"`
	Duration        int `json:"duration"`
}

ChunkInfo is used to store and decode relevant chunk information from the recorded game. It is used to store the

func (*ChunkInfo) MarshalJSON

func (mj *ChunkInfo) MarshalJSON() ([]byte, error)

func (*ChunkInfo) MarshalJSONBuf

func (mj *ChunkInfo) MarshalJSONBuf(buf fflib.EncodingBuffer) error

func (*ChunkInfo) UnmarshalJSON

func (uj *ChunkInfo) UnmarshalJSON(input []byte) error

func (*ChunkInfo) UnmarshalJSONFFLexer

func (uj *ChunkInfo) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error

func (ChunkInfo) WriteTo

func (c ChunkInfo) WriteTo(w io.Writer) (int64, error)

WriteTo encodes the ChunkInfo as JSON and writes it to a writer.

type GameInfo

type GameInfo struct {
	Platform      string
	Version       string
	GameID        string
	EncryptionKey string
	RecordTime    time.Time
}

GameInfo represents meta information for a game required to play it back at a stored recording level.

func (*GameInfo) MarshalJSON

func (mj *GameInfo) MarshalJSON() ([]byte, error)

func (*GameInfo) MarshalJSONBuf

func (mj *GameInfo) MarshalJSONBuf(buf fflib.EncodingBuffer) error

func (*GameInfo) UnmarshalJSON

func (uj *GameInfo) UnmarshalJSON(input []byte) error

func (*GameInfo) UnmarshalJSONFFLexer

func (uj *GameInfo) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error

type Recording

type Recording struct {
	// contains filtered or unexported fields
}

Recording manages the reading and writing of recording data to an io.ReadWriteSeeker such as an *os.File

func NewRecording

func NewRecording(file io.ReadWriteSeeker) (*Recording, error)

NewRecording creates a new recording for writing to, or reads an existing recording to read from using the io.ReadWriteSeeker, such as an *os.File.

func (*Recording) DeclareComplete

func (r *Recording) DeclareComplete() error

DeclareComplete declares the recording as a complete recording.

func (*Recording) HasChunk

func (r *Recording) HasChunk(num int) bool

HasChunk returns whether or not the specified chunk ID already exists in the recording or not.

func (*Recording) HasGameMetadata

func (r *Recording) HasGameMetadata() bool

HasGameMetadata returns whether or not the metadata of the game has already been written to the recording or not.

func (*Recording) HasKeyFrame

func (r *Recording) HasKeyFrame(num int) bool

HasKeyFrame returns whether or not the specified keyframe already exists in the recording or not.

func (*Recording) HasUserMetadata

func (r *Recording) HasUserMetadata() bool

HasUserMetadata returns whether or not the user metadata has already been written to the recording or not.

func (*Recording) IsComplete

func (r *Recording) IsComplete() bool

IsComplete returns whether or not the recording has been declared as being complete or not.

func (*Recording) LastWriteTime

func (r *Recording) LastWriteTime() time.Time

LastWriteTime returns the last time data was written to the recording.

func (*Recording) Lock

func (r *Recording) Lock()

Lock locks the recording to disallow any further reads or writes to the recording. This is used to safely close the underlying file without corrupting data written to it, or for other purposes to block reads and writes.

func (*Recording) MarshalJSON

func (mj *Recording) MarshalJSON() ([]byte, error)

func (*Recording) MarshalJSONBuf

func (mj *Recording) MarshalJSONBuf(buf fflib.EncodingBuffer) error

func (*Recording) RetrieveChunkTo

func (r *Recording) RetrieveChunkTo(num int, w io.Writer) (int, error)

RetrieveChunkTo retrieves the chunk data for a chunk ID into w. The number of bytes written to w and any errors that have occurred are returned. If the chunk ID does not exist, ErrMissingData will be returned.

func (*Recording) RetrieveFirstChunkInfo

func (r *Recording) RetrieveFirstChunkInfo() ChunkInfo

RetrieveFirstChunkInfo retrieves the chunk info that should be returned first to the client.

func (*Recording) RetrieveGameInfo

func (r *Recording) RetrieveGameInfo() GameInfo

RetrieveGameInfo retrieves the recorded game's basic information.

func (*Recording) RetrieveGameMetadataTo

func (r *Recording) RetrieveGameMetadataTo(w io.Writer) (int, error)

RetrieveGameMetadataTo retrieves the recorded game metadata into w. The number of bytes written to w and any errors that have occurred are returned.

func (*Recording) RetrieveKeyFrameTo

func (r *Recording) RetrieveKeyFrameTo(num int, w io.Writer) (int, error)

RetrieveKeyFrameTo retrieves the keyframe data into w. The number of bytes written to w and any errors that have occurred are returned. If the chunk ID does not exist, ErrMissingData will be returned.

func (*Recording) RetrieveLastChunkInfo

func (r *Recording) RetrieveLastChunkInfo() ChunkInfo

RetrieveLastChunkInfo retrieves the chunk info that should be returned after FirstChunkInfo.

func (*Recording) RetrieveUserMetadata

func (r *Recording) RetrieveUserMetadata(metadata interface{}) error

RetrieveUserMetadata retrieves the arbitrary user data stored by StoreUserMetadata into metadata.

func (*Recording) StoreChunk

func (r *Recording) StoreChunk(num int, rd io.Reader) error

StoreChunk stores the chunk data for a chunk ID. If the chunk ID already exists in the recording, ErrCannotModify will be returned.

func (*Recording) StoreFirstChunkInfo

func (r *Recording) StoreFirstChunkInfo(chunkInfo ChunkInfo) error

StoreFirstChunkInfo stores the chunk info that should be returned first to the client.

func (*Recording) StoreGameInfo

func (r *Recording) StoreGameInfo(info GameInfo) error

StoreGameInfo stores the game's basic information to the file.

func (*Recording) StoreGameMetadata

func (r *Recording) StoreGameMetadata(rd io.Reader) error

StoreGameMetadata stores the game metadata to the file.

func (*Recording) StoreKeyFrame

func (r *Recording) StoreKeyFrame(num int, rd io.Reader) error

StoreKeyFrame stores the keyframe data for a keyframe number. If the key frame already exists in the recording, ErrCannotModify will be returned.

func (*Recording) StoreLastChunkInfo

func (r *Recording) StoreLastChunkInfo(chunkInfo ChunkInfo) error

StoreLastChunkInfo stores the chunk info that should be returned after FirstChunkInfo.

func (*Recording) StoreUserMetadata

func (r *Recording) StoreUserMetadata(metadata interface{}) error

StoreUserMetadata stores arbitrary data with the recording for convenience. Note that the user metadata is read-only, and thus can only be stored once. It can be retrieved with RetrieveUserMetadata.

func (*Recording) Unlock

func (r *Recording) Unlock()

Unlock unlocks the recording that was previously locked to allow reads or writes to the recording. Ensure that Unlock is called after Lock is called.

func (*Recording) UnmarshalJSON

func (uj *Recording) UnmarshalJSON(input []byte) error

func (*Recording) UnmarshalJSONFFLexer

func (uj *Recording) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL