예제 #1
0
        public static bool TryReadFrom(byte[] data, ref int index, int byteCount, out OscPacket packet)
        {
            if (index >= byteCount)
            {
                packet = null;
                return(false);
            }

            packet = null;

            byte prefix = data[index];

            if (prefix == OscConst.bundlePrefixByte)
            {
                OscBundle bundle;
                if (OscBundle.TryReadFrom(data, ref index, byteCount, out bundle))
                {
                    packet = bundle;
                }
            }
            else if (prefix == OscConst.addressPrefixByte)
            {
                OscMessage message = null;
                if (OscMessage.TryReadFrom(data, ref index, byteCount, ref message))
                {
                    packet = message;
                }
            }

            return(packet != null);
        }
        public static bool TryReadFrom(byte[] data, ref int index, int byteCount, out OscPacket packet)
        {
            if (index >= byteCount)
            {
                packet = null;
                UnityEngine.Debug.LogError("FAIL");
                return(false);
            }

            packet = null;

            byte prefix = data[index];

            if (prefix == OscConst.bundlePrefixByte)
            {
                OscBundle bundle;
                //UnityEngine.Debug.Log( "READ BUNDLE\n" );
                if (OscBundle.TryReadFrom(data, ref index, byteCount, out bundle))
                {
                    packet = bundle;
                }
                //else UnityEngine.Debug.LogError( "Bundle read failed.\n");
            }
            else if (prefix == OscConst.addressPrefixByte)
            {
                OscMessage message = null;
                //UnityEngine.Debug.Log( "READ MESSAGE\n" );
                if (OscMessage.TryReadFrom(data, ref index, ref message))
                {
                    packet = message;
                }
                //else UnityEngine.Debug.LogError( "Message read failed.\n" );
            }
            else
            {
                UnityEngine.Debug.Log("INVALID PREFIX\n");
                index++;
            }

            return(packet != null);
        }