Giter Site home page Giter Site logo

Comments (6)

Loki-Astari avatar Loki-Astari commented on June 11, 2024

Hi there.

There is a way to conditionally serialize members.

struct TEST_OBJECT
{
    std::map<std::string, bool>   filter;   // filter object
    std::string _children;
    std::string _name;
};

ThorsAnvil_MakeFilter(TEST_OBJECT, filter);                     // define a filter object
ThorsAnvil_MakeTrait(TEST_OBJECT, _children, _name); // define a filter.

If the name of the field is in the filter AND has a value false then it will not be serialized on ouptut.
Otherwise the value is serialized.

Note: This only affects output and the filter is not used on input.

from thorsserializer.

ripe909 avatar ripe909 commented on June 11, 2024

hmm, interesting! I didn't see this in the docs, so I assume it is a new capability?

I see the test case for it, which is a good example: https://github.com/Loki-Astari/ThorsSerializer/blob/dac66aa1feefd3559032d9df3178ec19c318caf4/src/Serialize/test/FilterValuesTest.cpp

I have a fairly large tree of objects, which would require updating thousands of instances to remove/add a member to the filter, and it would increase the memory footprint to store the filter map.

Since I need a global Trait filter (not per object instance), I may need to figure out a different method.

from thorsserializer.

Loki-Astari avatar Loki-Astari commented on June 11, 2024

Yes. I am working on DB driver with optional field requirements.
This has made me add this feature.

Once I have stabalized the DB driver I will add the appropriate documentation to the Serializer product.

from thorsserializer.

ripe909 avatar ripe909 commented on June 11, 2024

Sounds good. I am using your library to serialize data from a microcontroller's SDRAM to an SD card, so memory is a scarce resource.

from thorsserializer.

Loki-Astari avatar Loki-Astari commented on June 11, 2024

Note: The filter does not have to be std::map<std::string, bool> object.

It can be an object that supports bool operator[](std::string).
It should be relatively simple to add an object that accesses a global structure.

std::map<std::string, bool>   globalFilter;

class GlobalFilter
{
     std::string prefix;
    public:
        GlobalFilter(std::string const& prefix): prefix(prefix) {}
        bool operator[](std::string const& name) const
        {
                return globalFilter[prefix + ":" + name];
        }
};

Then it each object just add a member to the type.
        GlobalFilter   filter("ObjectName");  // You could potentially make this static to save space
                                                                     // Though this adds some of its own complexities.

from thorsserializer.

ripe909 avatar ripe909 commented on June 11, 2024

I was able to try this today and it worked perfectly. I used a static member of my objects as a "global" filter

from thorsserializer.

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.