mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
Fix deserializing into existing objects
`read_object()` was trying to create copies.
This commit is contained in:
@@ -104,7 +104,7 @@ inline void write_object(Socket& socket, const T& object) {
|
|||||||
* @relates write_object
|
* @relates write_object
|
||||||
*/
|
*/
|
||||||
template <typename T, typename Socket>
|
template <typename T, typename Socket>
|
||||||
inline T read_object(Socket& socket, std::vector<uint8_t>& buffer, T& object) {
|
inline T& read_object(Socket& socket, std::vector<uint8_t>& buffer, T& object) {
|
||||||
// See the note above on the use of `uint64_t` instead of `size_t`
|
// See the note above on the use of `uint64_t` instead of `size_t`
|
||||||
std::array<uint64_t, 1> message_length;
|
std::array<uint64_t, 1> message_length;
|
||||||
boost::asio::read(socket, boost::asio::buffer(message_length));
|
boost::asio::read(socket, boost::asio::buffer(message_length));
|
||||||
@@ -141,7 +141,9 @@ inline T read_object(Socket& socket, std::vector<uint8_t>& buffer, T& object) {
|
|||||||
template <typename T, typename Socket>
|
template <typename T, typename Socket>
|
||||||
inline T read_object(Socket& socket, std::vector<uint8_t>& buffer) {
|
inline T read_object(Socket& socket, std::vector<uint8_t>& buffer) {
|
||||||
T object;
|
T object;
|
||||||
return read_object<T>(socket, buffer, object);
|
read_object<T>(socket, buffer, object);
|
||||||
|
|
||||||
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -151,7 +153,7 @@ inline T read_object(Socket& socket, std::vector<uint8_t>& buffer) {
|
|||||||
* @overload
|
* @overload
|
||||||
*/
|
*/
|
||||||
template <typename T, typename Socket>
|
template <typename T, typename Socket>
|
||||||
inline T read_object(Socket& socket, T& object) {
|
inline T& read_object(Socket& socket, T& object) {
|
||||||
std::vector<uint8_t> buffer(64);
|
std::vector<uint8_t> buffer(64);
|
||||||
return read_object<T>(socket, buffer, object);
|
return read_object<T>(socket, buffer, object);
|
||||||
}
|
}
|
||||||
@@ -166,7 +168,9 @@ template <typename T, typename Socket>
|
|||||||
inline T read_object(Socket& socket) {
|
inline T read_object(Socket& socket) {
|
||||||
T object;
|
T object;
|
||||||
std::vector<uint8_t> buffer(64);
|
std::vector<uint8_t> buffer(64);
|
||||||
return read_object<T>(socket, buffer, object);
|
read_object<T>(socket, buffer, object);
|
||||||
|
|
||||||
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ class Vst3MessageHandler : public AdHocSocketHandler<Thread> {
|
|||||||
* another thread, then this will create a new socket connection and send
|
* another thread, then this will create a new socket connection and send
|
||||||
* the event there instead.
|
* the event there instead.
|
||||||
*
|
*
|
||||||
|
* @param object The request object to send. Often a marker struct to ask
|
||||||
|
* for a specific object to be returned.
|
||||||
* @param logging A pair containing a logger instance and whether or not
|
* @param logging A pair containing a logger instance and whether or not
|
||||||
* this is for sending host -> plugin control messages. If set to false,
|
* this is for sending host -> plugin control messages. If set to false,
|
||||||
* then this indicates that this `Vst3MessageHandler` is handling plugin
|
* then this indicates that this `Vst3MessageHandler` is handling plugin
|
||||||
@@ -94,11 +96,16 @@ class Vst3MessageHandler : public AdHocSocketHandler<Thread> {
|
|||||||
* an existing object.
|
* an existing object.
|
||||||
*
|
*
|
||||||
* TODO: We might also need overloads that reuse buffers
|
* TODO: We might also need overloads that reuse buffers
|
||||||
|
* TODO: Rename to `receive_into()` to make it more apparent what's
|
||||||
|
* happening
|
||||||
|
*
|
||||||
|
* @param response_object The object to deserialize into.
|
||||||
*
|
*
|
||||||
* @overload
|
* @overload
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void send_message(const T& object,
|
typename T::Response& send_message(
|
||||||
|
const T& object,
|
||||||
typename T::Response& response_object,
|
typename T::Response& response_object,
|
||||||
std::optional<std::pair<Vst3Logger&, bool>> logging) {
|
std::optional<std::pair<Vst3Logger&, bool>> logging) {
|
||||||
using TResponse = typename T::Response;
|
using TResponse = typename T::Response;
|
||||||
@@ -126,6 +133,8 @@ class Vst3MessageHandler : public AdHocSocketHandler<Thread> {
|
|||||||
auto [logger, is_host_vst] = *logging;
|
auto [logger, is_host_vst] = *logging;
|
||||||
logger.log_response(!is_host_vst, response_object);
|
logger.log_response(!is_host_vst, response_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return response_object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user