Files
PlantBox/PlantBox.Shared/Communication/Commands/CommandSerializable.cs
2019-03-23 11:37:52 +01:00

39 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
namespace PlantBox.Shared.Communication.Commands
{
/// <summary>
/// A class serializable to a <see cref="CommandPacket"/>
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class CommandSerializable<T>
{
/// <summary>
/// Serialize all the values in a string <see cref="Array"/>,
/// should contains everything to deserialize
/// </summary>
/// <returns>Valid arguments for a <see cref="CommandPacket"/></returns>
public abstract string[] Serialize();
/// <summary>
/// Create an instance of the class from a string <see cref="Array"/>
/// </summary>
/// <param name="arguments">Arguments from the <see cref="CommandSerializable{T}.Serialize"/> method</param>
/// <returns><see cref="T"/> initilized accordingly</returns>
public abstract T Deserialize(string[] arguments);
/// <summary>
/// Convert a <see cref="CommandSerializable{T}"/> to a <see cref="CommandPacket"/>
/// </summary>
/// <param name="command">Command type</param>
/// <param name="id">A valid id</param>
/// <returns></returns>
public CommandPacket ToCommandPacket(Command command, ulong id)
{
return new CommandPacket(command, id, Serialize());
}
}
}