Decoding of default values
cyborgshead opened this issue · 2 comments
cyborgshead commented
let Coin = TypeFactory.create('Coin', [{
name: 'denom',
type: Types.String,
},
{
name: 'amount',
type: Types.String,
}
]);
let coin = new Coin('', "10000");
console.log("binary coin:\n ", (codec.marshalBinary(coin)).toString()); // 16,255,45,64,175,10,3,99,121,98,18,5,49,48,48,48,48
let decodedCoin = new Coin();
codec.unMarshalBinary(codec.marshalBinary(coin), decodedCoin);
console.log("Decode Data=", decodedCoin.JsObject());
Got
.../Js-Amino/src/binaryDecoder.js:108
throw new RangeError("Index of Field is not match. Expecting:" + (idx + 1) +
^
RangeError: Index of Field is not match. Expecting:1 But got:2
Expected:
Decode Data= { denom: '', amount: '10000' }
TanNgocDo commented
Thanks for reporting, I will check it
TanNgocDo commented
let {
Codec,
FieldOtions,
TypeFactory,
Utils,
Types,
WireTypes
} = require('../index')
let Coin = TypeFactory.create('Coin', [{
name: 'denom',
type: Types.String,
},
{
name: 'amount',
type: Types.String,
}
]);
let codec = new Codec()
codec.registerConcrete(new Coin(), 'coin')
let coin = new Coin('', "10000");
console.log("binary coin:\n ", (codec.marshalBinary(coin)).toString()); // 16,255,45,64,175,10,3,99,121,98,18,5,49,48,48,48,48
let decodedCoin = new Coin();
codec.unMarshalBinary(codec.marshalBinary(coin), decodedCoin);
console.log("Decode Data=", `decodedCoin.JsObject());
I tried this code and it worked, could you please check ?