[server] Finish filling in PixelCommand.AsCompiledCommand()

This commit is contained in:
Starbeamrainbowlabs 2017-03-04 12:08:36 +00:00
parent d2b32f3f09
commit 0c669012b6
2 changed files with 21 additions and 0 deletions

View File

@ -73,7 +73,20 @@ namespace PixelHub
public byte[] Header public byte[] Header
{ {
get { 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); 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() public byte[] AsCompiledCommand()
{ {
byte[] message = new byte[HeaderSize + Payload.Length]; byte[] message = new byte[HeaderSize + Payload.Length];
Buffer.BlockCopy(Header, 0, message, 0, HeaderSize);
Buffer.BlockCopy(Payload, 0, message, HeaderSize, Payload.Length);
return message;
} }
} }
} }

View File

@ -44,6 +44,7 @@
<Compile Include="PixelBot.cs" /> <Compile Include="PixelBot.cs" />
<Compile Include="NetTools.cs" /> <Compile Include="NetTools.cs" />
<Compile Include="PixelCommands\ResetCommand.cs" /> <Compile Include="PixelCommands\ResetCommand.cs" />
<Compile Include="PixelCommands\HandshakeRequestCommand.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>