Beispiel #1
0
        public static bool TryParse(byte[] data, out SendTextMessage sendTextMessage)
        {
            sendTextMessage = null;

            if (!TrySplitByte(data, PackageControl.UnitSeperator, false, out byte[] emailByte, out byte[] textByte))
Beispiel #2
0
        /// <summary>
        /// Converts a byte array to a Package and returns a code.
        /// 0 - Successful
        /// 1 - Wrong package structur
        /// 2 - Wrong package type
        /// </summary>
        /// <param name="input"></param>
        /// <param name="package"></param>
        /// <returns>0 - Successful, 1 - Wrong package structur, 2 - Wrong package type</returns>
        public static int TryParse(byte[] input, out Package package)
        {
            package = null;

            if (!TryConvertInputByte(input, out PackageType packageType, out byte[] userData))
            {
                return(1);
            }
            switch (packageType)
            {
            case PackageType.RegistrationRequest:
                if (RegistrationRequest.TryParse(userData, out RegistrationRequest request))
                {
                    package = request;
                }
                break;

            case PackageType.LoginRequest:
                if (LoginRequest.TryParse(userData, out LoginRequest login))
                {
                    package = login;
                }
                break;

            case PackageType.UserList:
                if (UserList.TryParse(userData, out UserList userList))
                {
                    package = userList;
                }
                break;

            case PackageType.MessageList:
                if (MessageList.TryParse(userData, out MessageList messageList))
                {
                    package = messageList;
                }
                break;

            case PackageType.TextMessageSend:
                if (SendTextMessage.TryParse(userData, out SendTextMessage sendTextMessage))
                {
                    package = sendTextMessage;
                }
                break;

            case PackageType.TextMessageReceive:
                if (ReceiveTextMessage.TryParse(userData, out ReceiveTextMessage receiveTextMessage))
                {
                    package = receiveTextMessage;
                }
                break;

            case PackageType.Ping:
                break;

            case PackageType.Feedback:
                if (Feedback.TryParse(userData, out Feedback feedback))
                {
                    package = feedback;
                }
                break;

            default:
                break;
            }
            if (package == null)
            {
                return(2);
            }


            return(0);
        }