Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update encoding enum and runtime interface #2

Merged
merged 3 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type Engine interface {
type EngineRuntime interface {
// Kind returns the kind of engine that the factory can produce
Kind() EngineKind
// Version returns the semver version string of the engine runtime
Version() string

// SpawnEngine returns a new Engine instance and initializes it with some
// Fuel, a LogicDriver, the CtxDriver associated with the logic and an EnvDriver.
Expand All @@ -70,9 +72,9 @@ type EngineRuntime interface {
// callsite element pointer from a LogicDriver object
GetCallEncoder(*Callsite, Logic) (CallEncoder, error)

// DecodeDependencyDriver decodes the given bytes into a
// DepDriver that is supported by the engine runtime
DecodeDependencyDriver([]byte) (DependencyDriver, error)
// DecodeDependencyDriver decodes the given bytes of the given
// encoding into a DepDriver that is supported by the engine runtime
DecodeDependencyDriver([]byte, Encoding) (DependencyDriver, error)

// DecodeErrorResult decodes the given bytes into an
// ErrorResult that is used by the engine runtime
Expand Down
14 changes: 7 additions & 7 deletions manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"gopkg.in/yaml.v3"
)

// ManifestEncoding is an enum with variants that describe
// encoding schemes supported for Manifest file objects.
type ManifestEncoding int
// Encoding is an enum with variants that describe
// encoding schemes supported for file objects.
type Encoding int

const (
POLO ManifestEncoding = iota
POLO Encoding = iota
JSON
YAML
)
Expand Down Expand Up @@ -66,7 +66,7 @@ type ManifestElementGenerator func() ManifestElementObject

// NewManifest decodes the given raw data of the specified encoding type into a Manifest.
// Fails if the encoding is unsupported or if the data is malformed.
func NewManifest(data []byte, encoding ManifestEncoding) (*Manifest, error) {
func NewManifest(data []byte, encoding Encoding) (*Manifest, error) {
manifest := new(Manifest)

switch encoding {
Expand Down Expand Up @@ -100,7 +100,7 @@ func ReadManifestFile(path string) (*Manifest, error) {

var (
extension string
encoding ManifestEncoding
encoding Encoding
)

switch extension = filepath.Ext(path); extension {
Expand Down Expand Up @@ -140,7 +140,7 @@ func (manifest Manifest) Hash() ([32]byte, error) {
}

// Encode returns the encoded bytes form of the Manifest for the specified encoding.
func (manifest Manifest) Encode(encoding ManifestEncoding) ([]byte, error) {
func (manifest Manifest) Encode(encoding Encoding) ([]byte, error) {
switch encoding {
case JSON:
return json.Marshal(manifest)
Expand Down
6 changes: 5 additions & 1 deletion registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func (m *mockEngineRuntime) Kind() EngineKind {
return m.kind
}

func (m *mockEngineRuntime) Version() string {
return "v0.0.0"
}

func (m *mockEngineRuntime) SpawnEngine(_ EngineFuel, _ Logic, _ CtxDriver, _ EnvDriver) (Engine, error) {
return nil, nil
}
Expand All @@ -72,7 +76,7 @@ func (m *mockEngineRuntime) GetCallEncoder(_ *Callsite, _ Logic) (CallEncoder, e
return nil, nil
}

func (m *mockEngineRuntime) DecodeDependencyDriver(_ []byte) (DependencyDriver, error) {
func (m *mockEngineRuntime) DecodeDependencyDriver(_ []byte, _ Encoding) (DependencyDriver, error) {
return nil, nil
}

Expand Down