예제 #1
0
        public Message(int size, byte[] buf, int type)
        {
            if (buf != null)
            {
                data_ = new byte[size + MSGHEADER.SIZE];
                hdr   = new MSGHEADER((uint)buf.Length, (uint)type);

                Buffer.BlockCopy(hdr.ToNetworkByteOrder(), 0, data_, 0, MSGHEADER.SIZE);
                Buffer.BlockCopy(buf, 0, data_, MSGHEADER.SIZE, buf.Length);
            }
        }
예제 #2
0
 public Message(byte[] data, int type)
 {
     data_ = data;
     if (data_ != null)
     {
         hdr = new MSGHEADER((uint)data.Length, (uint)type);
     }
     else
     {
         hdr = new MSGHEADER(0, (uint)type);
     }
 }
예제 #3
0
        public static byte[] SerializeHeader(MSGHEADER hdr, bool write_to_network_socket)
        {
            byte[] bytes = BitConverter.GetBytes(hdr.data);
            // https://docs.microsoft.com/en-us/dotnet/api/system.bitconverter?view=netcore-3.1
            // if the source architecture is liitle endian, and the destination is a network
            // socket, then need to serialize the header in big endian order prior to writing
            // into the socket
            if (BitConverter.IsLittleEndian && write_to_network_socket)
            {
                Array.Reverse(bytes);
            }

            return(bytes);
        }
예제 #4
0
 public Message(int type)
 {
     hdr   = new MSGHEADER(0, (uint)type);
     data_ = null;
 }
예제 #5
0
 public Message(MSGHEADER mhdr, byte[] data)
 {
     hdr   = mhdr;
     data_ = data;
 }
예제 #6
0
 public Message(MSGHEADER mhdr)
 {
     hdr   = mhdr;
     data_ = new byte[mhdr.Len()];
 }