getMaxEventsUnderSizeLimit static method

int getMaxEventsUnderSizeLimit(
  1. List<String> events
)

Returns the maximum number of events that can fit under MAX_FLUSH_SIZE bytes.

Implementation

static int getMaxEventsUnderSizeLimit(List<String> events) {
  int totalSize = 0;
  int count = 0;

  for (final event in events) {
    final size = utf8.encode(event).length;

    if ((totalSize + size + DELIMITER_SIZE) > DatabucketsEventTracker.MAX_FLUSH_SIZE) {
      break;
    }

    totalSize += size + DELIMITER_SIZE;
    count++;
  }

  return count;
}