/**
   * Writes the formatId and object, and returns the bytes.
   *
   * <p>This is a special case of EntityOutput.writeObject for a top level entity. Special
   * treatments are: - The entity may not be null. - The entity is not checked for existence in the
   * visited object set; entities cannot be referenced by another entity.
   */
  static void writeEntity(
      Format format, Catalog catalog, Object entity, DatabaseEntry data, boolean rawAccess)
      throws RefreshException {

    RecordOutput output = new RecordOutput(catalog, rawAccess);
    output.registerEntity(entity);
    output.writePackedInt(format.getId());
    format.writeObject(entity, output, rawAccess);
    TupleBase.outputToEntry(output, data);
  }
 static void copyElements(RecordInput input, Format format, Format keyFormat, Set results) {
   /*
    * This could be optimized by traversing the byte format of the
    * collection's elements array.
    */
   RawObject collection = (RawObject) format.newInstance(input, true);
   collection = (RawObject) format.readObject(collection, input, true);
   Object[] elements = getElements(collection);
   if (elements != null) {
     for (Object elem : elements) {
       RecordOutput output = new RecordOutput(input.getCatalog(), true);
       output.writeKeyObject(elem, keyFormat);
       DatabaseEntry entry = new DatabaseEntry();
       TupleBase.outputToEntry(output, entry);
       results.add(entry);
     }
   }
 }