removeOption method

void removeOption(
  1. int code
)

Removes all options that have the code.

Implementation

void removeOption(int code) {
  final options = optionsByteData;
  var newLength = options.lengthInBytes;

  while (true) {
    // Find first option of the type
    var i = indexOfOption(code);
    if (i < 0) {
      break;
    }
    newLength = i;

    // Skip the option
    i += options.getUint8(i + 1);

    // Move bytes of remaining options
    while (i < options.lengthInBytes) {
      options.setUint8(newLength, options.getUint8(i));
      i++;
      newLength++;
    }
  }

  // Change length
  optionsByteData = ByteData.view(
    options.buffer,
    options.offsetInBytes,
    newLength,
  );
}