Parse a JSON value from a byte slice and return a Python object. # Arguments - `py`: [Python](https://docs.rs/pyo3/latest/pyo3/marker/struct.Python.html) marker token. - `json_data`: The JSON data to parse. this should have a significant improvement on performance but increases memory slightly. # Returns A [PyObject](https://docs.rs/pyo3/latest/pyo3/type.PyObject.html) representing the parsed
(&self, py: Python<'py>, json_data: &[u8])
| 45 | /// |
| 46 | /// A [PyObject](https://docs.rs/pyo3/latest/pyo3/type.PyObject.html) representing the parsed JSON value. |
| 47 | pub fn python_parse<'py>(&self, py: Python<'py>, json_data: &[u8]) -> JsonResult<Bound<'py, PyAny>> { |
| 48 | macro_rules! ppp { |
| 49 | ($string_cache:ident, $key_check:ident, $parse_number:ident) => { |
| 50 | PythonParser::<$string_cache, $key_check, $parse_number>::parse( |
| 51 | py, |
| 52 | json_data, |
| 53 | self.allow_inf_nan, |
| 54 | self.partial_mode, |
| 55 | ) |
| 56 | }; |
| 57 | } |
| 58 | macro_rules! ppp_group { |
| 59 | ($string_cache:ident) => { |
| 60 | match (self.catch_duplicate_keys, self.float_mode) { |
| 61 | (true, FloatMode::Float) => ppp!($string_cache, DuplicateKeyCheck, ParseNumberLossy), |
| 62 | (true, FloatMode::Decimal) => ppp!($string_cache, DuplicateKeyCheck, ParseNumberDecimal), |
| 63 | (true, FloatMode::LosslessFloat) => ppp!($string_cache, DuplicateKeyCheck, ParseNumberLossless), |
| 64 | (false, FloatMode::Float) => ppp!($string_cache, NoopKeyCheck, ParseNumberLossy), |
| 65 | (false, FloatMode::Decimal) => ppp!($string_cache, NoopKeyCheck, ParseNumberDecimal), |
| 66 | (false, FloatMode::LosslessFloat) => ppp!($string_cache, NoopKeyCheck, ParseNumberLossless), |
| 67 | } |
| 68 | }; |
| 69 | } |
| 70 | |
| 71 | match self.cache_mode { |
| 72 | StringCacheMode::All => ppp_group!(StringCacheAll), |
| 73 | StringCacheMode::Keys => ppp_group!(StringCacheKeys), |
| 74 | StringCacheMode::None => ppp_group!(StringNoCache), |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /// Map a `JsonError` to a `PyErr` which can be raised as an exception in Python as a `ValueError`. |
no outgoing calls