/*
* Copyright 2012-2015 org.opencloudb.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opencloudb.net.mysql;
import java.nio.ByteBuffer;
import org.opencloudb.mysql.BufferUtil;
import org.opencloudb.mysql.MySQLMessage;
import org.opencloudb.net.FrontendConnection;
/**
* From Server To Client, at the end of a series of Field Packets, and at the
* end of a series of Data Packets.With prepared statements, EOF Packet can also
* end parameter information, which we'll describe later.
*
* <pre>
* Bytes Name
* ----- ----
* 1 field_count, always = 0xfe
* 2 warning_count
* 2 Status Flags
*
* @see http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol#EOF_Packet
* </pre>
*
* @author mycat
*/
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();
}
@Override
public ByteBuffer write(ByteBuffer buffer, FrontendConnection c) {
int size = calcPacketSize();
buffer = c.checkWriteBuffer(buffer, c.getPacketHeaderSize() + size);
BufferUtil.writeUB3(buffer, size);
buffer.put(packetId);
buffer.put(fieldCount);
BufferUtil.writeUB2(buffer, warningCount);
BufferUtil.writeUB2(buffer, status);
return buffer;
}
@Override
public int calcPacketSize() {
return 5;// 1+2+2;
}
@Override
protected String getPacketInfo() {
return "MySQL EOF Packet";
}
}