public void writeRating(Rating rating) throws IOException {
    // the buffer should already be clear
    assert ratingBuffer.position() == 0;
    assert ratingBuffer.limit() == ratingBuffer.capacity();

    checkUpgrade(rating.getUserId(), rating.getItemId());

    // and use it
    format.renderRating(rating, ratingBuffer);
    ratingBuffer.flip();
    BinaryUtils.writeBuffer(channel, ratingBuffer);
    ratingBuffer.clear();

    saveIndex(userMap, rating.getUserId(), index);
    saveIndex(itemMap, rating.getItemId(), index);
    index += 1;

    if (format.hasTimestamps()) {
      long ts = rating.getTimestamp();
      // did this timestamp send us backwards?
      if (ts < lastTimestamp && !needsSorting) {
        logger.debug("found out-of-order timestamps, activating sorting");
        needsSorting = true;
      }
      lastTimestamp = ts;
    }
  }