private static int OscMessageToPacket(OscMessage oscM, byte[] packet, int start, int length)
{
int index = start;
index = InsertString(oscM.Address, packet, index, length);
//if (oscM.Values.Count > 0)
{
StringBuilder tag = new StringBuilder();
tag.Append(",");
int tagIndex = index;
index += PadSize(2 + oscM.Values.Count);
foreach (object o in oscM.Values)
{
if (o is int)
{
int i = (int)o;
tag.Append("i");
packet[index++] = (byte)((i >> 24) & 0xFF);
packet[index++] = (byte)((i >> 16) & 0xFF);
packet[index++] = (byte)((i >> 8) & 0xFF);
packet[index++] = (byte)((i) & 0xFF);
}
else
{
if (o is float)
{
float f = (float)o;
tag.Append("f");
byte[] buffer = new byte[4];
MemoryStream ms = new MemoryStream(buffer);
BinaryWriter bw = new BinaryWriter(ms);
bw.Write(f);
packet[index++] = buffer[3];
packet[index++] = buffer[2];
packet[index++] = buffer[1];
packet[index++] = buffer[0];
}
else
{
if (o is string)
{
tag.Append("s");
index = InsertString(o.ToString(), packet, index, length);
}
else
{
tag.Append("?");
}
}
}
}
InsertString(tag.ToString(), packet, tagIndex, length);
}
return index;
}