getValueFromIntKey<T> method

T getValueFromIntKey<T>(
  1. int key
)

Retrieves the value associated with the specified integer key from the CborMapValue.

If key does not exist in the map and T is nullable, returns null. Otherwise, throws a MessageException.

Implementation

T getValueFromIntKey<T>(int key) {
  final val = value[CborIntValue(key)];
  if (val == null && null is T) return null as T;
  if (null is T && val is CborNullValue) return null as T;
  if (val is CborObject && val.value is T) return val.value;
  if (val is! T) {
    throw MessageException("Failed to cast value.",
        details: {"Excepted": val.runtimeType, "Type": "$T"});
  }
  return val;
}