Exemplo n.º 1
0
        /// <summary>
        /// Serialize the packet.
        /// </summary>
        /// <returns>The newly serialized packet.</returns>
        public override byte[] ToByteArray()
        {
            List <byte> data = new List <byte>();

            data.AddRange(OscPacket.ValueToByteArray(mAddress));
            OscPacket.PadNull(data);

            data.AddRange(OscPacket.ValueToByteArray(mTypeTag));
            OscPacket.PadNull(data);

            foreach (object value in mData)
            {
                byte[] bytes = OscPacket.ValueToByteArray(value);
                if (bytes != null)
                {
                    data.AddRange(bytes);
                    if (value is string || value is byte[])
                    {
                        OscPacket.PadNull(data);
                    }
                }
            }

            return(data.ToArray());
        }
Exemplo n.º 2
0
 /// <summary>
 /// Raises the <see cref="PacketReceived"/> event.
 /// </summary>
 /// <param name="packet">The packet to include in the event arguments.</param>
 private void OnPacketReceived(OscPacket packet)
 {
     if (PacketReceived != null)
     {
         PacketReceived(this, new OscPacketReceivedEventArgs(packet));
     }
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Process data received event.
        /// </summary>
        /// <param name="sourceEndPoint"></param>
        /// <param name="data">The received data.</param>
        private void DataReceived(IPEndPoint sourceEndPoint, byte[] data)
        {
            if (mHandleMessages)
            {
                try
                {
                    OscPacket packet = OscPacket.FromByteArray(sourceEndPoint, data);
                    OnPacketReceived(packet);

                    if (packet.IsBundle)
                    {
                        OnBundleReceived(packet as OscBundle);

                        foreach (object value in packet.Data)
                        {
                            OscMessage message = value as OscMessage;
                            if (message != null)
                            {
                                if (mFilterRegisteredMethods)
                                {
                                    if (mRegisteredMethods.Contains(message.Address))
                                    {
                                        OnMessageReceived(message);
                                    }
                                }
                                else
                                {
                                    OnMessageReceived(message);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (mFilterRegisteredMethods)
                        {
                            if (mRegisteredMethods.Contains(packet.Address))
                            {
                                OnMessageReceived(packet as OscMessage);
                            }
                        }
                        else
                        {
                            OnMessageReceived(packet as OscMessage);
                        }
                    }
                }
                catch
                {
                    Console.WriteLine("3");
                    if (mConsumeParsingExceptions == false)
                    {
                        throw;
                    }
                }
            }
        }
Exemplo n.º 5
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.º 6
0
        /// <summary>
        /// Process the data received event.
        /// </summary>
        /// <param name="connection">The <see cref="TcpConnection" /> object associated with this data.</param>
        /// <param name="sourceEndPoint">The source endpoint.</param>
        /// <param name="data">The received data.</param>
        private void DataReceived(TcpConnection connection, IPEndPoint sourceEndPoint, byte[] data)
        {
            if (mHandleMessages)
            {
                try
                {
                    OscPacket packet = OscPacket.FromByteArray(sourceEndPoint, data);
                    if (TransportType == TransportType.Tcp)
                    {
                        packet.Client = new OscClient(connection);
                    }

                    OnPacketReceived(packet);

                    if (packet.IsBundle)
                    {
                        OnBundleReceived(packet as OscBundle);
                    }
                    else
                    {
                        if (FilterRegisteredMethods)
                        {
                            if (mRegisteredMethods.Contains(packet.Address))
                            {
                                OnMessageReceived(packet as OscMessage);
                            }
                        }
                        else
                        {
                            OnMessageReceived(packet as OscMessage);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (ConsumeParsingExceptions == false)
                    {
                        OnReceiveErrored(ex);
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Serialize the packet.
        /// </summary>
        /// <returns>The newly serialized packet.</returns>
        public override byte[] ToByteArray()
        {
            List <byte> data = new List <byte>();

            data.AddRange(OscPacket.ValueToByteArray(mAddress));
            OscPacket.PadNull(data);

            data.AddRange(OscPacket.ValueToByteArray(mTimeStamp));

            foreach (object value in mData)
            {
                if ((value is OscPacket) && (value is OscBundle == false))
                {
                    byte[] packetBytes = ((OscPacket)value).ToByteArray();
                    data.AddRange(OscPacket.ValueToByteArray(packetBytes.Length));
                    data.AddRange(packetBytes);
                }
            }

            return(data.ToArray());
        }
Exemplo n.º 8
0
        /// <summary>
        /// Process the data received event.
        /// </summary>
        /// <param name="sourceEndPoint">The source endpoint.</param>
        /// <param name="data">The received data.</param>
        private void DataReceived(IPEndPoint sourceEndPoint, byte[] data)
        {
            if (mHandleMessages)
            {
                try
                {
                    OscPacket packet = OscPacket.FromByteArray(sourceEndPoint, data);
                    OnPacketReceived(packet);

                    if (packet.IsBundle)
                    {
                        OnBundleReceived(packet as OscBundle);
                    }
                    else
                    {
                        if (mFilterRegisteredMethods)
                        {
                            if (mRegisteredMethods.Contains(packet.Address))
                            {
                                OnMessageReceived(packet as OscMessage);
                            }
                        }
                        else
                        {
                            OnMessageReceived(packet as OscMessage);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (mConsumeParsingExceptions == false)
                    {
                        OnReceiveErrored(ex);
                    }
                }
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Send an OscPacket over the connection.
 /// </summary>
 /// <param name="packet">The <see cref="OscPacket"/> to send.</param>
 public void Send(OscPacket packet)
 {
     byte[] packetData = packet.ToByteArray();
     Connection.Writer.Write(OscPacket.ValueToByteArray(packetData));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Transmit an OSC packet via TCP through the connected OscClient.
 /// </summary>
 /// <param name="packet">The packet to transmit.</param>
 /// <param name="client">The OscClient to communicate through.</param>
 /// <remarks>The OscClient must be connected for successful transmission.</remarks>
 public static void Send(OscPacket packet, OscClient client)
 {
     client.Send(packet);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Transmit an OSC packet.
 /// </summary>
 /// <param name="packet">The packet to transmit.</param>
 /// <param name="destination">The packet's destination.</param>
 public static void Send(OscPacket packet, IPEndPoint destination)
 {
     packet.Send(destination);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="OscMessageReceivedEventArgs"/> class.
        /// </summary>
        /// <param name="packet">The <see cref="OscPacket"/> received.</param>
        public OscPacketReceivedEventArgs(OscPacket packet)
        {
            Assert.ParamIsNotNull(packet);

            mPacket = packet;
        }
Exemplo n.º 13
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     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);
        }