bitsery
bitsery copied to clipboard
Vector<String *>
i'm trying to serialize a vector of string pointers for the first time...
class Contact {
public:
String name;
std::vector<String *> bits;
};
template <typename S>
static void serialize(S& s, Contact& contact)
{
s.text1b(contact.name, UINT8_MAX);
s.container(contact.bits, UINT16_MAX, [](S& s1, auto& bit) {
PointerOwner{}.serialize(s1, bit, [](S& s2, auto &v) { s2.text1b(v, UINT16_MAX); });
});
}
thoughts on this?
In file included from /Users/victorstewart/xxx/Data/Database.cpp:9:
In file included from /Users/victorstewart/xxx/Data/Database.hpp:9:
In file included from /Users/victorstewart/xxx/all.h:40:
In file included from /Users/victorstewart/Dropbox/nametag/nametag/engines/nametag.engines.bitsery.v0.h:1:
In file included from /Users/victorstewart/Dropbox/nametag/nametag/libraries/include/bitsery/bitsery.h:40:
In file included from /Users/victorstewart/Dropbox/nametag/nametag/libraries/include/bitsery/serializer.h:27:
In file included from /Users/victorstewart/Dropbox/nametag/nametag/libraries/include/bitsery/ext/../details/serialization_common.h:29:
/Users/victorstewart/Dropbox/nametag/nametag/libraries/include/bitsery/ext/../details/adapter_common.h:87:28: error: no member named 'writeBytes' in 'bitsery::InputBufferAdapter<String, FastConfig>'
w.template writeBytes<1>(static_cast<uint8_t>(size));
~ ^
In file included from /Users/victorstewart/xxx/Data/Database.cpp:9:
In file included from /Users/victorstewart/xxx/Data/Database.hpp:9:
In file included from /Users/victorstewart/xxx/all.h:40:
In file included from /Users/victorstewart/Dropbox/nametag/nametag/engines/nametag.engines.bitsery.v0.h:3:
In file included from /Users/victorstewart/Dropbox/nametag/nametag/libraries/include/bitsery/ext/pointer.h:28:
/Users/victorstewart/Dropbox/nametag/nametag/libraries/include/bitsery/ext/utils/pointer_utils.h:297:34: note: in instantiation of function template specialization 'bitsery::details::writeSize<bitsery::InputBufferAdapter<String, FastConfig>>' requested here
details::writeSize(ser.adapter(), ptrInfo.id);
^
/Users/victorstewart/xxx/Data/Database.cpp:95:24: note: in instantiation of function template specialization 'bitsery::ext::pointer_utils::PointerObjectExtensionBase<pointer_details::PtrOwnerManager, PolymorphicContext, bitsery::ext::StandardRTTI>::serialize<bitsery::Deserializer<bitsery::InputBufferAdapter<String, FastConfig>, std::tuple<bitsery::ext::PointerLinkingContext>>, String *, (lambda at /Users/victorstewart/xxx/Data/Database.cpp:95:43)>' requested here
PointerOwner{}.serialize(s1, bit, [](S& s2, auto &v) { s2.text1b(v, UINT16_MAX); });
there also isn't really an ergonomic way to do this currently.
trying to map it through .object()
with s1.ext(bit, PointerOwner{});
and defining a serialize function for my custom String type triggers a static assert finding a free and member function named serialize because i have this in my class.
template <typename T>
uint32_t serialize(T&& object);
i could change it's name, but maybe we need to check if the return type of the serialize function is void?
but regardless i think the correct way would be something like exttext1b
. but of course that's pretty ugly and adds ever more functions.
Hello, So something like this should work
s.container(contract.bits, UINT16_MAX, [](S& s1, auto &bit){
s1.ext(bit, PointerOwner{}, [](S& s2, auto &v) {
s2.text1b(v, UINT16_MAX);
});
});
For static assert error, you can select serialize function like this:
namespace bitsery {
template <>
struct SelectSerializeFnc<String>:UseMemberFnc {};
// OR
template <>
struct SelectSerializeFnc<String>:UseNonMemberFnc {};
}
Hope that helps.