/* * Copyright 1999-2012 Alibaba Group. * * 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 com.alibaba.cobar.jdbc.packet; import java.util.ArrayList; import java.util.List; import com.alibaba.cobar.jdbc.util.MySQLMessage; /** * From server to client. One packet for each row in the result set. * * <pre> * Bytes Name * ----- ---- * n (Length Coded String) (column value) * ... * * (column value): The data in the column, as a character string. * If a column is defined as non-character, the * server converts the value into a character * before sending it. Since the value is a Length * Coded String, a NULL can be represented with a * single byte containing 251(see the description * of Length Coded Strings in section "Elements" above). * * @see http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol#Row_Data_Packet * </pre> * * @author xianmao.hexm 2010-7-23 上午01:05:55 */ public class RowDataPacket extends MySQLPacket { public final int fieldCount; public final List<byte[]> fieldValues; public RowDataPacket(int fieldCount) { this.fieldCount = fieldCount; this.fieldValues = new ArrayList<byte[]>(fieldCount); } public void read(BinaryPacket data) { packetLength = data.packetLength; packetId = data.packetId; MySQLMessage mm = new MySQLMessage(data.value); for (int i = 0; i < fieldCount; i++) { fieldValues.add(mm.readBytesWithLength()); } } @Override protected String packetInfo() { return "MySQL RowData Packet"; } }