encode static method
List<int>
encode(
- String value, {
- StringEncoding type = StringEncoding.utf8,
- bool validateB64Padding = true,
- bool allowUrlSafe = true,
- Base58Alphabets base58alphabets = Base58Alphabets.bitcoin,
Encodes the given value
string into a list of bytes using the specified type
.
The type
parameter determines the encoding type to use, with UTF-8 being the default.
Returns a list of bytes representing the encoded string.
Implementation
static List<int> encode(String value,
{StringEncoding type = StringEncoding.utf8,
bool validateB64Padding = true,
bool allowUrlSafe = true,
Base58Alphabets base58alphabets = Base58Alphabets.bitcoin}) {
try {
switch (type) {
case StringEncoding.utf8:
return utf8.encode(value);
case StringEncoding.base64:
case StringEncoding.base64UrlSafe:
return B64Decoder.decode(value,
validatePadding: validateB64Padding, urlSafe: allowUrlSafe);
case StringEncoding.base58:
return Base58Decoder.decode(value, base58alphabets);
case StringEncoding.base58Check:
return Base58Decoder.checkDecode(value, base58alphabets);
case StringEncoding.hex:
return BytesUtils.fromHexString(value);
case StringEncoding.ascii:
return ascii.encode(value);
}
} catch (e) {
throw ArgumentException("Failed to convert string as ${type.name} bytes.",
details: {"error": e.toString()});
}
}