From faa54aca0ebf536a8fbd2668f7ab4a5ec271f898 Mon Sep 17 00:00:00 2001 From: Eveldee Date: Fri, 22 Mar 2019 19:57:33 +0100 Subject: [PATCH] Add CommandSerializable Used to easily serialize class to CommandPacket --- PlantBox.Shared/Communication/CommandPacket.cs | 3 ++- .../Commands/CommandSerializable.cs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 PlantBox.Shared/Communication/Commands/CommandSerializable.cs diff --git a/PlantBox.Shared/Communication/CommandPacket.cs b/PlantBox.Shared/Communication/CommandPacket.cs index 3b9b9fe..37b8187 100644 --- a/PlantBox.Shared/Communication/CommandPacket.cs +++ b/PlantBox.Shared/Communication/CommandPacket.cs @@ -1,4 +1,5 @@ -using System; +using PlantBox.Shared.Communication.Commands; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/PlantBox.Shared/Communication/Commands/CommandSerializable.cs b/PlantBox.Shared/Communication/Commands/CommandSerializable.cs new file mode 100644 index 0000000..b9002e9 --- /dev/null +++ b/PlantBox.Shared/Communication/Commands/CommandSerializable.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace PlantBox.Shared.Communication.Commands +{ + public abstract class CommandSerializable + { + public abstract string[] Serialize(); + public abstract T Deserialize(string[] arguments); + + public CommandPacket ToCommandPacket(Command command, ulong id) + { + return new CommandPacket(command, id, Serialize()); + } + } +}