From c284e0779e69618f0524acba67849801cbb5a5d7 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Thu, 6 Mar 2025 16:20:30 +0100 Subject: [PATCH] update to contact4 --- .../message3/message_serializer.cpp | 33 +++++++++---------- .../message3/message_serializer.hpp | 8 ++--- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/solanaceae/message3/message_serializer.cpp b/src/solanaceae/message3/message_serializer.cpp index e2a7d89..bf0c045 100644 --- a/src/solanaceae/message3/message_serializer.cpp +++ b/src/solanaceae/message3/message_serializer.cpp @@ -1,5 +1,7 @@ #include "./message_serializer.hpp" +#include + #include #include #include @@ -8,18 +10,9 @@ #include -static Contact3 findContactByID(Contact3Registry& cr, const std::vector& id) { - // TODO: id lookup table, this is very inefficent - for (const auto& [c_it, id_it] : cr.view().each()) { - if (id == id_it.data) { - return c_it; - } - } +nlohmann::json MessageSerializerNJ::serlContactByID(Contact4 c) const { + const auto& cr = cs.registry(); - return entt::null; -} - -nlohmann::json MessageSerializerNJ::serlContactByID(Contact3 c) const { if (!cr.valid(c)) { // while this is invalid registry state, it is valid serialization std::cerr << "MSC warning: encountered invalid contact\n"; @@ -35,7 +28,7 @@ nlohmann::json MessageSerializerNJ::serlContactByID(Contact3 c) const { return nlohmann::json::binary(cr.get(c).data); } -Contact3 MessageSerializerNJ::deserlContactByID(const nlohmann::json& j) { +Contact4 MessageSerializerNJ::deserlContactByID(const nlohmann::json& j) { std::vector id; if (j.is_binary()) { id = j.get_binary(); @@ -43,11 +36,13 @@ Contact3 MessageSerializerNJ::deserlContactByID(const nlohmann::json& j) { j.at("bytes").get_to(id); } - Contact3 other_c = findContactByID(cr, id); - if (!cr.valid(other_c)) { + auto other_c = cs.getOneContactByID(ByteSpan{id}); + if (!other_c) { + auto& cr = cs.registry(); // create sparse contact with id only - other_c = cr.create(); + other_c = {cr, cr.create()}; cr.emplace_or_replace(other_c, id); + cs.throwEventConstruct(other_c); } return other_c; @@ -86,7 +81,7 @@ ObjectHandle MessageSerializerNJ::deserlFileObjByID(const nlohmann::json& j) { template<> bool MessageSerializerNJ::component_get_json(MessageSerializerNJ& msc, const Handle h, nlohmann::json& j) { - const Contact3 c = h.get().c; + const Contact4 c = h.get().c; j = msc.serlContactByID(c); return true; @@ -108,7 +103,7 @@ bool MessageSerializerNJ::component_emplace_or_replace_json bool MessageSerializerNJ::component_get_json(MessageSerializerNJ& msc, const Handle h, nlohmann::json& j) { - const Contact3 c = h.get().c; + const Contact4 c = h.get().c; j = msc.serlContactByID(c); return true; @@ -137,8 +132,10 @@ bool MessageSerializerNJ::component_get_json(Me return true; } + const auto& cr = msc.cs.registry(); + for (const auto& [c, v] : comp.ts) { - if (!msc.cr.valid(c) || !msc.cr.all_of(c)) { + if (!cr.valid(c) || !cr.all_of(c)) { // while this is invalid registry state, it is valid serialization // we just skip this contact entirely and drop the time std::cerr << "MSC warning: encountered invalid contact / contact without ID\n"; diff --git a/src/solanaceae/message3/message_serializer.hpp b/src/solanaceae/message3/message_serializer.hpp index 1a79553..938e5cc 100644 --- a/src/solanaceae/message3/message_serializer.hpp +++ b/src/solanaceae/message3/message_serializer.hpp @@ -12,9 +12,9 @@ struct MessageSerializerNJ { using Registry = Message3Registry; using Handle = Message3Handle; - static constexpr const char* version {"2"}; + static constexpr const char* version {"3"}; - Contact3Registry& cr; + ContactStore4I& cs; ObjectStore2& os; // nlohmann @@ -76,8 +76,8 @@ struct MessageSerializerNJ { // helper - nlohmann::json serlContactByID(Contact3 c) const; - Contact3 deserlContactByID(const nlohmann::json& j); + nlohmann::json serlContactByID(Contact4 c) const; + Contact4 deserlContactByID(const nlohmann::json& j); nlohmann::json serlFileObjByID(ObjectHandle o) const; ObjectHandle deserlFileObjByID(const nlohmann::json& j); };