Esempio n. 1
0
        public async Task <IMessage> ReadAndDecodeMessage(Header header, NetworkStream networkStream)
        {
            byte[] dataBuffer = new byte[header.MessageSize];

            await networkStream.ReadAsync(dataBuffer, 0, dataBuffer.Length);

            Console.WriteLine("message type being read in network service: " + header.MessageType);

            var dataBufferList = dataBuffer.ToList();

            switch (header.MessageType)
            {
            case MessageType.NotSet:
                return(null);

            case MessageType.Connect:
                return(ConnectRequestMessage.Decode(dataBufferList));

            case MessageType.Chat:
                return(ChatMessage.Decode(dataBufferList));

            case MessageType.Image:
                return(ImageMessage.Decode(dataBufferList));

            case MessageType.NewUserOnline:
                return(NewUserOnlineMessage.Decode(dataBufferList));

            case MessageType.UserLogoff:
                return(UserLogoffMessage.Decode(dataBufferList));

            case MessageType.UserOffline:
                return(UserOfflineMessage.Decode(dataBufferList));

            case MessageType.Typing:
                return(UserTypingMessage.Decode(dataBufferList));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 2
0
 public void StrongDecode()
 {
     _ = ChatMessage.Decode(_testBuffer);
 }