Skip to content

Commit

Permalink
append len prefix for decode
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Dec 12, 2022
1 parent 4a9cd2f commit ac15f12
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func DecodeData(data []byte) (pairs []types.StoreKVPair, err error) {
offset := 0
offset := 8
for offset < len(data) {
size, n := proto.DecodeVarint(data[offset:])
offset += n
Expand Down
5 changes: 4 additions & 1 deletion versiondb/tmdb/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/crypto-org-chain/cronos/client"
"github.com/crypto-org-chain/cronos/versiondb"
"github.com/crypto-org-chain/cronos/x/cronos/types"
Expand Down Expand Up @@ -35,7 +36,9 @@ func TestFeed(t *testing.T) {
_, err = buf.Write(bz)
require.NoError(t, err)
}
pairs, err := client.DecodeData(buf.Bytes())
data := buf.Bytes()
prefix := sdk.Uint64ToBigEndian(uint64(len(data)))
pairs, err := client.DecodeData(append(prefix, data...))
require.NoError(t, err)
require.NotEmpty(t, pairs)
store := storeCreator()
Expand Down

0 comments on commit ac15f12

Please sign in to comment.