parse static method

List<MtomPart> parse({
  1. required String boundary,
  2. required Uint8List response,
})

Implementation

static List<MtomPart> parse({
  required String boundary,
  required Uint8List response,
}) {
  final parts = <MtomPart>[];

  final boundaryBytes = '--$boundary'.codeUnits;
  final crlfBytes = '\r\n'.codeUnits;

  var start = 0;
  var end = 0;

  while (end < response.length) {
    if (response[end] == crlfBytes[0] &&
        response[end + 1] == crlfBytes[1] &&
        response[end + 2] == boundaryBytes[0] &&
        response[end + 3] == boundaryBytes[1]) {
      if (start != end) {
        final part = response.sublist(start, end);
        parts.add(_parsePart(part));
      }

      start = end + 4;
      end = start;
    } else {
      end++;
    }
  }

  return parts;
}