|
|
@ -73,7 +73,20 @@ namespace PixelHub |
|
|
|
public byte[] Header |
|
|
|
{ |
|
|
|
get { |
|
|
|
byte[] result = new byte[HeaderSize]; |
|
|
|
// Fetch all the components needed to build the message header and convert them to byte arrays
|
|
|
|
byte[] rawProtocolVersion = BitConverter.GetBytes(ProtocolVersion); |
|
|
|
byte[] rawMessageType = BitConverter.GetBytes((ushort)MessageType); |
|
|
|
byte[] rawMessageId = BitConverter.GetBytes((ushort)MessageId); |
|
|
|
byte[] rawMessageLength = BitConverter.GetBytes(Payload.Length); |
|
|
|
|
|
|
|
// Copy the pieces into the correct places
|
|
|
|
Buffer.BlockCopy(rawProtocolVersion, 0, result, 0, rawProtocolVersion.Length); |
|
|
|
Buffer.BlockCopy(rawMessageType, 0, result, 2, rawProtocolVersion.Length); |
|
|
|
Buffer.BlockCopy(rawMessageId, 0, result, 4, rawProtocolVersion.Length); |
|
|
|
Buffer.BlockCopy(rawMessageLength, 0, result, 8, rawProtocolVersion.Length); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -89,9 +102,16 @@ namespace PixelHub |
|
|
|
MessageId = BitConverter.ToUInt32(rawMessageId, 0); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns this message in it's raw format that's sent and received over the wire.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>This message, as a byte array.</returns>
|
|
|
|
public byte[] AsCompiledCommand() |
|
|
|
{ |
|
|
|
byte[] message = new byte[HeaderSize + Payload.Length]; |
|
|
|
Buffer.BlockCopy(Header, 0, message, 0, HeaderSize); |
|
|
|
Buffer.BlockCopy(Payload, 0, message, HeaderSize, Payload.Length); |
|
|
|
return message; |
|
|
|
} |
|
|
|
} |
|
|
|
} |