decode method
Decodes a value of storage type TStore
back to type T
.
Returns null if the stored value is null or cannot be decoded.
Implementation
@override
BigInt? decode(String? base64) {
if (base64 == null) return null;
try {
final bytes = base64Decode(base64);
if (bytes.isEmpty) return BigInt.zero;
// First byte indicates sign (0 for positive, 1 for negative)
final isNegative = bytes[0] == 1;
// Remaining bytes are the magnitude
var result = BigInt.zero;
for (var i = 1; i < bytes.length; i++) {
result = (result << 8) | BigInt.from(bytes[i]);
}
return isNegative ? -result : result;
} catch (_) {
return null; // Invalid format
}
}