chunk

package
v0.0.0-...-e78e2ff Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2018 License: BSD-3-Clause Imports: 3 Imported by: 18

Documentation

Index

Constants

View Source
const (
	// Palette refers to color tables.
	Palette = ContentType(0x00)
	// Text refers to texts.
	Text = ContentType(0x01)
	// Bitmap refers to images.
	Bitmap = ContentType(0x02)
	// Font refers to font descriptions.
	Font = ContentType(0x03)
	// VideoClip refers to movies (video-mails).
	VideoClip = ContentType(0x04)
	// Sound refers to audio samples.
	Sound = ContentType(0x07)
	// Geometry refers to 3D models.
	Geometry = ContentType(0x0F)
	// Media refers to audio logs and cutscenes.
	Media = ContentType(0x11)
	// Map refers to archive data.
	Map = ContentType(0x30)
)

Variables

This section is empty.

Functions

func ErrChunkDoesNotExist

func ErrChunkDoesNotExist(id Identifier) error

ErrChunkDoesNotExist returns an error specifying the given ID doesn't have an associated chunk.

Types

type BlockProvider

type BlockProvider interface {
	// BlockCount returns the number of available blocks in the chunk.
	// Unfragmented chunks will always have exactly one block.
	BlockCount() int

	// Block returns the reader for the identified block.
	// Each call returns a new reader instance.
	// Data provided by this reader is always uncompressed.
	Block(index int) (io.Reader, error)
}

BlockProvider are capable of returning block data of a chunk.

type Chunk

type Chunk struct {
	// Fragmented tells whether the chunk should be serialized with a directory.
	// Fragmented chunks can have zero, one, or more blocks.
	// Unfragmented chunks always have exactly one block.
	Fragmented bool

	// ContentType describes how the block data shall be interpreted.
	ContentType ContentType

	// Compressed tells whether the data shall be serialized in compressed form.
	Compressed bool

	// BlockProvider is the keeper of original block data.
	// This provider will be referred to if no other data was explicitly set.
	BlockProvider BlockProvider
	// contains filtered or unexported fields
}

Chunk provides meta information as well as access to its contained blocks.

func (Chunk) Block

func (chunk Chunk) Block(index int) (io.Reader, error)

Block returns the reader for the identified block. Each call returns a new reader instance. Data provided by this reader is always uncompressed.

func (Chunk) BlockCount

func (chunk Chunk) BlockCount() (count int)

BlockCount returns the number of available blocks in the chunk. Unfragmented chunks will always have exactly one block.

func (*Chunk) SetBlock

func (chunk *Chunk) SetBlock(index int, data []byte)

SetBlock registers new data for a block. For any block set this way, the block provider of this chunk will no longer be queried.

type ContentType

type ContentType byte

ContentType identifies how chunk data shall be interpreted.

type Identifier

type Identifier interface {
	// Value returns the numerical value of the identifier.
	Value() uint16
}

Identifier represents an integer key of chunks.

func ID

func ID(value uint16) Identifier

ID packs an integer as a chunk identifier.

type MemoryBlockProvider

type MemoryBlockProvider [][]byte

MemoryBlockProvider is a block provider backed by data in memory.

func (MemoryBlockProvider) Block

func (provider MemoryBlockProvider) Block(index int) (io.Reader, error)

Block returns the reader for the identified block. Each call returns a new reader instance.

func (MemoryBlockProvider) BlockCount

func (provider MemoryBlockProvider) BlockCount() int

BlockCount returns the number of available blocks.

type Provider

type Provider interface {
	// IDs returns a list of available IDs this provider can provide.
	IDs() []Identifier

	// Provide returns a chunk for the given identifier.
	Chunk(id Identifier) (*Chunk, error)
}

Provider provides chunks from some storage.

func NullProvider

func NullProvider() Provider

NullProvider returns a Provider instance that is empty. It contains no IDs and will not provide any chunk.

type ProviderBackedStore

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

ProviderBackedStore is a chunk store that defaults to a provider for returning chunks.

func NewProviderBackedStore

func NewProviderBackedStore(provider Provider) *ProviderBackedStore

NewProviderBackedStore returns a new store based on the specified provider. The created store will have a snapshot of the current provider; Changes in the list of available IDs are not reflected.

func (*ProviderBackedStore) Chunk

func (store *ProviderBackedStore) Chunk(id Identifier) (*Chunk, error)

Chunk returns a chunk for the given identifier.

func (*ProviderBackedStore) Del

func (store *ProviderBackedStore) Del(id Identifier)

Del removes the chunk with given identifier from the store.

func (*ProviderBackedStore) IDs

func (store *ProviderBackedStore) IDs() []Identifier

IDs returns a list of available IDs this store currently contains.

func (*ProviderBackedStore) Put

func (store *ProviderBackedStore) Put(id Identifier, chunk *Chunk)

Put (re-)assigns an identifier with data. If no chunk with given ID exists, then it is created. Existing chunks are overwritten with the provided data.

type Store

type Store interface {
	Provider

	// Del removes the chunk with given identifier from the store.
	// Trying to remove an unknown identifier has no effect.
	Del(id Identifier)

	// Put (re-)assigns an identifier with data. If no chunk with given ID exists,
	// then it is created. Existing chunks are overwritten with the provided data.
	Put(id Identifier, chunk *Chunk)
}

Store represents a dynamically accessible container of chunks.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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