예제 #1
0
        public static Tran_Head GetDataHead(byte[] data)
        {
            Tran_Head head = new Tran_Head();

            byte[] rcv_head = new byte[Marshal.SizeOf(head)];
            Array.ConstrainedCopy(data, 0, rcv_head, 0, Marshal.SizeOf(head));
            head = (Tran_Head)CStructBytesFormat.BytesToStruct <Tran_Head>(rcv_head);

            return(head);
        }
예제 #2
0
        public static byte[] BuildBytes <T>(Tran_Head hd, T obj)
        {
            byte[] head = CStructBytesFormat.StructToBytes(hd);
            byte[] data = CStructBytesFormat.StructToBytes(obj);

            byte[] rbyte = new byte[data.Length + head.Length];

            Array.ConstrainedCopy(head, 0, rbyte, 0, head.Length);
            Array.ConstrainedCopy(data, 0, rbyte, head.Length, data.Length);

            return(rbyte);
        }
예제 #3
0
        public static T GetDataObj <T>(byte[] data, Tran_Head head)
        {
            if (data == null)
            {
                return(default(T));
            }
            if (data.Length <= 0)
            {
                return(default(T));
            }
            int objLength = Marshal.SizeOf(typeof(T));

            byte[] rcv_data = new byte[head.length];
            T      obj;

            Array.ConstrainedCopy(data, Marshal.SizeOf(head), rcv_data, 0, rcv_data.Length);
            obj = (T)CStructBytesFormat.BytesToStruct <T>(rcv_data);

            return(obj);
        }