code: private static int getCollectionSize(int[] repetitionLevels, int maxRepetitionLevel, int nextIndex)
      {
          int size = 1;
          while (hasMoreElements(repetitionLevels, nextIndex) && !isCollectionBeginningMarker(repetitionLevels, maxRepetitionLevel, nextIndex)) {
              // Collection elements can not only be primitive, but also can have nested structure
              // Counting only elements which belong to current collection, skipping inner elements of nested collections/structs
              if (repetitionLevels[nextIndex] <= maxRepetitionLevel) {
                  size++;
              }
              nextIndex++;
          }
          return size;
      }
docs: This method is only called for non-empty collections