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)}");
|
||||
break;
|
||||
}
|
||||
Array.Copy(message, 5, payloadbytes, 0, message.Length - 5);
|
||||
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(payloadbytes));
|
||||
saveData.WriteDataJSON(Encoding.ASCII.GetString(payloadbytes));
|
||||
|
||||
@@ -131,7 +130,7 @@ namespace Server
|
||||
else if (DataParser.isRawData(message))
|
||||
{
|
||||
Console.WriteLine(BitConverter.ToString(message));
|
||||
saveData.WriteDataRAW(ByteArrayToString(message));
|
||||
saveData.WriteDataRAW(message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,20 +22,33 @@ namespace Server
|
||||
/// <summary>
|
||||
/// Every line is a new data entry
|
||||
/// </summary>
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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