Update Encoding for special characters

This commit is contained in:
2019-12-15 19:19:37 -06:00
parent 67c0fe176d
commit 7575fe1135
24 changed files with 4960 additions and 4855 deletions
@@ -46,7 +46,7 @@ namespace SharpOSC
int i = 0;
byte[] output = new byte[len];
Encoding.ASCII.GetBytes(bundle).CopyTo(output, i);
Encoding.UTF8.GetBytes(bundle).CopyTo(output, i);
i += bundleTagLen;
tag.CopyTo(output, i);
i += tag.Length;
@@ -142,10 +142,10 @@ namespace SharpOSC
byte[] output = new byte[total];
i = 0;
Encoding.ASCII.GetBytes(Address).CopyTo(output, i);
Encoding.UTF8.GetBytes(Address).CopyTo(output, i);
i += addressLen;
Encoding.ASCII.GetBytes(typeString).CopyTo(output, i);
Encoding.UTF8.GetBytes(typeString).CopyTo(output, i);
i += typeLen;
foreach (byte[] part in parts)
@@ -27,8 +27,9 @@ namespace SharpOSC
private static OscMessage parseMessage(byte[] msg)
{
int index = 0;
//Console.WriteLine("Raw OSC DATA: " + System.Text.Encoding.ASCII.GetString(msg));
string address = null;
//Console.WriteLine("Raw ASCII DATA: " + System.Text.Encoding.ASCII.GetString(msg));
//Console.WriteLine("Raw UTF-8 DATA: " + System.Text.Encoding.UTF8.GetString(msg));
string address = null;
char[] types = new char[0];
List<object> arguments = new List<object>();
List<object> mainArray = arguments; // used as a reference when we are parsing arrays to get the main array back
@@ -178,7 +179,7 @@ namespace SharpOSC
int index = 0;
var bundleTag = Encoding.ASCII.GetString(bundle.SubArray(0, 8));
var bundleTag = Encoding.UTF8.GetString(bundle.SubArray(0, 8));
index += 8;
timetag = getULong(bundle, index);
@@ -221,7 +222,7 @@ namespace SharpOSC
if (i == 0)
return "";
address = Encoding.ASCII.GetString(msg.SubArray(index, i - 1));
address = Encoding.UTF8.GetString(msg.SubArray(index, i - 1));
break;
}
}
@@ -241,7 +242,7 @@ namespace SharpOSC
{
if (msg[i - 1] == 0)
{
types = Encoding.ASCII.GetChars(msg.SubArray(index, i - index));
types = Encoding.UTF8.GetChars(msg.SubArray(index, i - index));
break;
}
}
@@ -249,7 +250,7 @@ namespace SharpOSC
if (types == null)
{
byte[] term = { 0 };
types = Encoding.ASCII.GetChars(term);
types = Encoding.UTF8.GetChars(term);
}
if (i >= msg.Length && types == null)
@@ -283,14 +284,14 @@ namespace SharpOSC
{
if (msg[i - 1] == 0)
{
output = Encoding.ASCII.GetString(msg.SubArray(index, i - index));
output = Encoding.UTF8.GetString(msg.SubArray(index, i - index));
break;
}
}
if (output == null)
{
byte[] term = { 0 };
output = Encoding.ASCII.GetString(term);
output = Encoding.UTF8.GetString(term);
}
if (i >= msg.Length && output == null)
throw new Exception("No null terminator after type string");
@@ -395,7 +396,7 @@ namespace SharpOSC
byte[] msg = new byte[len];
var bytes = Encoding.ASCII.GetBytes(value);
var bytes = Encoding.UTF8.GetBytes(value);
bytes.CopyTo(msg, 0);
return msg;
@@ -75,15 +75,15 @@ namespace SharpOSC
bytesRead = await netStream.ReadAsync(buffer, 0, buffer.Length);
responseData.AddRange(buffer);
Thread.Sleep(1);
//Console.WriteLine( "Thread " + num + ": Bytes read: " + bytesRead + " - " + Encoding.ASCII.GetString(buffer));
//Console.WriteLine( "Thread " + num + ": Bytes read: " + bytesRead + " - " + Encoding.UTF8.GetString(buffer));
} while (netStream.DataAvailable);
//Console.WriteLine("Raw TCP In: " + System.Text.Encoding.ASCII.GetString(responseData.ToArray()));
//Console.WriteLine("Raw TCP In: " + System.Text.Encoding.UTF8.GetString(responseData.ToArray()));
response = (OscMessage)OscPacket.GetPacket(responseData.Skip(1).ToArray());
}
} catch(Exception e)
{
Console.WriteLine("RECEIVE EXCEPTION: " + e.ToString());
Console.WriteLine("TCPSENDER - Receive Exception: " + e.ToString());
}
OnMessageReceived(response);
}
@@ -101,7 +101,7 @@ namespace SharpOSC
public void SendAndReceive(OscPacket packet)
{
OscMessage msg = (OscMessage)packet;
//Console.WriteLine("TCP Message Sent: " + msg.Address);
//Console.WriteLine("TCPSENDER - TCP Message Sent: " + msg.Address);
byte[] data = packet.GetBytes();
SendAndReceive(data);
}