Skip to content

Commit

Permalink
update encoding enum and runtime interface (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvalabs-manish authored Sep 11, 2023
1 parent d924b9f commit e8bc16c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
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

0 comments on commit e8bc16c

Please sign in to comment.