I'd like to use amino marshal when I have private variables in the structure.
In test2 package, test.go :
type Lnt struct {
Neg bool
abs string // this variable
}
func NewLnt() Lnt {
return Lnt{
Neg: true,
abs: "abcdefef",
}
}
testing go file :
func TestAbc(t *testing.T) {
s := test2.NewLnt()
t.Log("s=", s)
cdc := amino.NewCodec()
b, err := cdc.MarshalBinary(s)
assert.Nil(t, err)
t.Log("b=",b)
var s2 test2.Lnt
err = cdc.UnmarshalBinary(b, &s2)
assert.Nil(t, err)
assert.Equal(t, s, s2)
t.Log("s2=", s2)
}
result :
encoding_test.go:39: s= {true abcdefef}
encoding_test.go:55:
Error Trace: encoding_test.go:55
Error: Not equal:
expected: test2.Lnt{Neg:true, abs:"abcdefef"}
actual : test2.Lnt{Neg:true, abs:""} // error
Diff:
--- Expected
+++ Actual
@@ -2,3 +2,3 @@
Neg: (bool) true,
- abs: (string) (len=8) "abcdefef"
+ abs: (string) ""
}
Test: TestAbc
encoding_test.go:57: s2= {true }
Private variable "abs" is lost..
Is it not supported, or is there another way to use it in this case?