MCPcopy Create free account
hub / github.com/hashintel/hash / decode

Method decode

libs/@local/codec/src/bytes.rs:196–211  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 ///

Callers 6

decode_incomplete_dataFunction · 0.45
decode_malformed_jsonFunction · 0.45
decode_empty_bufferFunction · 0.45

Calls 6

map_errMethod · 0.80
mapMethod · 0.45
filterMethod · 0.45
is_emptyMethod · 0.45
attach_withMethod · 0.45
cloneMethod · 0.45

Tested by 6

decode_incomplete_dataFunction · 0.36
decode_malformed_jsonFunction · 0.36
decode_empty_bufferFunction · 0.36