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.Net.Sockets;
|
||||
using System.Text;
|
||||
@@ -48,6 +49,18 @@ namespace PlantBox.Shared.Communication
|
||||
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>
|
||||
/// Read a <see cref="CommandPacket"/> from the stream asynchronously
|
||||
/// </summary>
|
||||
@@ -74,6 +87,18 @@ namespace PlantBox.Shared.Communication
|
||||
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>
|
||||
/// Write a <see cref="CommandPacket"/> in the stream
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user