add message file object
This commit is contained in:
parent
e574c4f779
commit
5d8aa8aef9
@ -2,6 +2,7 @@
|
||||
|
||||
#include <solanaceae/message3/components.hpp>
|
||||
#include <solanaceae/contact/components.hpp>
|
||||
#include <solanaceae/object_store/meta_components.hpp>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@ -52,6 +53,37 @@ Contact3 MessageSerializerNJ::deserlContactByID(const nlohmann::json& j) {
|
||||
return other_c;
|
||||
}
|
||||
|
||||
nlohmann::json MessageSerializerNJ::serlFileObjByID(ObjectHandle o) const {
|
||||
if (!o) {
|
||||
std::cerr << "MSC warning: encountered invalid file object\n";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto* id_comp = o.try_get<ObjComp::ID>();
|
||||
if (id_comp == nullptr || id_comp->v.empty()) {
|
||||
std::cerr << "MSC warning: encountered file object without ID\n";
|
||||
return nullptr; // throw instead??
|
||||
}
|
||||
|
||||
return nlohmann::json::binary(id_comp->v);
|
||||
}
|
||||
|
||||
ObjectHandle MessageSerializerNJ::deserlFileObjByID(const nlohmann::json& j) {
|
||||
std::vector<uint8_t> id;
|
||||
if (j.is_binary()) {
|
||||
id = j.get_binary();
|
||||
} else {
|
||||
j["bytes"].get_to(id);
|
||||
}
|
||||
|
||||
auto o = os.getOneObjectByID(ByteSpan{id});
|
||||
if (!o) {
|
||||
// TODO: create empty objet with id, others need to merge if it exist? special tag to prevent arb merging??
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
template<>
|
||||
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;
|
||||
@ -154,3 +186,20 @@ bool MessageSerializerNJ::component_emplace_or_replace_json<Message::Components:
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool MessageSerializerNJ::component_get_json<Message::Components::MessageFileObject>(MessageSerializerNJ& msc, const Handle h, nlohmann::json& j) {
|
||||
const auto& comp = h.get<Message::Components::MessageFileObject>();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool MessageSerializerNJ::component_emplace_or_replace_json<Message::Components::MessageFileObject>(MessageSerializerNJ& msc, Handle h, const nlohmann::json& j) {
|
||||
if (j.is_null()) {
|
||||
std::cerr << "MSC warning: encountered null MessageFileObject\n";
|
||||
h.emplace_or_replace<Message::Components::MessageFileObject>();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <entt/container/dense_map.hpp>
|
||||
|
||||
#include <solanaceae/message3/registry_message_model.hpp>
|
||||
#include <solanaceae/object_store/object_store.hpp>
|
||||
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
|
||||
@ -14,6 +15,7 @@ struct MessageSerializerNJ {
|
||||
static constexpr const char* version {"1"};
|
||||
|
||||
Contact3Registry& cr;
|
||||
ObjectStore2& os;
|
||||
|
||||
// nlohmann
|
||||
// json/msgpack
|
||||
@ -76,6 +78,8 @@ struct MessageSerializerNJ {
|
||||
// helper
|
||||
nlohmann::json serlContactByID(Contact3 c) const;
|
||||
Contact3 deserlContactByID(const nlohmann::json& j);
|
||||
nlohmann::json serlFileObjByID(ObjectHandle o) const;
|
||||
ObjectHandle deserlFileObjByID(const nlohmann::json& j);
|
||||
};
|
||||
|
||||
// fwd
|
||||
@ -83,6 +87,7 @@ namespace Message::Components {
|
||||
struct ContactFrom;
|
||||
struct ContactTo;
|
||||
struct ReceivedBy;
|
||||
struct MessageFileObject;
|
||||
}
|
||||
|
||||
// make specializations known
|
||||
@ -98,3 +103,7 @@ template<>
|
||||
bool MessageSerializerNJ::component_get_json<Message::Components::ReceivedBy>(MessageSerializerNJ& msc, const Handle h, nlohmann::json& j);
|
||||
template<>
|
||||
bool MessageSerializerNJ::component_emplace_or_replace_json<Message::Components::ReceivedBy>(MessageSerializerNJ& msc, Handle h, const nlohmann::json& j);
|
||||
template<>
|
||||
bool MessageSerializerNJ::component_get_json<Message::Components::MessageFileObject>(MessageSerializerNJ& msc, const Handle h, nlohmann::json& j);
|
||||
template<>
|
||||
bool MessageSerializerNJ::component_emplace_or_replace_json<Message::Components::MessageFileObject>(MessageSerializerNJ& msc, Handle h, const nlohmann::json& j);
|
||||
|
@ -21,13 +21,7 @@ namespace Message::Components {
|
||||
// SyncedBy
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MessageText, text)
|
||||
|
||||
// TODO: remove
|
||||
//namespace Transfer {
|
||||
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(FileInfo::FileDirEntry, file_name, file_size)
|
||||
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(FileInfo, file_list, total_size)
|
||||
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(FileInfoLocal, file_list)
|
||||
//} // Transfer
|
||||
// file is special
|
||||
|
||||
} // Message::Components
|
||||
|
||||
|
@ -27,13 +27,7 @@ void registerMessageComponents(MessageSerializerNJ& msnj) {
|
||||
msnj.registerSerializer<Message::Components::TagMessageIsAction>();
|
||||
msnj.registerDeserializer<Message::Components::TagMessageIsAction>();
|
||||
|
||||
// files
|
||||
//_sc.registerSerializerJson<Message::Components::Transfer::FileID>()
|
||||
//_sc.registerSerializerJson<Message::Components::Transfer::FileInfo>();
|
||||
//_sc.registerDeSerializerJson<Message::Components::Transfer::FileInfo>();
|
||||
//_sc.registerSerializerJson<Message::Components::Transfer::FileInfoLocal>();
|
||||
//_sc.registerDeSerializerJson<Message::Components::Transfer::FileInfoLocal>();
|
||||
//_sc.registerSerializerJson<Message::Components::Transfer::TagHaveAll>();
|
||||
//_sc.registerDeSerializerJson<Message::Components::Transfer::TagHaveAll>();
|
||||
msnj.registerSerializer<Message::Components::MessageFileObject>();
|
||||
msnj.registerDeserializer<Message::Components::MessageFileObject>();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user