public byte[] ToByte() { byte[] result = new byte[MessageHeaderSize]; int offset = 0; offset = ByteHandler.ToBytes(result, offset, uMagicNumber); offset = ByteHandler.ToBytes(result, offset, uVersion); offset = ByteHandler.ToBytes(result, offset, uMessageSize); return(result); }
public MessageHeader(byte[] data) { if (data.Length != MessageHeaderSize) { throw new ApplicationException("INTERNAL ERROR - MessageHeader constructor passed buffer of invalid length"); } int offset = 0; offset = ByteHandler.FromBytes(data, offset, out uMagicNumber); offset = ByteHandler.FromBytes(data, offset, out uVersion); offset = ByteHandler.FromBytes(data, offset, out uMessageSize); if (offset != 12) { throw new ApplicationException("FATAL INTERNAL ERROR - MessageHeader is not 12 bytes long"); } if (uMagicNumber != ConstantForMagicNumber) { throw new ApplicationException("FATAL COMMUNICATIONS ERROR - MessageHeader Magic number is invalid"); } }