Esempio n. 1
0
        /// <summary>
        /// Reads in 4 bytes and converts it from network to host byte order
        /// </summary>
        /// <returns>A 4 byte value</returns>
        public virtual uint ReadInt()
        {
            var v1 = (byte)ReadByte();
            var v2 = (byte)ReadByte();
            var v3 = (byte)ReadByte();
            var v4 = (byte)ReadByte();

            return(Marshal.ConvertToUInt32(v1, v2, v3, v4));
        }
Esempio n. 2
0
        public virtual uint ReadIntLowEndian()
        {
            var v1 = (byte)ReadByte();
            var v2 = (byte)ReadByte();
            var v3 = (byte)ReadByte();
            var v4 = (byte)ReadByte();

            return(Marshal.ConvertToUInt32(v4, v3, v2, v1));
        }
Esempio n. 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="buf">Buffer containing packet data to read from</param>
        /// <param name="start">Starting index into buf</param>
        /// <param name="size">Number of bytes to read from buf</param>
        public PacketIn(byte[] buf, int start, int size)
            : base(size)
        {
            m_psize    = Marshal.ConvertToUInt32(buf, start) - HDR_SIZE;
            m_id       = Marshal.ConvertToUInt16(buf, start + 4);
            m_checksum = buf[start + 6];

            Position = 0;
            Write(buf, start + 7, size - HDR_SIZE);
            SetLength(size - HDR_SIZE);
            Position = 0;
        }
Esempio n. 4
0
        public uint GetUint()
        {
            if (val is byte[])
            {
                byte[] Data = val as byte[];
                return(Marshal.ConvertToUInt32(Data[3], Data[2], Data[1], Data[0]));
            }
            else if (val is uint)
            {
                return((uint)val);
            }

            return(0);
        }
Esempio n. 5
0
        public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
        {
            byte[] Data   = val as byte[];
            object Result = Data;

            if (Field.Equals(typeof(UInt32)))
            {
                Result = Marshal.ConvertToUInt32(Data[3], Data[2], Data[1], Data[0]);
            }
            else if (Field.Equals(typeof(Int32)))
            {
                Result = BitConverter.ToInt32(Data, 0);
            }
            else if (Field.Equals(typeof(long)))
            {
                Result = (long)BitConverter.ToUInt32(Data, 0);
            }

            Info.SetValue(Packet, Result);
        }