Bitsery v4.4.0 Release Notes

Release Date: 2019-01-08 // about 5 years ago
  • 🔋 Features

    • new extensions CompactValue and CompactValueAsObject, stores integral values in less space if possible. This is useful when you're working with mostly small values, that in rare cases can be large. E.g. int64_t money = 8000; will only use 2 bytes, instead of 8. CompactValueAsObject allows to use ext() overload, without specifying size of underlying type and sets BUFFER_OVERFLOW error if value doesn't fit in underlying type during deserialization.

    👌 Improvements

    • improved PolymorphicContext, allows to extend already registered hierarchy in one translation unit, using different type other than PolymorphicBaseClass to avoid symbol collision between translation units or libraries. 0️⃣ registerBasesList was modified, so that it could accept user defined type (instead of PolymorphicBaseClass) that is used to declare hierarchy, by default it is PolymorphicBaseClass. This introduced breaking change, for those who used this syntax (registerBasesList<MySerializer, Shape>({})) during registration. It is encouraged to define helper type, that could be used for registering hierarchy for serialization and deserialization [example](examples/smart_pointers_with_polymorphism.cpp). This is only relevant then you want to use **PolymorphicContext** between different translation units or libraries. ```cpp //libA namespace bitsery { namespace ext { template<> struct PolymorphicBaseClass : PolymorphicDerivedClasses {}; } } using MyPolymorphicClassesForRegistering = bitsery::ext::PolymorphicClassesList; ... ctx.registerBasesList(MyPolymorphicClassesForRegistering{}).

    //otherLib struct MySquare: Shape {...} //now it must define different type (exactly the same as PolymorphicBaseClass) to declare hierarchy template struct MyHierarchy { using Childs = PolymorphicClassesList<>; };

    template <> struct MyHierarchy: bitsery::ext::bitsery::ext::PolymorphicClassesList {}; ... //notice that we pass MyHierarchy as second argument ctx.registerBasesList(MyPolymorphicClassesForRegistering{}).

    * **PolymorphicContext** also get optional method `registerSingleBaseBranch`, that allows manually register hierarchies, this might be more convenient when using you need to register in different translation units (or libraries), but it is error-prone.