using System;
namespace Dashboard.Drawing
{
public interface IDrawCommand
{
///
/// Name of the command.
///
string Name { get; }
///
/// The draw extension that defines this command.
///
IDrawExtension Extension { get; }
///
/// The length of the command data segment, in bytes.
///
///
/// Must be 0 for simple commands. For commands that are variadic, the
/// value must be less than 0. Any other positive value, otherwise.
///
int Length { get; }
///
/// Get the parameters object for this command.
///
/// The parameter array.
/// The parameters object.
object? GetParams(DrawQueue queue, ReadOnlySpan param);
}
public interface IDrawCommand : IDrawCommand
{
///
/// Get the parameters object for this command.
///
/// The parameter array.
/// The parameters object.
new T? GetParams(DrawQueue queue, ReadOnlySpan param);
}
public sealed class DrawCommand : IDrawCommand
{
public string Name { get; }
public IDrawExtension Extension { get; }
public int Length { get; } = 0;
public DrawCommand(string name, IDrawExtension extension)
{
Name = name;
Extension = extension;
}
public object? GetParams(DrawQueue queue, ReadOnlySpan param)
{
return null;
}
}
public sealed class DrawCommand : IDrawCommand
where T : IParameterSerializer, new()
{
public string Name { get; }
public IDrawExtension Extension { get; }
public int Length { get; }
public DrawCommand(string name, IDrawExtension extension, int length)
{
Name = name;
Extension = extension;
Length = length;
}
public T? GetParams(DrawQueue queue, ReadOnlySpan param)
{
T t = new T();
t.Deserialize(queue, param);
return t;
}
object? IDrawCommand.GetParams(DrawQueue queue, ReadOnlySpan param)
{
return GetParams(queue, param);
}
}
}