saving in binairy format
took forever
This commit is contained in:
@@ -123,7 +123,6 @@ namespace Server
|
|||||||
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Array.Copy(message, 5, payloadbytes, 0, message.Length - 5);
|
|
||||||
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(payloadbytes));
|
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(payloadbytes));
|
||||||
saveData.WriteDataJSON(Encoding.ASCII.GetString(payloadbytes));
|
saveData.WriteDataJSON(Encoding.ASCII.GetString(payloadbytes));
|
||||||
|
|
||||||
@@ -131,7 +130,7 @@ namespace Server
|
|||||||
else if (DataParser.isRawData(message))
|
else if (DataParser.isRawData(message))
|
||||||
{
|
{
|
||||||
Console.WriteLine(BitConverter.ToString(message));
|
Console.WriteLine(BitConverter.ToString(message));
|
||||||
saveData.WriteDataRAW(ByteArrayToString(message));
|
saveData.WriteDataRAW(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,20 +22,33 @@ namespace Server
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Every line is a new data entry
|
/// Every line is a new data entry
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
public void WriteDataJSON(string data)
|
public void WriteDataJSON(string data)
|
||||||
{
|
{
|
||||||
using (StreamWriter sw = File.AppendText(this.path + "/json"+filename+".txt"))
|
using (StreamWriter sw = File.AppendText(this.path + "/json" + filename + ".txt"))
|
||||||
{
|
{
|
||||||
sw.WriteLine(data);
|
sw.WriteLine(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteDataRAW(string data)
|
public void WriteDataRAW(byte[] data)
|
||||||
{
|
{
|
||||||
using (StreamWriter sw = File.AppendText(this.path + "/raw" + filename + ".txt"))
|
int length = 0;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
sw.WriteLine(data);
|
FileInfo fi = new FileInfo(this.path + "/raw" + filename + ".bin");
|
||||||
|
length = (int)fi.Length;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
using (BinaryWriter sw = new BinaryWriter(File.Open(this.path + "/raw" + filename + ".bin", FileMode.Create)))
|
||||||
|
{
|
||||||
|
|
||||||
|
Console.WriteLine("head position " + sw.Seek(length, SeekOrigin.End));
|
||||||
|
sw.Write(data);
|
||||||
|
sw.Flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user