class SetMarshaller<T>
        implements BytesReader<Set<T>>, BytesWriter<Set<T>>, StatefulCopyable<SetMarshaller<T>> {

    // Config fields
    private BytesReader<T> elementReader;
    private BytesWriter<? super T> elementWriter;
    /**
     * Cache field
     */
    private transient Deque<T> orderedElements;

    /**
     * Constructs a {@code SetMarshaller} with the given set elements' serializers.
     * <p>
     * Use static factory {@link #of(BytesReader, BytesWriter)} instead of this constructor
     * directly.
     *
     * @param elementReader set elements' reader
     * @param elementWriter set elements' writer
     */
    public SetMarshaller(BytesReader<T> elementReader, BytesWriter<? super T> elementWriter) {
        this.elementReader = elementReader;
        this.elementWriter = elementWriter;
        initTransients();
    }

    /**
     * Returns a {@code SetMarshaller} which uses the given set elements' serializers.
     *
     * @param elementReader set elements' reader
     * @param elementWriter set elements' writer
     * @param <T>           type of set elements
     * @return a {@code SetMarshaller} which uses the given set elements' serializers
     */
    public static <T> SetMarshaller<T> of(
            BytesReader<T> elementReader, BytesWriter<? super T> elementWriter) {
        return new SetMarshaller<>(elementReader, elementWriter);
    }

    /**
     * Returns a {@code SetMarshaller} which uses the given marshaller as both reader and writer of
     * set elements. Example: <pre><code>
     * ChronicleMap
     *     .of(String.class,{@code (Class<Set<Integer>>)} ((Class) Set.class))
     *     .valueMarshaller(SetMarshaller.of(IntegerMarshaller.INSTANCE))
     *     ...</code></pre>
     *
     * @param elementMarshaller set elements' marshaller
     * @param <T>               type of set elements
     * @param <M>               type of set elements' marshaller
     * @return a {@code SetMarshaller} which uses the given set elements' marshaller
     */
    public static <T, M extends BytesReader<T> & BytesWriter<? super T>> SetMarshaller<T> of(
            M elementMarshaller) {
        return of(elementMarshaller, elementMarshaller);
    }

    private void initTransients() {
        orderedElements = new ArrayDeque<>();
    }

    @NotNull
    @Override
    public Set<T> read(Bytes in, @Nullable Set<T> using) {<FILL_FUNCTION_BODY>}

    @Override
    public void write(Bytes out, @NotNull Set<T> toWrite) {
        out.writeInt(toWrite.size());
        toWrite.forEach(e -> elementWriter.write(out, e));
    }

    @Override
    public SetMarshaller<T> copy() {
        return new SetMarshaller<>(copyIfNeeded(elementReader), copyIfNeeded(elementWriter));
    }

    @Override
    public void readMarshallable(@NotNull WireIn wireIn) {
        elementReader = wireIn.read(() -> "elementReader").typedMarshallable();
        elementWriter = wireIn.read(() -> "elementWriter").typedMarshallable();
        initTransients();
    }

    @Override
    public void writeMarshallable(@NotNull WireOut wireOut) {
        wireOut.write(() -> "elementReader").typedMarshallable(elementReader);
        wireOut.write(() -> "elementWriter").typedMarshallable(elementWriter);
    }
}

        int size = in.readInt();
        if (using == null) {
            using = new HashSet<>((int) (size / 0.75));
            for (int i = 0; i < size; i++) {
                using.add(elementReader.read(in, null));
            }
        } else {
            orderedElements.addAll(using);
            using.clear();
            for (int i = 0; i < size; i++) {
                using.add(elementReader.read(in, orderedElements.pollFirst()));
            }
            orderedElements.clear(); // for GC, avoid zombie object links
        }
        return using;
    
<no_super_class>