From 6b7ee73597515462e5d1c7a4416466f66e539be4 Mon Sep 17 00:00:00 2001 From: Eveldee Date: Sat, 23 Mar 2019 14:10:51 +0100 Subject: [PATCH] Add CommandStream.Receive --- .../Communication/CommandStream.cs | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/PlantBox.Shared/Communication/CommandStream.cs b/PlantBox.Shared/Communication/CommandStream.cs index 92b225f..4124903 100644 --- a/PlantBox.Shared/Communication/CommandStream.cs +++ b/PlantBox.Shared/Communication/CommandStream.cs @@ -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(';')); } + /// + /// Read a from the stream and deserialize data to a + /// + /// A valid + /// + public (CommandPacket, T) Receive() where T : CommandSerializable, new() + { + var packet = Receive(); + + return (packet, new T().Deserialize(packet.Arguments)); + } + /// /// Read a from the stream asynchronously /// @@ -74,6 +87,18 @@ namespace PlantBox.Shared.Communication return new CommandPacket(command, packet[1].Split(';')); } + /// + /// Read a from the stream and deserialize data to a asynchronously + /// + /// A valid + /// + public async Task<(CommandPacket, T)> ReceiveAsync() where T : CommandSerializable, new() + { + var packet = await ReceiveAsync(); + + return (packet, new T().Deserialize(packet.Arguments)); + } + /// /// Write a in the stream ///