示例#1
0
        /// <summary>
        /// Deserialize the packet.
        /// </summary>
        /// <param name="sourceEndPoint">The packet origin.</param>
        /// <param name="data">The serialized packet.</param>
        /// <param name="start">The starting index into the serialized data stream.</param>
        /// <returns>The newly deserialized packet.</returns>
        public static OscMessage FromByteArray(IPEndPoint sourceEndPoint, byte[] data, ref int start)
        {
            string     tmp     = System.Text.ASCIIEncoding.ASCII.GetString(data);
            string     address = OscPacket.ValueFromByteArray <string>(data, ref start);
            OscMessage message = new OscMessage(sourceEndPoint, address);

            char[] tags = OscPacket.ValueFromByteArray <string>(data, ref start).ToCharArray();
            foreach (char tag in tags)
            {
                object value;
                switch (tag)
                {
                case DefaultTag:
                    continue;

                case IntegerTag:
                    value = OscPacket.ValueFromByteArray <int>(data, ref start);
                    break;

                case LongTag:
                    value = OscPacket.ValueFromByteArray <long>(data, ref start);
                    break;

                case FloatTag:
                    value = OscPacket.ValueFromByteArray <float>(data, ref start);
                    break;

                case DoubleTag:
                    value = OscPacket.ValueFromByteArray <double>(data, ref start);
                    break;

                case TrueTag:
                    value = true;
                    break;

                case FalseTag:
                    value = false;
                    break;

                case StringTag:
                case SymbolTag:
                    value = OscPacket.ValueFromByteArray <string>(data, ref start);
                    break;

                case BlobTag:
                    value = OscPacket.ValueFromByteArray <byte[]>(data, ref start);
                    break;

                default:
                    Debug.WriteLine("Unknown tag: " + tag);
                    continue;
                }

                message.Append(value);
            }

            return(message);
        }
示例#2
0
        /// <summary>
        /// Deserialize the packet.
        /// </summary>
        /// <param name="sourceEndPoint">The packet origin.</param>
        /// <param name="data">The serialized packet.</param>
        /// <param name="start">The starting index into the serialized data stream.</param>
        /// <param name="end">The ending index into the serialized data stream.</param>
        /// <returns>The newly deserialized packet.</returns>
        public static new OscBundle FromByteArray(IPEndPoint sourceEndPoint, byte[] data, ref int start, int end)
        {
            string address = OscPacket.ValueFromByteArray <string>(data, ref start);

            Assert.IsTrue(address == BundlePrefix);

            OscTimeTag timeStamp = OscPacket.ValueFromByteArray <OscTimeTag>(data, ref start);
            OscBundle  bundle    = new OscBundle(sourceEndPoint, timeStamp);

            while (start < end)
            {
                int length    = OscPacket.ValueFromByteArray <int>(data, ref start);
                int packetEnd = start + length;
                bundle.Append(OscPacket.FromByteArray(sourceEndPoint, data, ref start, packetEnd));
            }

            return(bundle);
        }
        /// <summary>
        /// Deserialize the packet.
        /// </summary>
        /// <param name="sourceEndPoint">The packet origin.</param>
        /// <param name="data">The serialized packet.</param>
        /// <param name="start">The starting index into the serialized data stream.</param>
        /// <returns>The newly deserialized packet.</returns>
        public static OscMessage FromByteArray(IPEndPoint sourceEndPoint, byte[] data, ref int start)
        {
            string     address = OscPacket.ValueFromByteArray <string>(data, ref start);
            OscMessage message = new OscMessage(sourceEndPoint, address);

            char[] tags = OscPacket.ValueFromByteArray <string>(data, ref start).ToCharArray();
            foreach (char tag in tags)
            {
                object value;
                switch (tag)
                {
                case DefaultTag:
                    continue;

                case IntegerTag:
                    value = OscPacket.ValueFromByteArray <int>(data, ref start);
                    break;

                case LongTag:
                    value = OscPacket.ValueFromByteArray <long>(data, ref start);
                    break;

                case FloatTag:
                    value = OscPacket.ValueFromByteArray <float>(data, ref start);
                    break;

                case DoubleTag:
                    value = OscPacket.ValueFromByteArray <double>(data, ref start);
                    break;

                case StringTag:
                case SymbolTag:
                    value = OscPacket.ValueFromByteArray <string>(data, ref start);
                    break;

                case BlobTag:
                    value = OscPacket.ValueFromByteArray <byte[]>(data, ref start);
                    break;

                case TimeTag:
                    value = OscPacket.ValueFromByteArray <OscTimeTag>(data, ref start);
                    break;

                case CharacterTag:
                    value = OscPacket.ValueFromByteArray <char>(data, ref start);
                    break;

                case TrueTag:
                    value = true;
                    break;

                case FalseTag:
                    value = false;
                    break;

                case NilTag:
                    value = null;
                    break;

                case InfinitumTag:
                    value = float.PositiveInfinity;
                    break;

                default:
                    Debug.WriteLine("Unknown tag: " + tag);
                    continue;
                }

                message.Append(value);
            }

            return(message);
        }