deserializeBaseFlag function
Deserializes the base flag and returns true if typed clone, false if dynamic.
Throws DeserializationFormatException if the input is malformed.
Implementation
bool deserializeBaseFlag(final String data, {required final String prefix}) {
final lng = data.length;
if (lng == 0) {
throw DeserializationFormatException('empty data', invalidValue: data);
}
String raw;
if (lng == 1) {
raw = data;
} else {
final prefixLng = prefix.length;
if (lng != prefixLng + 1) {
throw DeserializationFormatException(
'length != $prefixLng',
invalidValue: data,
);
}
if (!data.startsWith(prefix)) {
throw DeserializationFormatException(
'must start with $prefix',
invalidValue: data,
);
}
raw = data.substring(prefixLng);
}
switch (raw) {
case _sTyped:
return true;
case _sDynamic:
return false;
default:
throw DeserializationFormatException(
'malformed doTypedClone',
invalidValue: raw,
);
}
}