@@ -91,23 +91,32 @@ func (e *Enum) Encode(data interface{}) string {
9191 }
9292 }
9393 }
94- for enumKey , value := range data .(map [string ]interface {}) {
95- index := 0
96- for k , v := range e .TypeMapping .Names {
97- if v == enumKey {
98- subType := e .TypeMapping .Types [k ]
99- var typeMap [][]string
100- if len (subType ) > 4 && subType [0 :2 ] == "[[" && json .Unmarshal ([]byte (subType ), & typeMap ) == nil && len (typeMap ) > 0 && len (typeMap [0 ]) == 2 {
101- var raw string
102- valueStruct := value .(map [string ]interface {})
103- for _ , st := range typeMap {
104- raw += EncodeWithOpt (st [1 ], valueStruct [st [0 ]], & ScaleDecoderOption {Spec : e .Spec , Metadata : e .Metadata })
94+ switch dataValue := data .(type ) {
95+ case map [string ]interface {}:
96+ for enumKey , value := range dataValue {
97+ index := 0
98+ for k , v := range e .TypeMapping .Names {
99+ if v == enumKey {
100+ subType := e .TypeMapping .Types [k ]
101+ var typeMap [][]string
102+ if len (subType ) > 4 && subType [0 :2 ] == "[[" && json .Unmarshal ([]byte (subType ), & typeMap ) == nil && len (typeMap ) > 0 && len (typeMap [0 ]) == 2 {
103+ var raw string
104+ valueStruct := value .(map [string ]interface {})
105+ for _ , st := range typeMap {
106+ raw += EncodeWithOpt (st [1 ], valueStruct [st [0 ]], & ScaleDecoderOption {Spec : e .Spec , Metadata : e .Metadata })
107+ }
108+ return utiles .U8Encode (index ) + raw
105109 }
106- return utiles .U8Encode (index ) + raw
110+ return utiles .U8Encode (index ) + EncodeWithOpt ( subType , value , & ScaleDecoderOption { Spec : e . Spec , Metadata : e . Metadata })
107111 }
108- return utiles .U8Encode (index ) + EncodeWithOpt (subType , value , & ScaleDecoderOption {Spec : e .Spec , Metadata : e .Metadata })
112+ index ++
113+ }
114+ }
115+ case string :
116+ for index , v := range e .TypeMapping .Names {
117+ if v == dataValue {
118+ return utiles .U8Encode (index )
109119 }
110- index ++
111120 }
112121 }
113122 }
0 commit comments