From 9b1ace03ece2d857f095ddf6abbbe7c7c3034a57 Mon Sep 17 00:00:00 2001 From: Andrei Drozdov Date: Sun, 21 Apr 2024 18:52:11 +0200 Subject: [PATCH] Simplified scalar data recv --- .../async_replicated_container.h | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/examples/async_replication/async_replicated_container.h b/examples/async_replication/async_replicated_container.h index 0cb88878..afc2af0e 100644 --- a/examples/async_replication/async_replicated_container.h +++ b/examples/async_replication/async_replicated_container.h @@ -169,52 +169,47 @@ class AsyncReplicatedContainer { Relay recv_relay(const std::unique_ptr& c) { // Get buffer length - std::vector len_buf(sizeof(size_t)); - auto size = c->BlockingRead(&len_buf[0], sizeof(size_t)); + size_t buffer_len; + auto size = c->BlockingRead(reinterpret_cast(&buffer_len), sizeof(size_t)); if (!size) throw; - size_t* buffer_len = reinterpret_cast(len_buf.data()); - *buffer_len = be64toh(*buffer_len); + buffer_len = be64toh(buffer_len); // Get the key - std::vector key_buf(*buffer_len); - size = c->BlockingRead(&key_buf[0], *buffer_len); + std::vector key_buf(buffer_len); + size = c->BlockingRead(&key_buf[0], buffer_len); if (!size) throw; std::string key(key_buf.begin(), key_buf.end()); // Get the value - std::vector val_buf(sizeof(uint32_t)); - size = c->BlockingRead(&val_buf[0], sizeof(uint32_t)); + uint32_t value; + size = c->BlockingRead(reinterpret_cast(&value), sizeof(value)); if (!size) throw; - uint32_t* value = reinterpret_cast(val_buf.data()); - *value = ntohl(*value); + value = ntohl(value); // Get replica_id length - std::vector repl_buf(sizeof(size_t)); - size = c->BlockingRead(&repl_buf[0], sizeof(size_t)); + size_t repl_len; + size = c->BlockingRead(reinterpret_cast(&repl_len), sizeof(repl_len)); if (!size) throw; - size_t* repl_len = reinterpret_cast(repl_buf.data()); - *repl_len = be64toh(*repl_len); + repl_len = be64toh(repl_len); // Get the replica id - std::vector repl_id_buf(*repl_len); - size = c->BlockingRead(&repl_id_buf[0], *repl_len); + std::vector repl_id_buf(repl_len); + size = c->BlockingRead(&repl_id_buf[0], repl_len); if (!size) throw; std::string replica_id(repl_id_buf.begin(), repl_id_buf.end()); // Get the clock - std::vector clock_buf(sizeof(uint64_t)); - size = c->BlockingRead(&clock_buf[0], sizeof(uint64_t)); + uint64_t clock_int; + size = c->BlockingRead(reinterpret_cast(&clock_int), sizeof(clock_int)); if (!size) throw; - uint64_t* clock_int = reinterpret_cast(clock_buf.data()); - *clock_int = be64toh(*clock_int); - std::chrono::microseconds clock(*clock_int); + clock_int = be64toh(clock_int); // Prepare the relay object Relay result; result.key = key; - result.value = *value; + result.value = value; result.replica_id = replica_id; - result.clock = clock; + result.clock = std::chrono::microseconds(clock_int); return result; }