diff --git a/serde-generate/runtime/dart/bcs/bcs_deserializer.dart b/serde-generate/runtime/dart/bcs/bcs_deserializer.dart index 96b37718d..5fff38eb7 100644 --- a/serde-generate/runtime/dart/bcs/bcs_deserializer.dart +++ b/serde-generate/runtime/dart/bcs/bcs_deserializer.dart @@ -56,4 +56,18 @@ class BcsDeserializer extends BinaryDeserializer { "Error while decoding map: keys are not serialized in the expected order"); } } + + bool deserializeBool() { + final result = input.getUint8(offset); + offset += 1; + if (result == 0) { + return false; + } else if (result == 1) { + return true; + } else { + throw Exception( + 'Invalid boolean: expected 0 or 1, but got ${result}', + ); + } + } } diff --git a/serde-generate/runtime/dart/bincode/bincode_deserializer.dart b/serde-generate/runtime/dart/bincode/bincode_deserializer.dart index 1b696e0cc..f5f9cc730 100644 --- a/serde-generate/runtime/dart/bincode/bincode_deserializer.dart +++ b/serde-generate/runtime/dart/bincode/bincode_deserializer.dart @@ -24,4 +24,10 @@ class BincodeDeserializer extends BinaryDeserializer { void checkThatKeySlicesAreIncreasing(Slice key1, Slice key2) { // Not required by the format. } + + bool deserializeBool() { + final result = input.getUint8(offset) != 0; + offset += 1; + return result; + } } diff --git a/serde-generate/runtime/dart/serde/binary_deserializer.dart b/serde-generate/runtime/dart/serde/binary_deserializer.dart index 1f6737439..e2f7045f9 100644 --- a/serde-generate/runtime/dart/serde/binary_deserializer.dart +++ b/serde-generate/runtime/dart/serde/binary_deserializer.dart @@ -11,88 +11,74 @@ abstract class BinaryDeserializer { @protected final ByteData input; - int _offset = 0; + @protected + int offset = 0; + @protected int containerDepthBudget; - int get offset { - return _offset; - } - - bool deserializeBool() { - final result = input.getUint8(_offset); - _offset += 1; - if (result == 0) { - return false; - } else if (result == 1) { - return true; - } else { - throw Exception( - 'Invalid boolean: expected 0 or 1, but got ${result}', - ); - } - } + bool deserializeBool(); Unit deserializeUnit() { return const Unit(); } int deserializeUint8() { - final result = input.getUint8(_offset); - _offset += 1; + final result = input.getUint8(offset); + offset += 1; return result; } int deserializeUint16() { - final result = input.getUint16(_offset, Endian.little); - _offset += 2; + final result = input.getUint16(offset, Endian.little); + offset += 2; return result; } int deserializeUint32() { - final result = input.getUint32(_offset, Endian.little); - _offset += 4; + final result = input.getUint32(offset, Endian.little); + offset += 4; return result; } Uint64 deserializeUint64() { final number = _bytesToBigInt(8, signed: false); - _offset += 8; + offset += 8; return Uint64(number); } int deserializeInt8() { - final result = input.getInt8(_offset); - _offset += 1; + final result = input.getInt8(offset); + offset += 1; return result; } int deserializeInt16() { - final result = input.getInt16(_offset, Endian.little); - _offset += 2; + final result = input.getInt16(offset, Endian.little); + offset += 2; return result; } int deserializeInt32() { - final result = input.getInt32(_offset, Endian.little); - _offset += 4; + final result = input.getInt32(offset, Endian.little); + offset += 4; return result; } int deserializeInt64() { - final result = input.getInt64(_offset, Endian.little); - _offset += 8; + final result = input.getInt64(offset, Endian.little); + offset += 8; return result; } double deserializeFloat32() { - final result = input.getFloat32(_offset, Endian.little); - _offset += 4; + final result = input.getFloat32(offset, Endian.little); + offset += 4; return result; } double deserializeFloat64() { - final result = input.getFloat64(_offset, Endian.little); - _offset += 8; + final result = input.getFloat64(offset, Endian.little); + offset += 8; return result; } @@ -149,7 +135,7 @@ abstract class BinaryDeserializer { // number += BigInt.from(bytes[byteLength - i - 1]) << (8 * i); // little endian - number += BigInt.from(input.getUint8(_offset + i)) << (8 * i); + number += BigInt.from(input.getUint8(offset + i)) << (8 * i); } if (signed) {