Decode `Self` from the given buffer.
(visitor: &mut V, reader: &mut R)
| 138 | |
| 139 | /// Decode `Self` from the given buffer. |
| 140 | pub fn decode<'a, V, R>(visitor: &mut V, reader: &mut R) -> Result<Self, V::Error> |
| 141 | where |
| 142 | V: Visitor<Row = T>, |
| 143 | R: BufReader<'a>, |
| 144 | { |
| 145 | let flags = Flags::from_bits_retain(reader.get_u8()?); |
| 146 | |
| 147 | // If the flags indicate that the payload contains `Inputs`, |
| 148 | // try to decode and visit them. |
| 149 | let inputs = flags |
| 150 | .contains(Flags::HAVE_INPUTS) |
| 151 | .then(|| Inputs::decode(reader)) |
| 152 | .transpose()?; |
| 153 | if let Some(inputs) = &inputs { |
| 154 | visitor.visit_inputs(inputs)?; |
| 155 | } |
| 156 | |
| 157 | // If the flags indicate that the payload contains `Outputs`, |
| 158 | // try to decode and visit them. |
| 159 | let outputs = flags |
| 160 | .contains(Flags::HAVE_OUTPUTS) |
| 161 | .then(|| Outputs::decode(reader)) |
| 162 | .transpose()?; |
| 163 | if let Some(outputs) = &outputs { |
| 164 | visitor.visit_outputs(outputs)?; |
| 165 | } |
| 166 | |
| 167 | // If the flags indicate that the payload contains `Mutations`, |
| 168 | // try to decode them. |
| 169 | let mutations = flags |
| 170 | .contains(Flags::HAVE_MUTATIONS) |
| 171 | .then(|| Mutations::decode(visitor, reader)) |
| 172 | .transpose()?; |
| 173 | |
| 174 | Ok(Self { |
| 175 | inputs, |
| 176 | outputs, |
| 177 | mutations, |
| 178 | }) |
| 179 | } |
| 180 | |
| 181 | /// Variant of [`Self::decode`] which doesn't allocate `Self`. |
| 182 | /// |
nothing calls this directly
no test coverage detected