valueAsBytes<T extends List<int>?> method

T valueAsBytes<T extends List<int>?>(
  1. K key, {
  2. bool allowHex = true,
  3. StringEncoding? encoding,
  4. bool allowJson = false,
  5. T onMissing()?,
  6. bool normalizeKeyLookup = false,
  7. T onError(
    1. 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);
  }
}