Giter Club home page Giter Club logo

Comments (3)

fraillt avatar fraillt commented on July 18, 2024

Hello,
First of all congratulations, you're the first to submit the ticket!
I believe the problem you encounter is that quickSerialization/Deserialization doesn't work, right?

The idea behind quickSerialization/Deserialization is that it would simplify the general case, e.g. serialize struct (object). If you look at the implementation of quickSerialization you would see that it calls ser.object(value), all you need to do is to use the same code except in your case call ser.container(value, maxSize) where maxSize is your defined max allowable container size.

Hope that helps :)

from bitsery.

Rinkss avatar Rinkss commented on July 18, 2024

Is this library suitable for maps and nested map?

from bitsery.

fraillt avatar fraillt commented on July 18, 2024

yep
Lets take this example

using NestedType = std::unordered_map<int, std::vector<float>>;
using MyType = std::map<std::string, NestedType>;

There are two ways to do it. using verbose syntax (full serialization control), and flexible syntax.

In verbose syntax you need to use StdMap extensions <bitsery/ext/std_map.h> and
define serialize function in bitsery namespace for ADL (polluting std namespace is not recommended)
e.g.

namespace bitsery {
    template <typename S>
    void serialize(S& ser, MyType& data) {
        ser.ext(data, ext::StdMap{10}, [&ser](std::string& key, NestedType & value) {
            ser.text1b(key, 10);
            ser.ext(value, ext::StdMap{10}, [&ser](int& key, std::vector<float>& value) {
                ser.value4b(key);
                ser.container4b(value, 10);
            });
        });
    }
}

or create your own function anywhere you like, e.g.

template <typename S>
void serializeAndDeserializeMyType(S& ser, MyType& data) {
    ser.ext(data, ext::StdMap{10}, [&ser](std::string& key, NestedType & value) {
        ser.text1b(key, 10);
        ser.ext(value, ext::StdMap{10}, [&ser](int& key, std::vector<float>& value) {
            ser.value4b(key);
            ser.container4b(value, 10);
        });
    });
}

In flexible syntax you don't need to define serialize function, just include other headers and you're done!

#include <bitsery/flexible.h>
#include <bitsery/flexible/map.h>
#include <bitsery/flexible/unordered_map.h>
#include <bitsery/flexible/string.h>
#include <bitsery/flexible/vector.h>

just instead of calling ser.object(data), call ser.archive(data) see this example for more details.

from bitsery.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.