/// <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.UnpackValue <string>(data, ref start); Trace.Assert(address == BUNDLE); long timeStamp = OSCPacket.UnpackValue <long>(data, ref start); OSCBundle bundle = new OSCBundle(timeStamp); while (start < end) { int length = OSCPacket.UnpackValue <int>(data, ref start); int packetEnd = start + length; bundle.Append(OSCPacket.Unpack(data, ref start, packetEnd)); } return(bundle); }
void didRecievedEvent(OSCServer sender, OSCPacket packet) { lock (_queue) { if (packet.IsBundle()) { var bundle = packet as OSCBundle; foreach (object obj in bundle.Data) { OSCMessage msg = obj as OSCMessage; _queue.Enqueue(msg); } } else { _queue.Enqueue(packet as OSCMessage); } } }
/// <summary> /// Packs the OSC message to binary data. /// </summary> override public void Pack() { List <byte> data = new List <byte>(); data.AddRange(OSCPacket.PackValue(_address)); OSCPacket.PadNull(data); data.AddRange(OSCPacket.PackValue(_typeTag)); OSCPacket.PadNull(data); foreach (object value in _data) { data.AddRange(OSCPacket.PackValue(value)); if (value is string || value is byte[]) { OSCPacket.PadNull(data); } } this._binaryData = data.ToArray(); }