@Override
    public void writeTo(MysqlSerializer serializer) {
        // used to check
        MysqlCapability capability = serializer.getCapability();

        serializer.writeInt1(PACKET_OK_INDICATOR);
        serializer.writeVInt(affectedRows);
        serializer.writeVInt(LAST_INSERT_ID);
        if (capability.isProtocol41()) {
            serializer.writeInt2(serverStatus);
            serializer.writeInt2(warningRows);
        } else if (capability.isTransactions()) {
            serializer.writeInt2(serverStatus);
        }

        if (capability.isSessionTrack()) {
            serializer.writeLenEncodedString(infoMessage);
            // TODO(zhaochun): STATUS_FLAGS
            // if ((STATUS_FLAGS & MysqlStatusFlag.SERVER_SESSION_STATE_CHANGED) != 0) {
            // }
        } else {
            if (!Strings.isNullOrEmpty(infoMessage)) {
                // NOTE: in datasheet, use EOF string, but in the code, mysql use length encoded string
                serializer.writeLenEncodedString(infoMessage);
            }
        }
    }
@Test
    public void testWrite() {
        MysqlOkPacket packet = new MysqlOkPacket(new QueryState());
        MysqlSerializer serializer = MysqlSerializer.newInstance(capability);
        packet.writeTo(serializer);

        ByteBuffer buffer = serializer.toByteBuffer();

        // assert OK packet indicator 0x00
        Assert.assertEquals(0x00, MysqlProto.readInt1(buffer));

        // assert affect rows vint: 0
        Assert.assertEquals(0x00, MysqlProto.readVInt(buffer));

        // assert last insert id, vint: 0
        Assert.assertEquals(0x00, MysqlProto.readVInt(buffer));

        // assert status flags, int2: 0
        Assert.assertEquals(0x00, MysqlProto.readInt2(buffer));

        // assert warnings, int2: 0
        Assert.assertEquals(0x00, MysqlProto.readInt2(buffer));

        // assert info, eof string: "OK"
        // Assert.assertEquals("OK", new String(MysqlProto.readEofString(buffer)));

        Assert.assertEquals(0, buffer.remaining());
    }