Closed ifyouseewendy closed 3 years ago
@pkedy Hey Phil, thanks for the review. Would you mind publishing a new version for this change as well? So that we can reference it from npm.
For the tinygo, sure thing, if you are not in a hurry, I can take a stab next week
@ifyouseewendy Published @wapc/as-msgpack
as 0.1.12
.
Thanks again for the PR!
👋 Hey guys, thanks for making the as-msgpack package. I'm running into a small issue and I created this PR to propose a fix.
Context
In a dynamic type language, which doesn't have proper type annotation over
i8/i16/i32/i64
,u8/u16/u32/u64
orf32/f64
, it encodes a numeric value simply for what it fits. Or in the case when we transform a numeric value from JSON to MsgPack, there is no way to specify the exact type the value is. In these cases, the current decoder fails to parse the value.For example,
When transforming the JSON value to Msgpack, it becomes
If the value is tagged as
i32
in AS code, it fails to properly decode when usingdecoder.readInt32()
, which results in abad prefix
error.This commit
This commit updates the decoder to auto converts compatible values and throws an error on value overflow and underflow.