Add Protocol implementation
This commit is contained in:
32
PlantBox.Shared/Communication/CommandPacket.cs
Normal file
32
PlantBox.Shared/Communication/CommandPacket.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PlantBox.Shared.Communication
|
||||
{
|
||||
public class CommandPacket
|
||||
{
|
||||
public Command Command { get; }
|
||||
public ulong ID { get; }
|
||||
public string[] Arguments { get; }
|
||||
|
||||
public CommandPacket(Command command, ulong id, string[] arguments)
|
||||
{
|
||||
Command = command;
|
||||
ID = id;
|
||||
Arguments = arguments ?? Array.Empty<string>();
|
||||
}
|
||||
public CommandPacket(Command command, params string[] arguments)
|
||||
{
|
||||
Command = command;
|
||||
ID = ulong.Parse(arguments[0]);
|
||||
Arguments = arguments != null && arguments.Length > 1 ? arguments.Skip(1).ToArray() : Array.Empty<string>();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Command.ToString().ToUpperInvariant()}\n{ID}{(Arguments.Length > 0 ? $";{string.Join(";", Arguments)}" : string.Empty)}\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user