public int marshalledLength(final ObjectContainerBase stream, final ClassMetadata clazz) {
    final IntByRef len =
        new IntByRef(
            stream.stringIO().shortLength(clazz.nameToWrite())
                + Const4.OBJECT_LENGTH
                + (Const4.INT_LENGTH * 2)
                + (Const4.ID_LENGTH));

    len.value += clazz.index().ownLength();

    clazz.forEachDeclaredAspect(
        new Procedure4() {
          public void apply(Object arg) {
            len.value += _family._field.marshalledLength(stream, (ClassAspect) arg);
          }
        });
    return len.value;
  }
  public void write(
      final Transaction trans, final ClassMetadata clazz, final ByteArrayBuffer writer) {

    writer.writeShortString(trans, clazz.nameToWrite());

    int intFormerlyKnownAsMetaClassID = 0;
    writer.writeInt(intFormerlyKnownAsMetaClassID);

    writer.writeIDOf(trans, clazz.i_ancestor);

    writeIndex(trans, clazz, writer);

    writer.writeInt(clazz.declaredAspectCount());
    clazz.forEachDeclaredAspect(
        new Procedure4() {
          public void apply(Object arg) {
            _family._field.write(trans, clazz, (ClassAspect) arg, writer);
          }
        });
  }
  public void defrag(
      final ClassMetadata classMetadata,
      final LatinStringIO sio,
      final DefragmentContextImpl context,
      int classIndexID) {
    readName(sio, context.sourceBuffer());
    readName(sio, context.targetBuffer());

    int metaClassID = 0;
    context.writeInt(metaClassID);

    // ancestor ID
    context.copyID();

    context.writeInt(indexIDForWriting(classIndexID));

    final int aspectCount = context.readInt();

    if (aspectCount > classMetadata.declaredAspectCount()) {
      throw new IllegalStateException();
    }

    final IntByRef processedAspectCount = new IntByRef(0);

    classMetadata.forEachDeclaredAspect(
        new Procedure4() {
          public void apply(Object arg) {
            if (processedAspectCount.value >= aspectCount) {
              return;
            }
            ClassAspect aspect = (ClassAspect) arg;
            _family._field.defrag(classMetadata, aspect, sio, context);
            processedAspectCount.value++;
          }
        });
  }