private void ConnectionRead(byte packetNumber, byte[] packet) { packetReader.NewPacket(packet); switch (State) { case ConnectionState.WaitForServerGreet: var connPacket = MySqlConnectionPacket.Parse(packetReader); bool version = connPacket.ServerVersion.IsAtLeast(4, 1, 1); if (!version) { } var response = new ClientAuthResponse() { ClientFlags = 0xA685, MaxPacketSize = 256 * 256, CharsetNumber = connPacket.ServerLanguage, User = Username, }; packetBuilder.NewPacket(); Socket.Write(response.Serialize(packetBuilder)); State = ConnectionState.WaitForLoginResponse; break; case ConnectionState.WaitForLoginResponse: var res = ResponsePacket.Parse(packetReader); if (res is OkPacket) { ConnectionCommand.FireSuccess(res as OkPacket); State = ConnectionState.ParsePackets; FireFirstCommand(); } else if (res is Error) { ConnectionCommand.FireError(res as Error); } break; } }
IEnumerable <bool> ProcessRequest(byte packetNumber, byte[] packet) { var queryCommand = commands.Peek().Callback; packetReader.NewPacket(packet); var type = ResponsePacket.GetType(packet); if (type != ResponsePacketType.Other) { var responsePacket = ResponsePacket.Parse(packetReader); queryCommand.FireResponse(responsePacket); FireNextCommand(); yield return(true); yield break; } long length = packetReader.ReadLength(); byte[] data; byte num; FieldPacket[] fields = new FieldPacket[length]; for (int i = 0; i < length; i++) { while (!ReadPacket(out num, out data)) { yield return(false); } packetReader.NewPacket(data); var field = FieldPacket.Parse(packetReader); fields[i] = field; } var f = new Fields(fields); while (!ReadPacket(out num, out data)) { yield return(false); } queryCommand.FireFields(f.FieldPackets); packetReader.NewPacket(data); // TODO: check if the packet is in place EOFPacket.Parse(packetReader); while (true) { while (!ReadPacket(out num, out data)) { yield return(false); } if (ResponsePacket.GetType(data) == ResponsePacketType.EOF) { queryCommand.FireEnd(); FireNextCommand(); yield return(true); yield break; } packetReader.NewPacket(data); string[] values = new string[length]; for (int i = 0; i < length; i++) { values[i] = packetReader.ReadLengthString(); } queryCommand.FireRow(new Row(f, values)); } }