Skip to content

Commit

Permalink
simplify encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
timwu20 committed Dec 4, 2023
1 parent 9993b83 commit 6edad0d
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions pkg/scale/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,13 @@ type encodeState struct {
}

func (es *encodeState) marshal(in interface{}) (err error) {
marshalerType := reflect.TypeOf((*Marshaler)(nil)).Elem()
inv := reflect.ValueOf(in)
if inv.Type().Implements(marshalerType) {
methodVal := inv.MethodByName("MarshalSCALE")
values := methodVal.Call(nil)
if !values[1].IsNil() {
errIn := values[1].Interface()
err := errIn.(error)
return err
marshaler, ok := in.(Marshaler)
if ok {
var bytes []byte
bytes, err = marshaler.MarshalSCALE()
if err != nil {
return
}
bytes := values[0].Interface().([]byte)
_, err = es.Write(bytes)
return
}
Expand Down

0 comments on commit 6edad0d

Please sign in to comment.