Skip to content

Commit

Permalink
who encodes
Browse files Browse the repository at this point in the history
  • Loading branch information
hyorigo committed Jan 8, 2024
1 parent 89aa335 commit 722968d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
8 changes: 4 additions & 4 deletions dataconv/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package dataconv

import "go.starlark.net/starlark"

// Unmarshaler is the interface use to unmarshal Starlark custom types.
// Unmarshaler is the interface use to unmarshal Starlark values to custom types.
type Unmarshaler interface {
// UnmarshalStarlark unmarshal a starlark object to custom type.
// UnmarshalStarlark unmarshal a Starlark object to custom type.
UnmarshalStarlark(starlark.Value) error
}

// Marshaler is the interface use to marshal Starlark custom types.
// Marshaler is the interface use to marshal Starlark from custom types.
type Marshaler interface {
// MarshalStarlark marshal a custom type to starlark object.
// MarshalStarlark marshal a custom type to Starlark object.
MarshalStarlark() (starlark.Value, error)
}
8 changes: 4 additions & 4 deletions dataconv/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"go.starlark.net/starlarkstruct"
)

// Unmarshal decodes a starlark.Value into it's Golang counterpart.
// Unmarshal converts a starlark.Value into it's Golang counterpart.
func Unmarshal(x starlark.Value) (val interface{}, err error) {
switch v := x.(type) {
case starlark.NoneType:
Expand Down Expand Up @@ -40,7 +40,7 @@ func Unmarshal(x starlark.Value) (val interface{}, err error) {
kval interface{}
keys []interface{}
vals []interface{}
// key as interface if found one key is not a string
// use interface{} as key type if found one key is not a string
ki bool
)
for _, k := range v.Keys() {
Expand Down Expand Up @@ -159,7 +159,7 @@ func Unmarshal(x starlark.Value) (val interface{}, err error) {
}
}
val = jo
//err = fmt.Errorf("constructor object from *starlarkstruct.Struct not supported Marshaler to starlark object: %T", v.Constructor())
//err = fmt.Errorf("constructor object from *starlarkstruct.Struct not supported Marshaler to Starlark object: %T", v.Constructor())
}
case *convert.GoSlice:
if IsInterfaceNil(v) {
Expand Down Expand Up @@ -193,7 +193,7 @@ func Unmarshal(x starlark.Value) (val interface{}, err error) {
return
}

// Marshal turns Go values into Starlark types. It only supports common Go types, won't wrap any custom types like Starlight does.
// Marshal converts Go values into Starlark types. It only supports common Go types, won't wrap any custom types like Starlight does.
func Marshal(data interface{}) (v starlark.Value, err error) {
switch x := data.(type) {
case nil:
Expand Down
1 change: 0 additions & 1 deletion dataconv/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ func (c *customType) UnmarshalStarlark(v starlark.Value) error {
}

// TODO: refactoring transform data

mustInt64 := func(sv starlark.Value) int64 {
i, _ := sv.(starlark.Int).Int64()
return i
Expand Down

0 comments on commit 722968d

Please sign in to comment.