valueAsBytes<T extends List<int>? > method
T
valueAsBytes<T extends List<int>? >(
- K key, {
- bool allowHex = true,
- StringEncoding? encoding,
- bool allowJson = false,
- T onMissing()?,
- bool normalizeKeyLookup = false,
- T onError(
- BuError err
Reads key and coerces it to bytes.
Implementation
T valueAsBytes<T extends List<int>?>(
K key, {
bool allowHex = true,
StringEncoding? encoding,
bool allowJson = false,
T Function()? onMissing,
/// Only applicable when [K] is `String`.
bool normalizeKeyLookup = false,
T Function(BuError err)? onError,
}) {
try {
final value = _checkItem<T>(key, onMissing, normalizeKeyLookup);
if (value == null) return value as T;
return JsonParser.valueAsBytes<T>(
value,
allowHex: allowHex,
encoding: encoding,
allowJson: allowJson,
);
} on BuError catch (e) {
if (onError != null) return onError(e);
throw CoreErrors.jsonErrorWithKey(e, key);
}
}