update to contact4
This commit is contained in:
parent
491c30988e
commit
c284e0779e
@ -1,5 +1,7 @@
|
|||||||
#include "./message_serializer.hpp"
|
#include "./message_serializer.hpp"
|
||||||
|
|
||||||
|
#include <solanaceae/contact/contact_store_impl.hpp>
|
||||||
|
|
||||||
#include <solanaceae/message3/components.hpp>
|
#include <solanaceae/message3/components.hpp>
|
||||||
#include <solanaceae/contact/components.hpp>
|
#include <solanaceae/contact/components.hpp>
|
||||||
#include <solanaceae/object_store/meta_components.hpp>
|
#include <solanaceae/object_store/meta_components.hpp>
|
||||||
@ -8,18 +10,9 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
static Contact3 findContactByID(Contact3Registry& cr, const std::vector<uint8_t>& id) {
|
nlohmann::json MessageSerializerNJ::serlContactByID(Contact4 c) const {
|
||||||
// TODO: id lookup table, this is very inefficent
|
const auto& cr = cs.registry();
|
||||||
for (const auto& [c_it, id_it] : cr.view<Contact::Components::ID>().each()) {
|
|
||||||
if (id == id_it.data) {
|
|
||||||
return c_it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return entt::null;
|
|
||||||
}
|
|
||||||
|
|
||||||
nlohmann::json MessageSerializerNJ::serlContactByID(Contact3 c) const {
|
|
||||||
if (!cr.valid(c)) {
|
if (!cr.valid(c)) {
|
||||||
// while this is invalid registry state, it is valid serialization
|
// while this is invalid registry state, it is valid serialization
|
||||||
std::cerr << "MSC warning: encountered invalid contact\n";
|
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<Contact::Components::ID>(c).data);
|
return nlohmann::json::binary(cr.get<Contact::Components::ID>(c).data);
|
||||||
}
|
}
|
||||||
|
|
||||||
Contact3 MessageSerializerNJ::deserlContactByID(const nlohmann::json& j) {
|
Contact4 MessageSerializerNJ::deserlContactByID(const nlohmann::json& j) {
|
||||||
std::vector<uint8_t> id;
|
std::vector<uint8_t> id;
|
||||||
if (j.is_binary()) {
|
if (j.is_binary()) {
|
||||||
id = j.get_binary();
|
id = j.get_binary();
|
||||||
@ -43,11 +36,13 @@ Contact3 MessageSerializerNJ::deserlContactByID(const nlohmann::json& j) {
|
|||||||
j.at("bytes").get_to(id);
|
j.at("bytes").get_to(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Contact3 other_c = findContactByID(cr, id);
|
auto other_c = cs.getOneContactByID(ByteSpan{id});
|
||||||
if (!cr.valid(other_c)) {
|
if (!other_c) {
|
||||||
|
auto& cr = cs.registry();
|
||||||
// create sparse contact with id only
|
// create sparse contact with id only
|
||||||
other_c = cr.create();
|
other_c = {cr, cr.create()};
|
||||||
cr.emplace_or_replace<Contact::Components::ID>(other_c, id);
|
cr.emplace_or_replace<Contact::Components::ID>(other_c, id);
|
||||||
|
cs.throwEventConstruct(other_c);
|
||||||
}
|
}
|
||||||
|
|
||||||
return other_c;
|
return other_c;
|
||||||
@ -86,7 +81,7 @@ ObjectHandle MessageSerializerNJ::deserlFileObjByID(const nlohmann::json& j) {
|
|||||||
|
|
||||||
template<>
|
template<>
|
||||||
bool MessageSerializerNJ::component_get_json<Message::Components::ContactFrom>(MessageSerializerNJ& msc, const Handle h, nlohmann::json& j) {
|
bool MessageSerializerNJ::component_get_json<Message::Components::ContactFrom>(MessageSerializerNJ& msc, const Handle h, nlohmann::json& j) {
|
||||||
const Contact3 c = h.get<Message::Components::ContactFrom>().c;
|
const Contact4 c = h.get<Message::Components::ContactFrom>().c;
|
||||||
j = msc.serlContactByID(c);
|
j = msc.serlContactByID(c);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -108,7 +103,7 @@ bool MessageSerializerNJ::component_emplace_or_replace_json<Message::Components:
|
|||||||
|
|
||||||
template<>
|
template<>
|
||||||
bool MessageSerializerNJ::component_get_json<Message::Components::ContactTo>(MessageSerializerNJ& msc, const Handle h, nlohmann::json& j) {
|
bool MessageSerializerNJ::component_get_json<Message::Components::ContactTo>(MessageSerializerNJ& msc, const Handle h, nlohmann::json& j) {
|
||||||
const Contact3 c = h.get<Message::Components::ContactTo>().c;
|
const Contact4 c = h.get<Message::Components::ContactTo>().c;
|
||||||
j = msc.serlContactByID(c);
|
j = msc.serlContactByID(c);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -137,8 +132,10 @@ bool MessageSerializerNJ::component_get_json<Message::Components::ReceivedBy>(Me
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto& cr = msc.cs.registry();
|
||||||
|
|
||||||
for (const auto& [c, v] : comp.ts) {
|
for (const auto& [c, v] : comp.ts) {
|
||||||
if (!msc.cr.valid(c) || !msc.cr.all_of<Contact::Components::ID>(c)) {
|
if (!cr.valid(c) || !cr.all_of<Contact::Components::ID>(c)) {
|
||||||
// while this is invalid registry state, it is valid serialization
|
// while this is invalid registry state, it is valid serialization
|
||||||
// we just skip this contact entirely and drop the time
|
// we just skip this contact entirely and drop the time
|
||||||
std::cerr << "MSC warning: encountered invalid contact / contact without ID\n";
|
std::cerr << "MSC warning: encountered invalid contact / contact without ID\n";
|
||||||
|
@ -12,9 +12,9 @@ struct MessageSerializerNJ {
|
|||||||
using Registry = Message3Registry;
|
using Registry = Message3Registry;
|
||||||
using Handle = Message3Handle;
|
using Handle = Message3Handle;
|
||||||
|
|
||||||
static constexpr const char* version {"2"};
|
static constexpr const char* version {"3"};
|
||||||
|
|
||||||
Contact3Registry& cr;
|
ContactStore4I& cs;
|
||||||
ObjectStore2& os;
|
ObjectStore2& os;
|
||||||
|
|
||||||
// nlohmann
|
// nlohmann
|
||||||
@ -76,8 +76,8 @@ struct MessageSerializerNJ {
|
|||||||
|
|
||||||
|
|
||||||
// helper
|
// helper
|
||||||
nlohmann::json serlContactByID(Contact3 c) const;
|
nlohmann::json serlContactByID(Contact4 c) const;
|
||||||
Contact3 deserlContactByID(const nlohmann::json& j);
|
Contact4 deserlContactByID(const nlohmann::json& j);
|
||||||
nlohmann::json serlFileObjByID(ObjectHandle o) const;
|
nlohmann::json serlFileObjByID(ObjectHandle o) const;
|
||||||
ObjectHandle deserlFileObjByID(const nlohmann::json& j);
|
ObjectHandle deserlFileObjByID(const nlohmann::json& j);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user