content: package alchemystar.engine.net.proto.mysql;
  
  import alchemystar.engine.net.proto.MySQLPacket;
  import alchemystar.engine.net.proto.util.BufferUtil;
  import io.netty.buffer.ByteBuf;
  import io.netty.channel.ChannelHandlerContext;
  
  /**
   * EOFPacket
   *
   * @Author lizhuyang
   */
  public class EOFPacket extends MySQLPacket {
      public static final byte FIELD_COUNT = (byte) 0xfe;
  
      public byte fieldCount = FIELD_COUNT;
      public int warningCount;
      public int status = 2;
  
      public void read(byte[] data) {
          MySQLMessage mm = new MySQLMessage(data);
          packetLength = mm.readUB3();
          packetId = mm.read();
          fieldCount = mm.read();
          warningCount = mm.readUB2();
          status = mm.readUB2();
      }
  
      public void read(BinaryPacket bin) {
          packetLength = bin.packetLength;
          packetId = bin.packetId;
          MySQLMessage mm = new MySQLMessage(bin.data);
          fieldCount = mm.read();
          warningCount = mm.readUB2();
          status = mm.readUB2();
      }
  
      @Override
      public ByteBuf writeBuf(ByteBuf buffer, ChannelHandlerContext ctx) {
          int size = calcPacketSize();
          BufferUtil.writeUB3(buffer, size);
          buffer.writeByte(packetId);
          buffer.writeByte(fieldCount);
          BufferUtil.writeUB2(buffer, warningCount);
          BufferUtil.writeUB2(buffer, status);
          return buffer;
      }
  
      public boolean hasStatusFlag(long flag) {
          return ((this.status & flag) == flag);
      }
  
      @Override
      public int calcPacketSize() {
          return 5;// 1+2+2;
      }
  
      @Override
      protected String getPacketInfo() {
          return "MySQL EOF Packet";
      }
  
  }