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

T decodeCbor<T extends CborObject<Object?>>(
  1. List<int> cborBytes
)

Decode a CBOR (Concise Binary Object Representation) data stream represented by a List<int>. The method decodes the CBOR data and returns the resulting CborObject.

Implementation

static T decodeCbor<T extends CborObject>(List<int> cborBytes) {
  try {
    final decode = _decode(cborBytes);
    assert(decode.consumed == cborBytes.length, "cbor decoding faild.");
    return decode.value.cast<T>();
  } on CborException catch (e) {
    throw ArgumentException.invalidOperationArguments(
      "CborObject",
      name: "cborBytes",
      reason: "Invalid cobr bytes. ${e.message}",
    );
  } catch (_) {
    throw ArgumentException.invalidOperationArguments(
      "CborObject",
      name: "cborBytes",
      reason: "Invalid cobr bytes.",
    );
  }
}