From 88d5a5e9d8d80eac0e999b54d42506eae364e125 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 5 Mar 2020 13:13:40 +0100 Subject: [PATCH] Allow deserializing to existing objects --- src/common/communication.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/common/communication.h b/src/common/communication.h index c51bf4c4..7244c578 100644 --- a/src/common/communication.h +++ b/src/common/communication.h @@ -136,17 +136,20 @@ inline void write_object(Socket& socket, const T& object) { * together with `write_object`. This will block until the object is available. * * @param socket The Boost.Asio socket to read from. + * @param object The object to deserialize to, if given. This can be used to + * update an existing `AEffect` struct without losing the pointers set by the + * host and the bridge. + * * @throw std::runtime_error If the conversion to an object was not successful. * * @relates write_object */ template -inline T read_object(Socket& socket) { +inline T read_object(Socket& socket, T object = T()) { // TODO: Reuse buffers Buffer buffer; auto message_length = socket.receive(boost::asio::buffer(buffer)); - T object; auto [_, success] = bitsery::quickDeserialization>( {buffer.begin(), message_length}, object);