package gamemanager
import (
"errors"
"fmt"
)
// EngineConfig contains settings information for driving the engine.
type EngineConfig struct {
RenderDescriptions bool
StateTokenFormat SerializationFormat
}
// SerializationFormat determines which format StateTokens are serialized as.
type SerializationFormat int
const (
json SerializationFormat = iota + 1
protobuf
)
func getSerDeFormat(format string) SerializationFormat {
serializationFormats := map[string]SerializationFormat{
"json": json,
"proto": protobuf,
}
return serializationFormats[format]
}
// ErrInvalidSerializationFormat occurs when engine config specifies a unsupported format.
var ErrInvalidSerializationFormat = errors.New("invalid serialization format")
// NewEngineConfig news up an EngineConfig based on passed in values.
func NewEngineConfig(renderDesc bool, tokenFormat string) (EngineConfig, error) {
serdeFormat := getSerDeFormat(tokenFormat)
if serdeFormat == 0 {
return EngineConfig{}, fmt.Errorf("%w: %s", ErrInvalidSerializationFormat, tokenFormat)
}
return EngineConfig{
RenderDescriptions: renderDesc,
StateTokenFormat: serdeFormat,
}, nil
}