예제 #1
0
        /// <summary>
        /// The constructor
        /// </summary>
        /// <param name="mType">The message type</param>
        /// <param name="mCode">The message code</param>
        /// <param name="id">The message Id</param>
        public CoAPRequest(byte mType, byte mCode, UInt16 id)
        {
            if (mType != CoAPMessageType.CON && mType != CoAPMessageType.NON)
            {
                throw new ArgumentException("A request message must be of type CON or NON");
            }
            if (!CoAPMessageCode.DoesMessageCodeRepresentARequest(mCode))
            {
                throw new ArgumentException("The message code is not allowed for a request message");
            }

            this.Version = new CoAPVersion();

            this.MessageType       = new CoAPMessageType();
            this.MessageType.Value = mType;

            this.Code = new CoAPMessageCode();
            if (!this.Code.IsValid(mCode))
            {
                throw new ArgumentException("Invalid message code in request");
            }
            this.Code.Value = mCode;

            this.ID = new CoAPMessageID(id);

            this.Options = new CoAPHeaderOptions();
        }
예제 #2
0
        /// <summary>
        /// Try to check if the message code represents a request code
        /// </summary>
        /// <param name="data">The data stream to parse</param>
        /// <returns>true if message code found and represents a request</returns>
        public static bool PeekIfMessageCodeIsRequestCode(byte[] data)
        {
            if (data == null || data.Length < AbstractCoAPMessage.HEADER_LENGTH)
            {
                throw new ArgumentNullException("Invalid byte stream to parse");
            }
            byte            mCode   = data[1];
            CoAPMessageCode msgCode = new CoAPMessageCode();

            return(msgCode.IsValid(data[1]) && CoAPMessageCode.DoesMessageCodeRepresentARequest(data[1]));
        }