Serialize `value = &bytes[range_move(0..ty.size(), *curr_offset)]` into a `ser`, using `blob_store` to retrieve the bytes of any large blob object and `curr_offset`, advanced as serialization progresses, to decide where to start reading. SAFETY: 1. the `value` must be valid at type `ty` and properly aligned for `ty`. 2. for any `vlr: VarLenRef` stored in `value`, `vlr.first_offset` must either be
(
ser: S,
bytes: &Bytes,
page: &Page,
blob_store: &dyn BlobStore,
curr_offset: CurrOffset<'_>,
ty: &AlgebraicTypeLayout,
)
| 232 | /// `vlr.first_offset` must either be `NULL` or point to a valid granule in `page`. |
| 233 | /// 3. `align_to(curr_offset.get(), ty.align())` must be the offset of a field typed at `ty`. |
| 234 | pub(crate) unsafe fn serialize_value<S: Serializer>( |
| 235 | ser: S, |
| 236 | bytes: &Bytes, |
| 237 | page: &Page, |
| 238 | blob_store: &dyn BlobStore, |
| 239 | curr_offset: CurrOffset<'_>, |
| 240 | ty: &AlgebraicTypeLayout, |
| 241 | ) -> Result<S::Ok, S::Error> { |
| 242 | debug_assert_eq!( |
| 243 | curr_offset.get(), |
| 244 | align_to(curr_offset.get(), ty.align()), |
| 245 | "curr_offset {curr_offset:?} insufficiently aligned for type {ty:#?}", |
| 246 | ); |
| 247 | |
| 248 | match ty { |
| 249 | AlgebraicTypeLayout::Sum(ty) => { |
| 250 | // SAFETY: `value` was valid at `ty` and `VarLenRef`s won't be dangling. |
| 251 | unsafe { serialize_sum(ser, bytes, page, blob_store, curr_offset, ty) } |
| 252 | } |
| 253 | AlgebraicTypeLayout::Product(ty) => { |
| 254 | // SAFETY: `value` was valid at `ty` and `VarLenRef`s won't be dangling. |
| 255 | unsafe { serialize_product(ser, bytes, page, blob_store, curr_offset, ty.view()) } |
| 256 | } |
| 257 | // The primitive types: |
| 258 | // |
| 259 | // SAFETY (applies to app primitive types): |
| 260 | // Per caller requirement, know `value` points to a valid `ty`. |
| 261 | // Thus `&bytes[range_move(0..ty.size(), *curr_offset)]` points to init bytes |
| 262 | // and `ty.size()` corresponds exactly to `N = 1, 1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 4, 8`. |
| 263 | &AlgebraicTypeLayout::Bool => ser.serialize_bool(unsafe { read_from_bytes::<u8>(bytes, curr_offset) } != 0), |
| 264 | &AlgebraicTypeLayout::I8 => ser.serialize_i8(unsafe { read_from_bytes(bytes, curr_offset) }), |
| 265 | &AlgebraicTypeLayout::U8 => ser.serialize_u8(unsafe { read_from_bytes(bytes, curr_offset) }), |
| 266 | &AlgebraicTypeLayout::I16 => { |
| 267 | ser.serialize_i16(i16::from_le_bytes(unsafe { read_from_bytes(bytes, curr_offset) })) |
| 268 | } |
| 269 | &AlgebraicTypeLayout::U16 => { |
| 270 | ser.serialize_u16(u16::from_le_bytes(unsafe { read_from_bytes(bytes, curr_offset) })) |
| 271 | } |
| 272 | &AlgebraicTypeLayout::I32 => { |
| 273 | ser.serialize_i32(i32::from_le_bytes(unsafe { read_from_bytes(bytes, curr_offset) })) |
| 274 | } |
| 275 | &AlgebraicTypeLayout::U32 => { |
| 276 | ser.serialize_u32(u32::from_le_bytes(unsafe { read_from_bytes(bytes, curr_offset) })) |
| 277 | } |
| 278 | &AlgebraicTypeLayout::I64 => { |
| 279 | ser.serialize_i64(i64::from_le_bytes(unsafe { read_from_bytes(bytes, curr_offset) })) |
| 280 | } |
| 281 | &AlgebraicTypeLayout::U64 => { |
| 282 | ser.serialize_u64(u64::from_le_bytes(unsafe { read_from_bytes(bytes, curr_offset) })) |
| 283 | } |
| 284 | &AlgebraicTypeLayout::I128 => { |
| 285 | ser.serialize_i128(i128::from_le_bytes(unsafe { read_from_bytes(bytes, curr_offset) })) |
| 286 | } |
| 287 | &AlgebraicTypeLayout::U128 => { |
| 288 | ser.serialize_u128(u128::from_le_bytes(unsafe { read_from_bytes(bytes, curr_offset) })) |
| 289 | } |
| 290 | &AlgebraicTypeLayout::I256 => { |
| 291 | ser.serialize_i256(i256::from_le_bytes(unsafe { read_from_bytes(bytes, curr_offset) })) |
no test coverage detected
searching dependent graphs…