News for hackers. Stuff that matters.
Re:Libnop: C++ Native Object Protocols by CyberDildonics on Friday October 05, 2018 @06:31PM (#18152264)
How is this better than cereal, which is already mature and very easy.

https://uscilab.github.io/cereal/

Re:Libnop: C++ Native Object Protocols by stochastic_monk on Friday October 05, 2018 @06:48PM (#18152337)
I’m familiar with capnproto [0], which claims something like zero overhead.

Personally, I just write serialization functions using fwrite/fread/write/read, but I’ve used projects which depend on it.

[0] https://capnproto.org/

Re:Libnop: C++ Native Object Protocols by CyberDildonics on Saturday October 06, 2018 @11:20AM (#18155561)
I've done that, but it can be very error prone and therefore time consuming.

Instead of relying on serialization of existing data structures I actually try to use more general data structures that already exist in a single span of memory.

Then serialization is just a matter of writing them out from start to finish, or allocating them in a memory mapped file.

Re:Libnop: C++ Native Object Protocols by gmueckl on Friday October 05, 2018 @06:53PM (#18152383)
Can cereal handle user defined types without having to write custom serialization and deserialization functions for each? At first glance this seems to be the main difference.
Re:Libnop: C++ Native Object Protocols by nly on Friday October 05, 2018 @09:42PM (#18153022)
Cereal requires a bit more copy & paste template boilerplate (it's a customization point) but they're basically the same.

* libnop uses a macro called NOP_STRUCTURE to create its key-value pairs.

* Cereal has a macro called CEREAL_NVP.

* Boost.Fusion has BOOST_FUSION_ADAPT_ASSOC_STRUCT

* Boost.Hana has BOOST_HANA_ADAPT_STRUCT

* Boost.Serialization has BOOST_SERIALIZATION_NVP

...all these things work the same way to get reflection

Re:Libnop: C++ Native Object Protocols by coreytabaka on Saturday October 06, 2018 @03:05AM (#18153951)
Yes! Hopefully C++20 or C++25-ish will provide better alternatives for compile-time reflection.

Don't forget that libnop also has NOP_EXTERNAL_STRUCTURE (and friends) to decouple the annotation from the structure definition. This is handy when you have a C ABI with C++ internal implementation. I don't recall seeing a similar facility in other libraries.

Re:Libnop: C++ Native Object Protocols by nly on Sunday October 07, 2018 @07:06PM (#18163109)
Most of the above macros work this way. Boost fusions macro will let you specify arbitrary code for getting and setting attributes.
Re:Libnop: C++ Native Object Protocols by jhasse on Friday October 05, 2018 @07:00PM (#18152420)
cereal supports shared_ptrs and unique_ptrs, this doesn't (pls correct me if I'm wrong).
Re:Libnop: C++ Native Object Protocols by coreytabaka on Friday October 05, 2018 @07:16PM (#18152501)
unique_ptr and nop::Optional<unique_ptr<T>> is on the way. shared_ptr opens up the ability to create cycles, which are not supported yet.