public void ObjectToBinaryData()
        {
            string message = "This message cannot be resolved!";

            byte [] data = BinaryDataExtensions.ToByteArrayWithLengthHeader(message);
            Assert.AreEqual(data[0], 44);
        }
 public void Send(object message, bool allowToCompressMessage = true)
 {
     LastSentMessage = message;
     if (DataSent != null)
     {
         DataSent(message);
     }
     if (IsConnected)
     {
         server.ReceiveMessage(this, BinaryDataExtensions.ToByteArrayWithLengthHeader(message));
     }
 }
Exemple #3
0
        public void ConvertBinaryDataToArray()
        {
            var server = new MockServer();

            Assert.IsNull(server.LastMessage);
            var client = new MockClient(server);

            client.Connect("localhost", 1);
            client.Send(new TextMessage("Hi"));
            var serverMessage = server.LastMessage as TextMessage;

            byte[] byteArray       = BinaryDataExtensions.ToByteArrayWithLengthHeader(serverMessage);
            int    classNameLength = "TestMessage".Length + StringLengthByte;
            int    textLength      = "Hi".Length + StringLengthByte + StringIsNullBooleanByte;

            Assert.AreEqual(LengthOfNetworkMessage + LengthOfDataVersion + classNameLength + textLength,
                            byteArray.Length);
        }