MCPcopy Create free account
hub / github.com/ElementsProject/lightning / decode

Method decode

plugins/src/codec.rs:32–51  ·  view source on GitHub ↗
(&mut self, buf: &mut BytesMut)

Source from the content-addressed store, hash-verified

30 type Item = String;
31 type Error = Error;
32 fn decode(&mut self, buf: &mut BytesMut) -> Result<Option<Self::Item>, Error> {
33 let bytes = &buf[..];
34 let mut i = self.search_pos;
35
36 while i + 1 < bytes.len() {
37 if bytes[i] == b'\n' && bytes[i + 1] == b'\n' {
38 let line = buf.split_to(i + 2);
39 let line = &line[..line.len() - 2];
40
41 self.search_pos = 0;
42
43 return Ok(Some(utf8(line)?.to_owned()));
44 }
45 i += 1;
46 }
47
48 self.search_pos = bytes.len().saturating_sub(1);
49
50 Ok(None)
51 }
52}
53
54impl<T> Encoder<T> for MultiLineCodec

Callers 1

test_json_codecFunction · 0.45

Calls 1

utf8Function · 0.70

Tested by 1

test_json_codecFunction · 0.36