Giter Club home page Giter Club logo

Comments (2)

stephenberry avatar stephenberry commented on July 23, 2024

Thanks for explaining your problem in detail. We can still have compile time hash tables with runtime inclusion/exclusion, since we know our potential keys at compile time.

The problem with runtime JSON pointers to keys is that this induces runtime sorting and grouping, which is a significant cost. But, I'm sure you're looking for flexibility and not peak performance.

Better performance can be achieved if we don't use JSON pointers and only allow top level keys.

Do you find yourself using nested partial writing? Or, would you be satisfied with only top level keys in an object being specified?

Potential API:

std::vector<std::string> keys = { "key_one", "key_two" };
glz::write_partial_json(keys, object, buffer);

from glaze.

pawcam avatar pawcam commented on July 23, 2024

We're only writing top level keys for the foreseeable future, so this would be a nice enhancement.

That api is pretty much what I want to do. I'd love to keep the compile time key performance, but It would be nice to set flags in my struct that indicate which known compile time keys that should be ignored during serialization (you have a flags() method available in glz::meta but Im not sure it solves my use case):

static constexpr auto value = flags("my-conditional-key", &T::bSerializeConditionalKey); // this seems to only work for the field bSerializeConditionalKey itself, not another field with a real value.

Something like:

struct myData
{
  bool bField1Flag{false};
  bool bField2Flag{false};

 char someField1[]
 char someField2[]
}


template <>
struct meta<myData>
{
using T = myData;

  static constexpr auto value = object("field-1", , glz::custom<read_field_1  , write_field1
, true                     // always read
, &T::bFieldFlag1 // runtime conditionally write
>.
}

from glaze.

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.