Closed seal90 closed 2 years ago
Your using the SmallInt type, this has a length of 2 bytes giving you a signed range of -32768 to +32767, if you want to encode a vlaue larger than 32767 please use int
if i try encode 430080 by SmallInt when i decode i got true num. the code like this var a = cbor.encode(const CborSmallInt(43008)); print(a); var aa = cbor.decode(a); if(aa is CborSmallInt) { print(aa.toInt()); }
print("-------------"); var a1 = cbor.encode(CborInt(BigInt.from(43008))); print(a1); var aa1 = cbor.decode(a1); if(aa1 is CborSmallInt) { print(aa1.toInt()); }
print("-------------"); var a2 = cbor.encode(const CborSmallInt(430080)); print(a2); var aa2 = cbor.decode(a2); if(aa2 is CborSmallInt) { print(aa2.toInt()); }
and the result is
[26, 0, 6, 144, 0] 430080
Sorry I see the problem now, this has been fixed you need version 5.0.1 of the package, not 5.0.0
Thinks i change to 5.0.1 the data will true
i try to run the code at below, i don't unstand why i encode 43008 but decode another num -22528 var a = cbor.encode(const CborSmallInt(43008)); print(a); // [25, 168, 0] var aa = cbor.decode(a); print(aa); // -22528
and i use cbor: ^5.0.0