Decodes a JSON line into a value of type `T`. # Performance This method has time complexity dependent on the length of the line being decoded. JSON parsing complexity is approximately O(n) where n is the length of the input string. # Errors - if reading the line fails - if the JSON content is invalid - if the JSON doesn't match type `T`
(&mut self, src: &mut BytesMut)
| 194 | /// - if the JSON content is invalid |
| 195 | /// - if the JSON doesn't match type `T` |
| 196 | fn decode(&mut self, src: &mut BytesMut) -> Result<Option<T>, Self::Error> { |
| 197 | self.lines |
| 198 | .decode(src) |
| 199 | .inspect(|_| { |
| 200 | self.current_line += 1; |
| 201 | }) |
| 202 | .map_err(io::Error::other)? |
| 203 | .filter(|line| !line.is_empty()) |
| 204 | .map(|line| { |
| 205 | serde_json::from_str(&line) |
| 206 | .map_err(io::Error::from) |
| 207 | .attach_with(|| format!("line in input: {}", self.current_line)) |
| 208 | .attach_with(|| line.clone()) |
| 209 | }) |
| 210 | .transpose() |
| 211 | } |
| 212 | |
| 213 | /// Decodes any remaining data when the stream has ended. |
| 214 | /// |