@Override
    public HandlerStatus onWrite() {
        compactOrClear(dst);
        try {
            for (; ; ) {
                if (packet == null) {
                    packet = src.get();

                    if (packet == null) {
                        // everything is processed, so we are done
                        return CLEAN;
                    }
                }

                if (packetWriter.writeTo(packet, dst)) {
                    // packet got written, lets see if another packet can be written
                    packet = null;
                } else {
                    // the packet didn't get written completely, so we are done.
                    return DIRTY;
                }
            }
        } finally {
            dst.flip();
        }
    }
@Test
    public void whenNotEnoughSpace() {
        final Packet packet = new Packet(serializationService.toBytes(new byte[2000]));
        ByteBuffer dst = ByteBuffer.allocate(1000);
        dst.flip();

        PacketSupplier src = new PacketSupplier();
        src.queue.add(packet);

        encoder.dst(dst);
        encoder.src(src);

        HandlerStatus result = encoder.onWrite();

        assertEquals(DIRTY, result);
    }