Encoding int32, int64 to signed varint?
Closed this issue · 3 comments
Thunnini commented
package main
import (
"encoding/hex"
"fmt"
amino "github.com/tendermint/go-amino"
)
type TestBin struct {
A int64 `binary:"fixed64"`
}
type TestBin2 struct {
A int64
}
func main() {
cdc := amino.NewCodec()
bz, err := cdc.MarshalBinary(TestBin{1})
if err != nil {
panic(err)
}
fmt.Println(hex.EncodeToString(bz))
bz, err = cdc.MarshalBinary(TestBin2{1})
if err != nil {
panic(err)
}
fmt.Println(hex.EncodeToString(bz))
}
Result is
09090100000000000000
020802
https://github.com/tendermint/go-amino/blob/master/codec.go#L521
https://github.com/tendermint/go-amino/blob/master/binary-encode.go#L89
In go-amino, it seemed that they encode int32, 64 to fixed length when users define variables with fixed option.
But js-amino encode int32, 64 to fixed length by default.
I think it is better to encode int32, 64 to varint by default, and support options that encode int32, 64 to fixed length.
TanNgocDo commented
Thanks @Thunnini , options is the target I will implement. I'm trying to fix your last issues. Stay tune for more update :)
Thunnini commented
@TanNgocDo, I really appreciate your efforts. This project is helping me a lot. :)