Giter Club home page Giter Club logo

Comments (7)

breese avatar breese commented on July 19, 2024

What kind of API do you have in mind?

from trial.protocol.

vinipsmaker avatar vinipsmaker commented on July 19, 2024

I think a...

size_t raw_node(view_type v);

It's the same signature as of literal(). The difference is that the usual separators will be inserted as if a node was inserted.

An alternative approach would be to change literal() parameters so you can state your intention and implementation choice there, but I don't like this idea.

TBH I think the hard task will be to choose the name. Is raw_node() a good name? The implementation itself doesn't seem challenging.

from trial.protocol.

breese avatar breese commented on July 19, 2024

The requirement is that the inserted fragment is a valid JSON element. Otherwise the writer could end up being confused about the current separator and nesting level.

So we could call it element().

from trial.protocol.

vinipsmaker avatar vinipsmaker commented on July 19, 2024

The name element() works for me.

from trial.protocol.

vinipsmaker avatar vinipsmaker commented on July 19, 2024

On a second thought, I think the code will be more readable if you use the name raw_element(). To the non-initiated user, there is no difference between value and element (and indeed there is little difference between these two grammar rules in the json spec). To someone that just started to hack on a new codebase, the name choices between value() and element() would seem arbitrary and not intuitive. raw_value() would be yet another option (but then again we're just one jump away from literal_value() and two jumps from literal()). Maybe rename literal() to literal_ws() and use the name literal() for this function (but it'd be a bold API breakage here).

from trial.protocol.

breese avatar breese commented on July 19, 2024

An alternative solution is a separator() function that writes the correct separator depending on context -- comma separator in a JSON array, alternating colon and comma separators in JSON object, and nothing in the top-level scope.

separator() must be called before inserting raw data. This would allow us to insert raw data in chunks using multiple literal() calls.

  writer.value<begin_array>();
  writer.separator();
  writer.literal("null");
  writer.separator();
  writer.literal("nu");
  writer.literal("ll");
  writer.value<end_array>();

from trial.protocol.

vinipsmaker avatar vinipsmaker commented on July 19, 2024

That works.

from trial.protocol.

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.