We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Currently, trying to use scale to decode structs where fields are strings or arrays of strings doesn't work.
Strings on their own (not in struct) works for encoding/decoding and encoding strings in structs is working fine.
eg. if we run this from the codec package:
func TestEncodeAndDecodeStringInStruct(t *testing.T) { test := &struct{ A string } { A: "noot", } enc, err := Encode(test) if err != nil { t.Fatal(err) } dec, err := Decode(enc, &struct{A string}{A: ""}) if err != nil { t.Fatal(err) } if !reflect.DeepEqual(test, dec) { t.Fatalf("Fail: got %v expected %v", dec, test) } }
This will not work, the resulting A field will be empty: Fail: got &{} expected &{noot}
A
Fail: got &{} expected &{noot}
A workaround right now is to cast all strings in a struct to []byte then use scale, which works fine.
[]byte
for example, this works:
func TestEncodeAndDecodeByteArrayInStruct(t *testing.T) { test := &struct{ A []byte } { A: []byte("noot"), } enc, err := Encode(test) if err != nil { t.Fatal(err) } dec, err := Decode(enc, &struct{A []byte}{A: []byte{}}) if err != nil { t.Fatal(err) } if !reflect.DeepEqual(test, dec) { t.Fatalf("Fail: got %v expected %v", dec, test) } }
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
Currently, trying to use scale to decode structs where fields are strings or arrays of strings doesn't work.
Strings on their own (not in struct) works for encoding/decoding and encoding strings in structs is working fine.
eg. if we run this from the codec package:
This will not work, the resulting
A
field will be empty:Fail: got &{} expected &{noot}
A workaround right now is to cast all strings in a struct to
[]byte
then use scale, which works fine.for example, this works:
The text was updated successfully, but these errors were encountered: