示例#1
0
        /// <summary>
        /// Reads an event message from the reader.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="targetDeviceId"></param>
        /// <param name="sourceDeviceId"></param>
        /// <returns></returns>
        internal static RnetHandshakeMessage Read(RnetMessageBodyReader reader, RnetDeviceId targetDeviceId, RnetDeviceId sourceDeviceId)
        {
            Contract.Requires<ArgumentNullException>(reader != null);

            var handshakeType = (RnetHandshakeType)reader.ReadByte();
            
            return new RnetHandshakeMessage(
                targetDeviceId, sourceDeviceId,
                handshakeType);
        }
示例#2
0
        /// <summary>
        /// Reads an event message from the reader.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="targetDeviceId"></param>
        /// <param name="sourceDeviceId"></param>
        /// <returns></returns>
        internal static RnetNumberSixMessage Read(RnetMessageBodyReader reader, RnetDeviceId targetDeviceId, RnetDeviceId sourceDeviceId)
        {
            Contract.Requires<ArgumentNullException>(reader != null);

            return new RnetNumberSixMessage(
                targetDeviceId, sourceDeviceId,
                reader.ReadByte(),
                reader.ReadByte(),
                reader.ReadByte(),
                reader.ReadByte(),
                reader.ReadByte());
        }
示例#3
0
        /// <summary>
        /// Reads an event message from the reader.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="targetDeviceId"></param>
        /// <param name="sourceDeviceId"></param>
        /// <returns></returns>
        internal static RnetRequestDataMessage Read(RnetMessageBodyReader reader, RnetDeviceId targetDeviceId, RnetDeviceId sourceDeviceId)
        {
            Contract.Requires<ArgumentNullException>(reader != null);

            var targetPath = RnetPath.Read(reader);
            var sourcePath = RnetPath.Read(reader);
            var type = (RnetRequestMessageType)reader.ReadByte();

            return new RnetRequestDataMessage(
                targetDeviceId, sourceDeviceId,
                targetPath,
                sourcePath,
                type);
        }
示例#4
0
        /// <summary>
        /// Attempts to parse the given RNet message body.
        /// </summary>
        /// <param name="body"></param>
        /// <returns></returns>
        RnetMessage ParseMessage(RnetMessageBodyReader reader)
        {
            Contract.Requires<ArgumentNullException>(reader != null);

            try
            {
                // parse device ids
                var targetDeviceId = RnetDeviceId.Read(reader);
                var sourceDeviceId = RnetDeviceId.Read(reader);
                var messageType = (RnetMessageType)reader.ReadByte();

                switch (messageType)
                {
                    case RnetMessageType.Event:
                        return RnetEventMessage.Read(reader, targetDeviceId, sourceDeviceId);
                    case RnetMessageType.RequestData:
                        return RnetRequestDataMessage.Read(reader, targetDeviceId, sourceDeviceId);
                    case RnetMessageType.SetData:
                        return RnetSetDataMessage.Read(reader, targetDeviceId, sourceDeviceId);
                    case RnetMessageType.Handshake:
                        return RnetHandshakeMessage.Read(reader, targetDeviceId, sourceDeviceId);
                    case RnetMessageType.Number6:
                        return RnetNumberSixMessage.Read(reader, targetDeviceId, sourceDeviceId);
                    default:
                        return RnetUnknownMessage.Read(reader, targetDeviceId, sourceDeviceId, messageType);
                }
            }
            catch (RnetException e)
            {
                ExceptionDispatchInfo.Capture(e).Throw();
            }
            catch (Exception e)
            {
                throw new RnetProtocolException("Exception parsing RNET message.", e);
            }

            // unreachable
            return null;
        }
示例#5
0
        /// <summary>
        /// Reads an event message from the reader.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="targetDeviceId"></param>
        /// <param name="sourceDeviceId"></param>
        /// <returns></returns>
        internal static RnetSetDataMessage Read(RnetMessageBodyReader reader, RnetDeviceId targetDeviceId, RnetDeviceId sourceDeviceId)
        {
            Contract.Requires<ArgumentNullException>(reader != null);

            var targetPath = RnetPath.Read(reader);
            var sourcePath = RnetPath.Read(reader);
            var packetNumber = reader.ReadUInt16();
            var packetCount = reader.ReadUInt16();
            var data = RnetData.Read(reader);

            return new RnetSetDataMessage(
                targetDeviceId, sourceDeviceId,
                targetPath,
                sourcePath,
                packetNumber,
                packetCount,
                data);
        }
示例#6
0
        /// <summary>
        /// Reads an event message from the reader.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="targetDeviceId"></param>
        /// <param name="sourceDeviceId"></param>
        /// <returns></returns>
        internal static RnetEventMessage Read(RnetMessageBodyReader reader, RnetDeviceId targetDeviceId, RnetDeviceId sourceDeviceId)
        {
            Contract.Requires<ArgumentNullException>(reader != null);

            return new RnetEventMessage(
                targetDeviceId, sourceDeviceId,
                RnetPath.Read(reader),
                RnetPath.Read(reader),
                (RnetEvent)reader.ReadUInt16(),
                reader.ReadUInt16(),
                reader.ReadUInt16(),
                (RnetPriority)reader.ReadByte());
        }
示例#7
0
 /// <summary>
 /// Reads an event message from the reader.
 /// </summary>
 /// <param name="reader"></param>
 /// <param name="targetDeviceId"></param>
 /// <param name="sourceDeviceId"></param>
 /// <returns></returns>
 internal static RnetUnknownMessage Read(RnetMessageBodyReader reader, RnetDeviceId targetDeviceId, RnetDeviceId sourceDeviceId, RnetMessageType messageType)
 {
     return new RnetUnknownMessage(
         targetDeviceId, sourceDeviceId,
         messageType);
 }