MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / decode

Method decode

crates/commitlog/src/payload/txdata.rs:140–179  ·  view source on GitHub ↗

Decode `Self` from the given buffer.

(visitor: &mut V, reader: &mut R)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

decodeFunction · 0.85
from_strFunction · 0.85
decode_varintFunction · 0.85
get_u8Method · 0.80
visit_outputsMethod · 0.80
get_u32Method · 0.80
OkFunction · 0.50
containsMethod · 0.45
visit_inputsMethod · 0.45
get_sliceMethod · 0.45
unwrapMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected