simd-lite / simd-json-derive

high performance Serialize and Deserialize derives
Apache License 2.0
30 stars 7 forks source link

failability of parsing code #73

Open Licenser opened 8 months ago

Licenser commented 8 months ago
          although I really do think there should be a discussion about the safety of the parsing code, why is parse fallible, and why we parse the array, without having the values of the array in the first place

Originally posted by @NightMare-Vortex in https://github.com/simd-lite/simd-json-derive/issues/54#issuecomment-1783574836

Licenser commented 8 months ago

I agree, definetly worth considering and revisiting! I pulled this in it's own issue so it's nut buried in a completed PR :)

Licenser commented 8 months ago

a few startingpoints:

1) the tape is (assuming no bugs) guaranteed to be valid JSON, all validation from formating (numbers, strings etc) and structure (correct k/v of objects, correct nesting etc) are checked in the second stage of parsing

2) for derives we need fallibility as we can have a valid json that does not match the expected structure that the derive demands

3) for DOM like structures (owned::Value, borrowed::Value that cover the entire JSON value space) we can expect all translation from tape -> dom to be correct

4) for DOM like structures that may not cover the entire value space, there is a chance of failures