Giter Club home page Giter Club logo

Comments (7)

stephenberry avatar stephenberry commented on September 26, 2024 1

Thanks for bringing up these issues with raw and std::string_view buffers. I'm about to merge a major change to support errors when writing and then I'll prioritize these issues.

from glaze.

stephenberry avatar stephenberry commented on September 26, 2024 1

Support has been merged, let me know if you run into any issues.

from glaze.

stephenberry avatar stephenberry commented on September 26, 2024

This was just overlooked for partial writing, so I'll add in a function that supports raw buffers.

I actually need to make some write API changes to better support handling write errors. I'll probably include this support in that merge.

I'm curious, do you know your sizes? Could you be using std::string_view?

from glaze.

pawcam avatar pawcam commented on September 26, 2024

As far as knowing sizes:
JSON tags: yes
JSON values: no

so it'll look like this for one partial
{"name": "John Smith"}

and this for another and so on.
{"address": "123 North Str"}

so the size of the JSON needs to be variable, but we're just allocating enough memory up front to hold anything we would ever serialize and using a buffer + an offset to determine the size of the buffer content we care about.

I get a different issue when using std::string_view interestingly:

/include/glaze/json/write.hpp:1326:38: error: could not convert ‘quoted_key’ from ‘const std::basic_string_view<char>’ to ‘long unsigned int’
 1326 |                      dump<quoted_key>(b, ix);
      |                      ~~~~~~~~~~~~~~~~^~~~~~~
      |                                      |
      |                                      const std::basic_string_view<char>

where my call to write_json is as follows

char buf*;
std::string_view svOut{buf};
glz::write_json<partial_1>(msg, svOut);

from glaze.

stephenberry avatar stephenberry commented on September 26, 2024

Support is being added in #1074

from glaze.

stephenberry avatar stephenberry commented on September 26, 2024

std::string_view is read only, so I've decided to just support char* and char[] raw buffers for writing. I could add write support for std::span<char>, but this might add some confusion and I don't feel is necessary.

from glaze.

pawcam avatar pawcam commented on September 26, 2024

Awesome, I will definitely check it out soon. Thanks!

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.