Add CommandStream.Receive<T>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using PlantBox.Shared.Communication.Commands;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -48,6 +49,18 @@ namespace PlantBox.Shared.Communication
|
|||||||
return new CommandPacket(command, packet[1].Split(';'));
|
return new CommandPacket(command, packet[1].Split(';'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Read a <see cref="CommandPacket"/> from the stream and deserialize data to a <see cref="CommandSerializable{T}"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">A valid <see cref="CommandSerializable{T}"/></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public (CommandPacket, T) Receive<T>() where T : CommandSerializable<T>, new()
|
||||||
|
{
|
||||||
|
var packet = Receive();
|
||||||
|
|
||||||
|
return (packet, new T().Deserialize(packet.Arguments));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read a <see cref="CommandPacket"/> from the stream asynchronously
|
/// Read a <see cref="CommandPacket"/> from the stream asynchronously
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -74,6 +87,18 @@ namespace PlantBox.Shared.Communication
|
|||||||
return new CommandPacket(command, packet[1].Split(';'));
|
return new CommandPacket(command, packet[1].Split(';'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Read a <see cref="CommandPacket"/> from the stream and deserialize data to a <see cref="CommandSerializable{T}"/> asynchronously
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">A valid <see cref="CommandSerializable{T}"/></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<(CommandPacket, T)> ReceiveAsync<T>() where T : CommandSerializable<T>, new()
|
||||||
|
{
|
||||||
|
var packet = await ReceiveAsync();
|
||||||
|
|
||||||
|
return (packet, new T().Deserialize(packet.Arguments));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write a <see cref="CommandPacket"/> in the stream
|
/// Write a <see cref="CommandPacket"/> in the stream
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user