saving in binairy format

took forever
This commit is contained in:
shinichi
2020-09-30 13:00:13 +02:00
parent 3494f678e3
commit 6f1ab57fe4
2 changed files with 19 additions and 7 deletions

View File

@@ -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);
} }

View File

@@ -25,17 +25,30 @@ namespace Server
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();
} }
} }
} }