(context: &mut ReadContext)
| 234 | } |
| 235 | |
| 236 | pub fn read_collection_data<C, T>(context: &mut ReadContext) -> Result<C, Error> |
| 237 | where |
| 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)] |
| 279 | pub fn read_vec_data<T>(context: &mut ReadContext) -> Result<Vec<T>, Error> |
no test coverage detected