private ByteBuf write(final ResponseMessage responseMessage, final Object aggregate,
                          final ByteBufAllocator allocator, final EnumSet<MessageParts> parts) throws SerializationException {
        final ByteBuf byteBuf = allocator.buffer();
        final Buffer buffer = bufferFactory.create(byteBuf);

        try {
            if (parts.contains(MessageParts.HEADER)) {
                // Version
                buffer.writeByte(GraphBinaryWriter.VERSION_BYTE);
                if (responseMessage.getResult().isBulked()) {
                    buffer.writeByte(GraphBinaryWriter.BULKED_BYTE);
                } else {
                    buffer.writeByte((byte) 0);
                }
            }

            if (parts.contains(MessageParts.DATA)) {
                final Object data = aggregate == null && responseMessage.getResult() != null
                        ? responseMessage.getResult().getData()
                        : aggregate;
                if (data != null) {
                    for (final Object item : (List) data) {
                        writer.write(item, buffer);
                    }
                }
            }

            if (parts.contains(MessageParts.FOOTER)) {
                final ResponseStatus status = responseMessage.getStatus();

                // we don't know how much data we have, so need a special object
                writer.write(Marker.END_OF_STREAM, buffer);
                // Status code
                writer.writeValue(status.getCode().code(), buffer, false);
                // Nullable status message
                writer.writeValue(status.getMessage(), buffer, true);
                // Nullable exception
                writer.writeValue(status.getException(), buffer, true);
            }
        } catch (IOException e) {
            throw new SerializationException(e);
        }
        return byteBuf;
    }
Creates a new instance of the message serializer using the default type serializers.
gremlin-util/src/main/java/org/apache/tinkerpop/gremlin/util/ser/GraphBinaryMessageSerializerV4.java