Exemplo n.º 1
0
        /// <summary>
        /// Returns a value indicating whether this instance is equal to a specified OscTimeTag instance.
        /// </summary>
        /// <param name="value">An object to compare to this instance.</param>
        /// <returns>true if value is an instance of System.DateTime and equals the value of this instance; otherwise, false.</returns>
        public bool Equals(OscTimeTag value)
        {
            if ((object)value == null)
            {
                return(false);
            }

            return(mTimeStamp.Equals(value.mTimeStamp));
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Determines whether two specified instances of OscTimeTag are equal.
 /// </summary>
 /// <param name="lhs">An OscTimeTag.</param>
 /// <param name="rhs">An OscTimeTag.</param>
 /// <returns>true if lhs and rhs represent the same time tag; otherwise, false.</returns>
 public static bool Equals(OscTimeTag lhs, OscTimeTag rhs)
 {
     return(lhs.Equals(rhs));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OscBundle"/> class.
 /// </summary>
 /// <param name="sourceEndPoint">The packet origin.</param>
 /// <param name="timeStamp">The creation time of the bundle.</param>
 /// <param name="client">The destination of sent packets when using TransportType.Tcp.</param>
 public OscBundle(IPEndPoint sourceEndPoint, OscTimeTag timeStamp, OscClient client = null)
     : base(sourceEndPoint, BundlePrefix, client)
 {
     TimeStamp = timeStamp;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Deserialize a value.
        /// </summary>
        /// <typeparam name="T">The value's data type.</typeparam>
        /// <param name="data">The serialized data source.</param>
        /// <param name="start">The starting index into the serialized data stream.</param>
        /// <returns>The newly deserialized value.</returns>
        public static T ValueFromByteArray <T>(byte[] data, ref int start)
        {
            Type   type = typeof(T);
            object value;

            switch (type.Name)
            {
            case "String":
            {
                int count = 0;
                for (int index = start; index < data.Length && data[index] != 0; index++)
                {
                    count++;
                }

                value  = Encoding.ASCII.GetString(data, start, count);
                start += count + 1;
                start  = ((start + 3) / 4) * 4;
                break;
            }

            case "Byte[]":
            {
                int    length = ValueFromByteArray <int>(data, ref start);
                byte[] buffer = data.CopySubArray(start, length);

                value  = buffer;
                start += buffer.Length + 1;
                start  = ((start + 3) / 4) * 4;
                break;
            }

            case "OscTimeTag":
            {
                byte[] buffer = data.CopySubArray(start, 8);
                value  = new OscTimeTag(buffer);
                start += buffer.Length;
                break;
            }

            case "Char":
            {
                value = Convert.ToChar(ValueFromByteArray <int>(data, ref start));
                break;
            }

            case "Color":
            {
                byte[] buffer = data.CopySubArray(start, 4);
                start += buffer.Length;

                value = Color.FromArgb(buffer[3], buffer[0], buffer[1], buffer[2]);
                break;
            }

            default:
            {
                int bufferLength;
                switch (type.Name)
                {
                case "Int32":
                case "Single":
                    bufferLength = 4;
                    break;

                case "Int64":
                case "Double":
                    bufferLength = 8;
                    break;

                default:
                    throw new Exception("Unsupported data type.");
                }

                byte[] buffer = data.CopySubArray(start, bufferLength);
                start += buffer.Length;

                if (BitConverter.IsLittleEndian != LittleEndianByteOrder)
                {
                    buffer = Utility.SwapEndian(buffer);
                }

                switch (type.Name)
                {
                case "Int32":
                    value = BitConverter.ToInt32(buffer, 0);
                    break;

                case "Int64":
                    value = BitConverter.ToInt64(buffer, 0);
                    break;

                case "Single":
                    value = BitConverter.ToSingle(buffer, 0);
                    break;

                case "Double":
                    value = BitConverter.ToDouble(buffer, 0);
                    break;

                default:
                    throw new Exception("Unsupported data type.");
                }
                break;
            }
            }

            return((T)value);
        }