getValue<T> method

T getValue<T>()

Retrieves the value stored in the CborObject as the specified type T.

Throws a MessageException if the stored value cannot be cast to T.

Implementation

T getValue<T>() {
  if (value is CborObject) {
    final cborObject = (value as CborObject);
    if (cborObject.value is T) return cborObject.value;
    if (null is T && cborObject is CborNullValue) return null as T;
  }
  if (null is T && value is CborNullValue) return null as T;
  if (value is! T) {
    throw MessageException("Failed to cast value.", details: {
      "Value": value.runtimeType,
      "Type": "$T",
    });
  }
  return value as T;
}