Beispiel #1
0
        public ushort ReadShort(ref int position)
        {
            ushort value = BigEndian.ToUInt16(_bodyBuffer, position);

            position += BigEndian.GetSize(value);

            _read.Add(value);
            return(value);
        }
Beispiel #2
0
        public bool CanReadString(int position)
        {
            int readable = (_body.Count - position);

            if (readable < 2)
            {
                return(false);
            }

            ushort stringLength =
                BigEndian.ToUInt16(_bodyBuffer, position);

            return(readable >= (stringLength + 2));
        }
Beispiel #3
0
        public void RemoveString(int position)
        {
            int readable = (_body.Count - position);

            if (readable < 2)
            {
                return;
            }

            ushort stringLength =
                BigEndian.ToUInt16(_bodyBuffer, position);

            if (readable >= (stringLength + 2))
            {
                RemoveBytes(stringLength + 2, position);
            }
        }
Beispiel #4
0
        public HMessage(byte[] data, HDestination destination)
            : this()
        {
            Destination = destination;
            IsCorrupted = (data.Length < 6 ||
                           (BigEndian.ToInt32(data, 0) != data.Length - 4));

            if (!IsCorrupted)
            {
                Header = BigEndian.ToUInt16(data, 4);

                _bodyBuffer = new byte[data.Length - 6];
                Buffer.BlockCopy(data, 6, _bodyBuffer, 0, data.Length - 6);
            }
            else
            {
                _bodyBuffer = data;
            }
            _body.AddRange(_bodyBuffer);
        }