decodeTyped<T> function

T decodeTyped<T>(
  1. dynamic raw, {
  2. TransferCodec<T>? codec,
})

Implementation

T decodeTyped<T>(dynamic raw, {TransferCodec<T>? codec}) {
  if (raw is T) {
    return raw;
  }

  if (raw == null) {
    throw CodecException.typeMismatch(T, raw.runtimeType);
  }

  codec ??= TransferCodec.find<T>();
  if (codec != null) {
    return (codec as dynamic).decode(raw) as T;
  }

  throw ApiError.invalidType(T);
}