MCPcopy Create free account
hub / github.com/f0rr0/oliphaunt / join

Method join

src/protocol/tests.rs:62–82  ·  view source on GitHub ↗
(&self, append_length: bool, code: Option<u8>)

Source from the content-addressed store, hash-verified

60 }
61
62 pub fn join(&self, append_length: bool, code: Option<u8>) -> Vec<u8> {
63 let body_len: usize = self.buffers.iter().map(|b| b.len()).sum();
64 let mut result = Vec::with_capacity(
65 body_len + usize::from(append_length) * 4 + usize::from(code.is_some()),
66 );
67
68 if let Some(code) = code {
69 result.push(code);
70 }
71
72 if append_length {
73 let length = (body_len + 4) as i32;
74 result.extend_from_slice(&length.to_be_bytes());
75 }
76
77 for part in &self.buffers {
78 result.extend_from_slice(part);
79 }
80
81 result
82 }
83 }
84
85 pub fn concat_slices(parts: &[&[u8]]) -> Vec<u8> {

Calls 3

iterMethod · 0.80
lenMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected