public static OSCPacket LoadPacket(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return(null);
            }

            //TODO: Omg
            try
            {
                return(OSCConverter.Unpack(File.ReadAllBytes(filePath)));
            }
            catch (Exception e)
            {
                Debug.LogFormat("[OSCEditorUtils] Load Packet error: {0}", e);

                try
                {
                    var document = new XmlDocument();
                    document.Load(filePath);

                    return(OSCPacket.FromBase64String(document.FirstChild.InnerText));
                }
                catch (Exception e2)
                {
                    Debug.LogFormat("[OSCEditorUtils] Load Old Format Packet Error: {0}", e2);
                }
            }

            return(null);
        }
示例#2
0
        public static OSCPacket CopyPacket(OSCPacket packet)
        {
            var size   = 0;
            var buffer = OSCConverter.Pack(packet, out size);

            return(OSCConverter.Unpack(buffer, size));
        }
        protected OSCPacket Receive(UdpClient receivedClient, IAsyncResult result)
        {
            try
            {
                IPEndPoint ip    = null;
                var        bytes = receivedClient.EndReceive(result, ref ip);

                if (bytes != null && bytes.Length > 0)
                {
                    var packet = OSCConverter.Unpack(bytes);
                    packet.Ip   = ip.Address;
                    packet.Port = ip.Port;

                    return(packet);
                }
            }
            catch (ObjectDisposedException)
            { }
            catch (Exception e)
            {
                Debug.LogErrorFormat("[OSCReceiver] Receive error: " + e);
            }

            return(null);
        }
示例#4
0
        public static IOSCPacket LoadPacket(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return(null);
            }

            try
            {
                return(OSCConverter.Unpack(File.ReadAllBytes(filePath)));
            }
            catch (Exception e)
            {
                Debug.LogFormat("[extOSC:OSCEditorUtils] Load packet exception: {0}", e);

                try
                {
                    var document = new XmlDocument();
                    document.Load(filePath);

                    return(OSCUtilities.FromBase64String(document.FirstChild.InnerText));
                }
                catch (Exception e2)
                {
                    Debug.LogFormat("[extOSC:OSCEditorUtils] Old format unpack exception: {0}", e2);
                }
            }

            return(null);
        }
示例#5
0
        private static void Log(OSCConsolePacket message)
        {
            // COPY PACKET
            var rawData = OSCConverter.Pack(message.Packet);

            message.Packet = OSCConverter.Unpack(rawData);

            OSCConsole.ConsoleBuffer.Add(message);
        }
示例#6
0
        private static void Log(OSCConsolePacket message)
        {
#if UNITY_EDITOR
            // COPY PACKET
            var rawData = OSCConverter.Pack(message.Packet);
            message.Packet = OSCConverter.Unpack(rawData);

            _consoleBuffer.Add(message);
#else
            if (_logConsole)
            {
                Debug.LogFormat("[OSCConsole] Packed {0}: {1}", message.PacketType, message.Packet);
            }
#endif
        }
示例#7
0
        private OSCPacket ReadPacket()
        {
            var ip     = (IPAddress)null;
            var ipSize = _reader.ReadInt32();

            if (ipSize > 0)
            {
                var ipBytes = _reader.ReadBytes(ipSize);
                ip = new IPAddress(ipBytes);
            }

            var port  = (int)_reader.ReadUInt16();
            var size  = _reader.ReadInt32();
            var bytes = _reader.ReadBytes(size);

            var message = OSCConverter.Unpack(bytes);

            message.Ip   = ip;
            message.Port = port;

            return(message);
        }
示例#8
0
        private void Receive(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        {
            try
            {
                using (var dataReader = args.GetDataReader())
                {
                    var data = new byte[dataReader.UnconsumedBufferLength];
                    dataReader.ReadBytes(data);

                    var packet = OSCConverter.Unpack(data);
                    packet.Ip   = IPAddress.Parse(args.RemoteAddress.ToString());
                    packet.Port = int.Parse(args.RemotePort);

                    if (_receivedCallback != null)
                    {
                        _receivedCallback.Invoke(packet);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogErrorFormat("[OSCReceiver] Receive error: " + e);
            }
        }
 public static OSCPacket CopyPacket(OSCPacket packet)
 {
     return(OSCConverter.Unpack(OSCConverter.Pack(packet)));
 }
示例#10
0
 public static IOSCPacket FromBase64String(string value)
 {
     return(OSCConverter.Unpack(Convert.FromBase64String(value)));
 }