public T Deserialize <T>(object serializedData)
        {
            using (EneterTrace.Entering())
            {
                if (serializedData is byte[] == false)
                {
                    throw new ArgumentException("Input parameter 'serializedData' is not byte[].");
                }

                if (typeof(T) != typeof(MonitorChannelMessage))
                {
                    throw new InvalidOperationException("Data can be deserialized only into" + typeof(MonitorChannelMessage).Name);
                }

                MonitorChannelMessage aResult;

                byte[] aData = (byte[])serializedData;

                using (MemoryStream aStream = new MemoryStream(aData))
                {
                    BinaryReader aReader = new BinaryReader(aStream);

                    // Read type of the message.
                    int aRequest = aReader.ReadByte();
                    MonitorChannelMessageType aMessageType = (MonitorChannelMessageType)aRequest;

                    // If it is the message then read data.
                    object aMessageData = null;
                    if (aMessageType == MonitorChannelMessageType.Message)
                    {
                        aMessageData = myEncoderDecoder.Read(aReader, myIsLittleEndian);
                    }

                    aResult = new MonitorChannelMessage(aMessageType, aMessageData);
                    return((T)(object)aResult);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructs the message from specified parameters.
 /// </summary>
 /// <param name="messageType">type of the message, ping or regular message</param>
 /// <param name="messageContent">message content, in case of ping this parameter is not used</param>
 public MonitorChannelMessage(MonitorChannelMessageType messageType, object messageContent)
 {
     MessageType    = messageType;
     MessageContent = messageContent;
 }