cborDecode<T> function

T cborDecode<T>(
  1. List<int> value
)

Implementation

T cborDecode<T>(List<int> value) {
  try {
    final buffer = value is Uint8Buffer ? value : Uint8Buffer()
      ..addAll(value);
    cbor.Input input = cbor.Input(buffer);
    final cbor.Listener listener = cbor.ListenerStack();
    final _decodeStack = cbor.DecodeStack();
    listener.itemStack.clear();
    cbor.Decoder decoder = cbor.Decoder.withListener(input, listener);
    decoder.run();

    List<dynamic>? getDecodedData() {
      try {
        _decodeStack.build(listener.itemStack);
        return _decodeStack.walk();
      } catch (e) {
        rethrow;
      }
    }

    // print(getDecodedData());

    return getDecodedData()![0] as T;
  } catch (e) {
    throw "Can not decode with cbor :$e";
  }
}