/**
   * Writes this instance to the given raw data object.
   *
   * @param out {@code non-null;} where to write to
   */
  public final void writeTo(AnnotatedOutput out) {
    throwIfNotPrepared();
    align(out);

    int cursor = out.getCursor();

    if (fileOffset < 0) {
      fileOffset = cursor;
    } else if (fileOffset != cursor) {
      throw new RuntimeException(
          "alignment mismatch: for " + this + ", at " + cursor + ", but expected " + fileOffset);
    }

    if (out.annotates()) {
      if (name != null) {
        out.annotate(0, "\n" + name + ":");
      } else if (cursor != 0) {
        out.annotate(0, "\n");
      }
    }

    writeTo0(out);
  }