parseHeaderSize method

String? parseHeaderSize(
  1. String message
)

parse header size of the received message.

parse and set a header size from received message string message. after that return a header string exclude the header size.

Implementation

String? parseHeaderSize(String message) {
  RegExpMatch? headerSizeMatch =
      RegExp('^([0-9]+)(?:$delimiter(.*))?', dotAll: true)
          .firstMatch(message);
  final String? headerSizeStr = headerSizeMatch?.group(1);

  // check it was not match.
  // check it is a number.
  if ((headerSizeStr == null)) {
    throw const MessageFormatException('Could not find body size.');
  } else {
    headerSize = int.parse(headerSizeStr);
  }

  try {
    return headerSizeMatch?.group(2)?.substring(0, headerSize);
  } on RangeError {
    return headerSizeMatch?.group(2)?.substring(0);
  }
}