Exemplo n.º 1
0
        /// <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.UnpackValue <string>(data, ref start);
            OSCMessage message = new OSCMessage(address);

            char[] tags = OSCPacket.UnpackValue <string>(data, ref start).ToCharArray();

            foreach (char tag in tags)
            {
                object value;

                switch (tag)
                {
                case DEFAULT:
                    continue;

                case INTEGER:
                    value = OSCPacket.UnpackValue <int>(data, ref start);
                    break;

                case LONG:
                    value = OSCPacket.UnpackValue <long>(data, ref start);
                    break;

                case FLOAT:
                    value = OSCPacket.UnpackValue <float>(data, ref start);
                    break;

                case DOUBLE:
                    value = OSCPacket.UnpackValue <double>(data, ref start);
                    break;

                case STRING:
                    value = OSCPacket.UnpackValue <string>(data, ref start);
                    break;

                case BYTE:
                    value = OSCPacket.UnpackValue <byte[]>(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);
        }
Exemplo n.º 2
0
        /// <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);
        }