You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For now, if we want to get primitive types (such as int, uint, bool) from KVStores, we have to UnmarshalBinary it manually. But since the primitive types don't need codec to be unmarshaled, we can make it simpler.
We can declare a wrapper type for byte slices:
type StoreValue []byte
KVStores returns StoreValue instead of raw []byte when Get is called on it
type KVStore interface {
//...
Get([]byte) StoreValue
//...
}
It has the following methods:
func (v StoreValue) Int64() int64
func (v StoreValue) Uint64() uint64
func (v StoreValue) Bool() bool
//...
StoreValue can still be treated as byte slice for the other situations, but if the caller want to unmarshal it to one of the primitive types, they can just call the methods.
Futhermore, we can also support amino types when they are being used with MustUnmarshalBinary.
func (v StoreValue) Amino(cdc *wire.Codec, ptr interface{})
One problem here is if the value is empty then we have to check it before calling the methods. It will be better if we can handle it in one line.
The text was updated successfully, but these errors were encountered:
For now, if we want to get primitive types (such as int, uint, bool) from
KVStore
s, we have toUnmarshalBinary
it manually. But since the primitive types don't need codec to be unmarshaled, we can make it simpler.We can declare a wrapper type for byte slices:
KVStore
s returnsStoreValue
instead of raw[]byte
whenGet
is called on itIt has the following methods:
StoreValue
can still be treated as byte slice for the other situations, but if the caller want to unmarshal it to one of the primitive types, they can just call the methods.Futhermore, we can also support amino types when they are being used with
MustUnmarshalBinary
.One problem here is if the value is empty then we have to check it before calling the methods. It will be better if we can handle it in one line.
The text was updated successfully, but these errors were encountered: