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); } }
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); } }
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); }
public Message(int type) { hdr = new MSGHEADER(0, (uint)type); data_ = null; }
public Message(MSGHEADER mhdr, byte[] data) { hdr = mhdr; data_ = data; }
public Message(MSGHEADER mhdr) { hdr = mhdr; data_ = new byte[mhdr.Len()]; }