@Override
    public void write(FieldBase field, StructuredFieldValue s) {
        // Serialize all parts first.. As we need to know length before starting
        // Serialize all the fields.

        //keep the buffer we're serializing everything into:
        GrowableByteBuffer bigBuffer = buf;

        //create a new buffer and serialize into that for a while:
        GrowableByteBuffer buffer = new GrowableByteBuffer(4096, 2.0f);
        buf = buffer;

        int numFields = s.getFieldCount();
        int [] fieldIds = new int[numFields];
        int [] fieldLengths = new int[numFields];

        var iter = s.iterator();
        for (int i=0; iter.hasNext(); i++) {
            Map.Entry<Field, FieldValue> value = iter.next();

            int startPos = buffer.position();
            Field key = value.getKey();
            value.getValue().serialize(key, this);

            fieldLengths[i] = buffer.position() - startPos;
            fieldIds[i] = key.getId();
        }

        // Switch buffers again:
        buffer.flip();
        buf = bigBuffer;

        // Actual serialization starts here.
        int lenPos = buf.position();
        putInt(null, 0); // Move back to this after compression is done.
        buf.put(CompressionType.NONE.getCode());
        buf.putInt1_4Bytes(numFields);

        for (int i = 0; i < numFields; ++i) {
            putInt1_4Bytes(null, fieldIds[i]);
            putInt2_4_8Bytes(null, fieldLengths[i]);
        }

        int pos = buf.position();
        put(null, buffer.getByteBuffer());
        int dataLength = buf.position() - pos;

        int posNow = buf.position();
        buf.position(lenPos);
        putInt(null, dataLength);
        buf.position(posNow);
    }
Write out the value of structured field

@param field - field description (name and data type)
@param s     - field value
document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java