From 203f03a597a5749cf77c24f69479022a6e8a2cac Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 22 Apr 2024 23:25:19 +0200 Subject: [PATCH] Add `Write`/`Read` methods to `NetworkStream` for `INetworkSerializable` sending in C# api --- Source/Engine/Networking/NetworkStream.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Networking/NetworkStream.cs b/Source/Engine/Networking/NetworkStream.cs index 02fb5eab8..bf8b9b269 100644 --- a/Source/Engine/Networking/NetworkStream.cs +++ b/Source/Engine/Networking/NetworkStream.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. +// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. using System; using System.Text; @@ -441,5 +441,23 @@ namespace FlaxEngine.Networking ReadBytes((byte*)&value, sizeof(bool)); return value; } + + /// + /// Writes the object data to the stream. Object has to be allocated. + /// + /// The serializable object. + public void Write(INetworkSerializable obj) + { + obj.Serialize(this); + } + + /// + /// Reads the object data from the stream. Object has to be allocated. + /// + /// The serializable object. + public void Read(INetworkSerializable obj) + { + obj.Deserialize(this); + } } }