/// <summary> /// Unpacks an OSC message. /// </summary> /// <param name="data"> /// A <see cref="System.Byte[]"/> /// </param> /// <param name="start"> /// A <see cref="System.Int32"/> /// </param> /// <returns> /// A <see cref="OSCMessage"/> /// </returns> /// public static OSCMessage Unpack(byte[] data, ref int start) { string address = OSCPacket.UnpackString(data, ref start); OSCMessage message = new OSCMessage(address); char[] tags = OSCPacket.UnpackString(data, ref start).ToCharArray(); if (start == 8) { message._typeTag = ","; } foreach (char tag in tags) { object value; switch (tag) { case FLOAT: value = OSCPacket.UnpackFloat(data, ref start); break; case DEFAULT: continue; case INTEGER: value = OSCPacket.UnpackInt(data, ref start); break; case LONG: value = OSCPacket.UnpackLong(data, ref start); break; case DOUBLE: value = OSCPacket.UnpackDouble(data, ref start); break; case STRING: value = OSCPacket.UnpackString(data, ref start); break; case BYTE: value = OSCPacket.UnpackBytes(data, ref start); break; default: Console.WriteLine("Unknown tag: " + tag); continue; } message.Append(value); } if (message.TimeStamp == 0) { message.TimeStamp = DateTime.Now.Ticks; } return(message); }
/// <summary> /// Unpacks an OSC bundle from a data stream. /// </summary> /// <param name="data"> /// A <see cref="System.Byte[]"/> /// </param> /// <param name="start"> /// A <see cref="System.Int32"/> /// </param> /// <param name="end"> /// A <see cref="System.Int32"/> /// </param> /// <returns> /// A <see cref="OSCBundle"/> /// </returns> public new static OSCBundle Unpack(byte[] data, ref int start, int end) { string address = OSCPacket.UnpackString(data, ref start); Trace.Assert(address == BUNDLE); long timeStamp = OSCPacket.UnpackLong(data, ref start); OSCBundle bundle = new OSCBundle(timeStamp); while (start < end) { int length = OSCPacket.UnpackInt(data, ref start); int packetEnd = start + length; bundle.Append(OSCPacket.Unpack(data, ref start, packetEnd)); } return(bundle); }