decode<T extends CborObject<Object?>> static method

T decode<T extends CborObject<Object?>>({
  1. List<int>? cborBytes,
  2. CborObject<Object?>? object,
  3. String? hex,
})

Implementation

static T decode<T extends CborObject>({
  List<int>? cborBytes,
  CborObject? object,
  String? hex,
}) {
  try {
    if (object == null) {
      cborBytes ??= BytesUtils.tryFromHexString(hex);
      if (cborBytes != null) {
        object = CborObject.fromCbor(cborBytes);
      }
    }
    if (object is T) {
      return object;
    }
  } catch (_) {}
  throw CborSerializationException(
    "Failed to deserialize CBOR object to $T.",
  );
}