public void OnDataRead(string jsonData) { if (jsonData.Length == 0) { throw new SFSError("Unexpected empty string data: no readable informations available!"); } if (socketClient.Debug) { log.Info("Data read: " + jsonData); } ISFSObject packet = SFSObject.NewFromJsonData(jsonData); protocolCodec.OnPacketRead(packet); }
private ByteArray HandlePacketData(ByteArray data) { //Discarded unreachable code: IL_01f8 int num = pendingPacket.Header.ExpectedLength - pendingPacket.Buffer.Length; bool flag = data.Length > num; ByteArray result = new ByteArray(data.Bytes); try { log.Debug("Handling Data: " + data.Length + ", previous state: " + pendingPacket.Buffer.Length + "/" + pendingPacket.Header.ExpectedLength); if (data.Length >= num) { pendingPacket.Buffer.WriteBytes(data.Bytes, 0, num); log.Debug("<<< Packet Complete >>>"); if (pendingPacket.Header.Encrypted) { packetEncrypter.Decrypt(pendingPacket.Buffer); } if (pendingPacket.Header.Compressed) { pendingPacket.Buffer.Uncompress(); } protocolCodec.OnPacketRead(pendingPacket.Buffer); fsm.ApplyTransition(PacketReadTransition.PacketFinished); } else { pendingPacket.Buffer.WriteBytes(data.Bytes); } if (flag) { data = ResizeByteArray(data, num, data.Length - num); return(data); } data = EMPTY_BUFFER; return(data); } catch (Exception ex) { log.Error("Error handling data: " + ex.Message + " " + ex.StackTrace); skipBytes = num; fsm.ApplyTransition(PacketReadTransition.InvalidData); return(result); } }
/// <summary> /// /// </summary> /// <param name="data"></param> /// <returns></returns> private ByteArray HandlePacketData(ByteArray data) { int count = pendingPacket.Header.ExpectedLength - pendingPacket.Buffer.Length; bool flag = data.Length > count; ByteArray array = new ByteArray(data.Bytes); try { string message = string.Concat("Handling Data: ", data.Length, ", previous state: ", pendingPacket.Buffer.Length, "/", pendingPacket.Header.ExpectedLength); log.Debug(message); if (data.Length >= count) { pendingPacket.Buffer.WriteBytes(data.Bytes, 0, count); log.Debug("<<< Packet Complete >>>"); if (pendingPacket.Header.Compressed) { pendingPacket.Buffer.Uncompress(); } protocolCodec.OnPacketRead(pendingPacket.Buffer); fsm.ApplyTransition(PacketReadTransition.PacketFinished); } else { pendingPacket.Buffer.WriteBytes(data.Bytes); } if (flag) { data = ResizeByteArray(data, count, data.Length - count); return(data); } data = EMPTY_BUFFER; } catch (Exception exception) { log.Error("Error handling data: " + exception.Message + " " + exception.StackTrace); skipBytes = count; fsm.ApplyTransition(PacketReadTransition.InvalidData); return(array); } return(data); }