Documentation ¶
Overview ¶
Package recording handles the encoding and decoding of recorded games to files.
Index ¶
- Constants
- Variables
- type ChunkInfo
- func (mj *ChunkInfo) MarshalJSON() ([]byte, error)
- func (mj *ChunkInfo) MarshalJSONBuf(buf fflib.EncodingBuffer) error
- func (uj *ChunkInfo) UnmarshalJSON(input []byte) error
- func (uj *ChunkInfo) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error
- func (c ChunkInfo) WriteTo(w io.Writer) (int64, error)
- type GameInfo
- type Recording
- func (r *Recording) DeclareComplete() error
- func (r *Recording) HasChunk(num int) bool
- func (r *Recording) HasGameMetadata() bool
- func (r *Recording) HasKeyFrame(num int) bool
- func (r *Recording) HasUserMetadata() bool
- func (r *Recording) IsComplete() bool
- func (r *Recording) LastWriteTime() time.Time
- func (r *Recording) Lock()
- func (mj *Recording) MarshalJSON() ([]byte, error)
- func (mj *Recording) MarshalJSONBuf(buf fflib.EncodingBuffer) error
- func (r *Recording) RetrieveChunkTo(num int, w io.Writer) (int, error)
- func (r *Recording) RetrieveFirstChunkInfo() ChunkInfo
- func (r *Recording) RetrieveGameInfo() GameInfo
- func (r *Recording) RetrieveGameMetadataTo(w io.Writer) (int, error)
- func (r *Recording) RetrieveKeyFrameTo(num int, w io.Writer) (int, error)
- func (r *Recording) RetrieveLastChunkInfo() ChunkInfo
- func (r *Recording) RetrieveUserMetadata(metadata interface{}) error
- func (r *Recording) StoreChunk(num int, rd io.Reader) error
- func (r *Recording) StoreFirstChunkInfo(chunkInfo ChunkInfo) error
- func (r *Recording) StoreGameInfo(info GameInfo) error
- func (r *Recording) StoreGameMetadata(rd io.Reader) error
- func (r *Recording) StoreKeyFrame(num int, rd io.Reader) error
- func (r *Recording) StoreLastChunkInfo(chunkInfo ChunkInfo) error
- func (r *Recording) StoreUserMetadata(metadata interface{}) error
- func (r *Recording) Unlock()
- func (uj *Recording) UnmarshalJSON(input []byte) error
- func (uj *Recording) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error
Constants ¶
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 ¶
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 (*ChunkInfo) MarshalJSONBuf ¶
func (mj *ChunkInfo) MarshalJSONBuf(buf fflib.EncodingBuffer) error
func (*ChunkInfo) UnmarshalJSON ¶
func (*ChunkInfo) UnmarshalJSONFFLexer ¶
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 (*GameInfo) MarshalJSONBuf ¶
func (mj *GameInfo) MarshalJSONBuf(buf fflib.EncodingBuffer) error
func (*GameInfo) UnmarshalJSON ¶
func (*GameInfo) UnmarshalJSONFFLexer ¶
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 ¶
DeclareComplete declares the recording as a complete recording.
func (*Recording) HasChunk ¶
HasChunk returns whether or not the specified chunk ID already exists in the recording or not.
func (*Recording) HasGameMetadata ¶
HasGameMetadata returns whether or not the metadata of the game has already been written to the recording or not.
func (*Recording) HasKeyFrame ¶
HasKeyFrame returns whether or not the specified keyframe already exists in the recording or not.
func (*Recording) HasUserMetadata ¶
HasUserMetadata returns whether or not the user metadata has already been written to the recording or not.
func (*Recording) IsComplete ¶
IsComplete returns whether or not the recording has been declared as being complete or not.
func (*Recording) LastWriteTime ¶
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 (*Recording) MarshalJSONBuf ¶
func (mj *Recording) MarshalJSONBuf(buf fflib.EncodingBuffer) error
func (*Recording) RetrieveChunkTo ¶
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 ¶
RetrieveFirstChunkInfo retrieves the chunk info that should be returned first to the client.
func (*Recording) RetrieveGameInfo ¶
RetrieveGameInfo retrieves the recorded game's basic information.
func (*Recording) RetrieveGameMetadataTo ¶
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 ¶
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 ¶
RetrieveLastChunkInfo retrieves the chunk info that should be returned after FirstChunkInfo.
func (*Recording) RetrieveUserMetadata ¶
RetrieveUserMetadata retrieves the arbitrary user data stored by StoreUserMetadata into metadata.
func (*Recording) StoreChunk ¶
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 ¶
StoreFirstChunkInfo stores the chunk info that should be returned first to the client.
func (*Recording) StoreGameInfo ¶
StoreGameInfo stores the game's basic information to the file.
func (*Recording) StoreGameMetadata ¶
StoreGameMetadata stores the game metadata to the file.
func (*Recording) StoreKeyFrame ¶
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 ¶
StoreLastChunkInfo stores the chunk info that should be returned after FirstChunkInfo.
func (*Recording) StoreUserMetadata ¶
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.