operator []= method

void operator []=(
  1. dynamic key,
  2. CandidType value
)
inherited

Associates the key with the given value.

If the key was already in the map, its associated value is changed. Otherwise the key/value pair is added to the map.

Implementation

void operator []=(dynamic key, CandidType value) { // key can be String or a nat(int). if key is String it gets hashed with the candid-hash for the lookup which is: nat.
    late int k;
    if (key is String) {
        k = candid_text_hash(key);
    } else
    if (key is int) {
        if (key >= pow(2,32)) {
            throw Exception('candid fieldtype-id as an int needs to be < 2^32. "An id value must be smaller than 2^32." ');
        }
        k = key;
    }
    else {
        throw Exception('must pass in a String or an int as a fieldtype-id');
    }
    if (type_mode != value.type_mode) {
        throw Exception('A Record or Variant with an type_mode=${type_mode} can only set map-key-values that are with an type_mode=${type_mode}. You tried to set a CandidType-value with a type_mode=${value.type_mode} to the value of a Record/Variant with an type_mode=${type_mode}.');
    }
    _map[k] = value;
}