github.com/0chain/gosdk@v1.17.11/wasmsdk/jsbridge/bytes.go (about) 1 //go:build js && wasm 2 // +build js,wasm 3 4 package jsbridge 5 6 import ( 7 "strconv" 8 "strings" 9 ) 10 11 type Bytes struct { 12 Buffer []byte 13 } 14 15 func (bytes *Bytes) UnmarshalJSON(buf []byte) error { 16 17 if len(buf) > 0 { 18 19 src := strings.Trim(string(buf), "\"") 20 21 if len(src) > 0 { 22 items := strings.Split(src, ",") 23 24 bytes.Buffer = make([]byte, len(items)) 25 26 for k, v := range items { 27 it, err := strconv.ParseUint(v, 10, 64) 28 if err != nil { 29 return err 30 } 31 32 bytes.Buffer[k] = byte(it) 33 } 34 35 } 36 37 } 38 39 return nil 40 }