MCPcopy Create free account
hub / github.com/apache/fory / read_collection_data

Function read_collection_data

rust/fory-core/src/serializer/collection.rs:236–276  ·  view source on GitHub ↗
(context: &mut ReadContext)

Source from the content-addressed store, hash-verified

234}
235
236pub fn read_collection_data<C, T>(context: &mut ReadContext) -> Result<C, Error>
237where
238 T: Serializer + ForyDefault,
239 C: FromIterator<T>,
240{
241 let len = context.reader.read_var_u32()?;
242 if len == 0 {
243 return Ok(C::from_iter(std::iter::empty()));
244 }
245 if T::fory_is_polymorphic() || T::fory_is_shared_ref() {
246 return read_collection_data_dyn_ref(context, len);
247 }
248 let header = context.reader.read_u8()?;
249 let declared = (header & DECL_ELEMENT_TYPE) != 0;
250 if !declared {
251 // context.read_any_type_info();
252 // TODO check whether type info consistent with T
253 T::fory_read_type_info(context)?;
254 }
255 let has_null = (header & HAS_NULL) != 0;
256 ensure!(
257 (header & IS_SAME_TYPE) != 0,
258 Error::type_error("Type inconsistent, target type is not polymorphic")
259 );
260 let _ = check_collection_len(context, len)?;
261 if !has_null {
262 (0..len)
263 .map(|_| T::fory_read_data(context))
264 .collect::<Result<C, Error>>()
265 } else {
266 (0..len)
267 .map(|_| {
268 let flag = context.reader.read_i8()?;
269 if flag == RefFlag::Null as i8 {
270 return Ok(T::fory_default());
271 }
272 T::fory_read_data(context)
273 })
274 .collect::<Result<C, Error>>()
275 }
276}
277
278#[inline(always)]
279pub fn read_vec_data<T>(context: &mut ReadContext) -> Result<Vec<T>, Error>

Callers 3

fory_read_dataMethod · 0.85
fory_read_dataMethod · 0.85
fory_read_dataMethod · 0.85

Calls 9

emptyFunction · 0.85
fory_read_type_infoFunction · 0.85
check_collection_lenFunction · 0.85
fory_read_dataFunction · 0.85
read_var_u32Method · 0.80
read_u8Method · 0.80
read_i8Method · 0.80
mapMethod · 0.45

Tested by

no test coverage detected