sonic-rs icon indicating copy to clipboard operation
sonic-rs copied to clipboard

Support from_reader() like serde_json::from_reader()

Open pymongo opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

Any function to deserialize from a TcpStream or File?

pymongo avatar Dec 14 '23 09:12 pymongo

there are no existing functions as from_reader in #38, welcome to PR for it

liuq19 avatar Dec 14 '23 10:12 liuq19

@liuq19 I think there are two ways:

  1. Call io::Read::read_to_end to save data in a buffer, and call from_slice. This is a simple way that references https://github.com/simd-lite/simd-json/blob/dd7fc44f5526e3e2abe0ebba53bc1faed501a128/src/serde.rs#L143C8-L143C19.
  2. Adapt Reader trait for io::Read. This could be complex. We have to redesign Reader trait API and do refactor. serde do this way since it deserializes json char by char, which consists of the feature of io::Read. But we may get better performance.

CPunisher avatar Sep 19 '24 11:09 CPunisher

thanks, I prefer the first method, could you try it?

liuq19 avatar Sep 19 '24 13:09 liuq19