Example #1
0
 private bool Validation(PacketSize p)
 {
     if (p.Header[0] == 0x01 &&
         p.Header[1] == 0x02 &&
         p.Header[2] == 0x03 &&
         p.Header[3] == 0x04)
     {
         return(true);
     }
     return(false);
 }
Example #2
0
        public static PacketSize Create(int size)
        {
            PacketSize ret = new PacketSize();

            ret.Header[0] = 0x01;
            ret.Header[1] = 0x02;
            ret.Header[2] = 0x03;
            ret.Header[3] = 0x04;

            ret.Size = size;
            return(ret);
        }
Example #3
0
        public static PacketSize FromBytes(byte[] data)
        {
            PacketSize ret = new PacketSize();

            if (data.Length != 8)
            {
                return(null);
            }
            for (int i = 0; i < ret.Header.Length; i++)
            {
                ret.Header[i] = data[i];
            }
            if (ret.Validation(ret) == false)
            {
                return(null);
            }


            ret.Size = BitConverter.ToInt32(data, 4);

            return(ret);
        }