merge method

void merge(
  1. IntelHex other, [
  2. Overlap overlap = Overlap.error
])

Merge content of other IntelHex object into current object (self). other other IntelHex object. overlap action on overlap of data or starting addr: - error: raising OverlapError; - ignore: ignore other data and keep current data in overlapping region; - replace: replace data with other data in overlapping region. @raise TypeError if other is not instance of IntelHex @raise ValueError if other is the same object as self (it can't merge itself) @raise ValueError if overlap argument has incorrect value @raise AddressOverlapError on overlapped data

Implementation

/// @raise  TypeError       if other is not instance of IntelHex
/// @raise  ValueError      if other is the same object as self
///                         (it can't merge itself)
/// @raise  ValueError      if overlap argument has incorrect value
/// @raise  AddressOverlapError    on overlapped data
void merge(IntelHex other, [Overlap overlap = Overlap.error]){
  // check args
  if(other == this){
    throw("Can't merge itself");
  }

  // merge data
  final thisBuf = buffer;
  final otherBuf = other.buffer;
  for(dynamic i in otherBuf.keys){//(i in other_buf){
    if (thisBuf.containsKey(i)){
      if (overlap == Overlap.error){
        logger?.verbose('Data overlapped at address 0x$i');
      }
      else if(overlap == Overlap.ignore){
        continue;
      }
    }

    if(otherBuf[i] != null){
      thisBuf[i] = otherBuf[i]!;
    }
    // # merge start_addr
    if (startAddr != other.startAddr){
      if(startAddr == null){ // set start addr from other
        startAddr = other.startAddr;
      }
      else if(other.startAddr == null){ // keep existing start addr

      }
      else{ // conflict
        if(overlap == Overlap.error){
          throw('Starting addresses are different');
        }
        else if (overlap == Overlap.replace){
          startAddr = other.startAddr;
        }
      }
    }
  }
}