Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement --stream #133

Open
Tracked by #33
MiSawa opened this issue Mar 26, 2022 · 5 comments
Open
Tracked by #33

Implement --stream #133

MiSawa opened this issue Mar 26, 2022 · 5 comments

Comments

@MiSawa
Copy link
Owner

MiSawa commented Mar 26, 2022

To really implement this without expand JSON in memory, we need one of followings

  • generator feature so that we can yield to pass value into the VM while keeping the intermediate state of the parser,
  • spawn a thread that reads input, and send the result into std::sync::mpsc::sync_channel(0) (or 1 so the reader thread can read one element ahead) to do a similar with above, or
  • implement a JSON parser on our own (and perhaps yaml as well).
@MiSawa
Copy link
Owner Author

MiSawa commented Mar 27, 2022

Actually generator wouldn't work since for example the A of visit_seq<A>(self, mut seq: A) itself may have a lifetime that is shorter than 'de or whatever so can't return a structure including this seq thing.

Also it's hard to do send/recv, since serde_json doesn't support providing DeserializeSeed for iteration mode (Deserializer::from_reader(stdin).into_iter()).
serde_yaml on the other hand is probably fine.

@MiSawa
Copy link
Owner Author

MiSawa commented Mar 27, 2022

Though serde_yaml doesn't seem to parse until we supply everything till EOF??? So presumably they keep everything in memory??? 😞

@MiSawa
Copy link
Owner Author

MiSawa commented Mar 27, 2022

serde-rs/json#304

@MiSawa
Copy link
Owner Author

MiSawa commented Mar 27, 2022

Here's a code to see the feasibility. https://gist.github.com/MiSawa/4e4086bd649f4639f390b93ca214f7f0

@MiSawa
Copy link
Owner Author

MiSawa commented Mar 28, 2022

Here's an implementation. Though it uses GATs in a non-essential part so require a nightly compiler to build. https://github.com/MiSawa/xq-stream-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant