encode method
Encodes the input string using the codec's specific algorithm.
input
The plain text string to be encoded.
Returns the encoded string.
Throws ArgumentError if the input is invalid for this codec. Throws FormatException if encoding fails due to format issues.
Implementation
@override
String encode(String input) {
if (input.isEmpty) {
throw ArgumentError('Input cannot be empty');
}
String result = input;
for (int i = 0; i < codecs.length; i++) {
try {
result = codecs[i].encode(result);
} catch (e) {
throw FormatException(
'Failed at codec ${codecs[i].name} (step ${i + 1}): $e');
}
}
return result;
}