Read a datum starting at byte `offset`. Updates `offset` to point to the first byte after the end of the read region. # Safety This function is safe if a `Datum` was previously written at this offset by `push_datum`. Otherwise it could return invalid values, which is Undefined Behavior.
(data: &mut &'a [u8])
| 1351 | /// This function is safe if a `Datum` was previously written at this offset by `push_datum`. |
| 1352 | /// Otherwise it could return invalid values, which is Undefined Behavior. |
| 1353 | pub unsafe fn read_datum<'a>(data: &mut &'a [u8]) -> Datum<'a> { |
| 1354 | let tag = Tag::try_from_primitive(read_byte(data)).expect("unknown row tag"); |
| 1355 | match tag { |
| 1356 | Tag::Null => Datum::Null, |
| 1357 | Tag::False => Datum::False, |
| 1358 | Tag::True => Datum::True, |
| 1359 | Tag::UInt8_0 | Tag::UInt8_8 => { |
| 1360 | let i = u8::from_le_bytes(read_byte_array_extending_nonnegative( |
| 1361 | data, |
| 1362 | tag.actual_int_length() |
| 1363 | .expect("returns a value for variable-length-encoded integer tags"), |
| 1364 | )); |
| 1365 | Datum::UInt8(i) |
| 1366 | } |
| 1367 | Tag::Int16 => { |
| 1368 | let i = i16::from_le_bytes(read_byte_array(data)); |
| 1369 | Datum::Int16(i) |
| 1370 | } |
| 1371 | Tag::NonNegativeInt16_0 | Tag::NonNegativeInt16_16 | Tag::NonNegativeInt16_8 => { |
| 1372 | // SAFETY:`tag.actual_int_length()` is <= 16 for these tags, |
| 1373 | // and `data` is big enough because it was encoded validly. These assumptions |
| 1374 | // are checked in debug asserts. |
| 1375 | let i = i16::from_le_bytes(read_byte_array_extending_nonnegative( |
| 1376 | data, |
| 1377 | tag.actual_int_length() |
| 1378 | .expect("returns a value for variable-length-encoded integer tags"), |
| 1379 | )); |
| 1380 | Datum::Int16(i) |
| 1381 | } |
| 1382 | Tag::UInt16_0 | Tag::UInt16_8 | Tag::UInt16_16 => { |
| 1383 | let i = u16::from_le_bytes(read_byte_array_extending_nonnegative( |
| 1384 | data, |
| 1385 | tag.actual_int_length() |
| 1386 | .expect("returns a value for variable-length-encoded integer tags"), |
| 1387 | )); |
| 1388 | Datum::UInt16(i) |
| 1389 | } |
| 1390 | Tag::Int32 => { |
| 1391 | let i = i32::from_le_bytes(read_byte_array(data)); |
| 1392 | Datum::Int32(i) |
| 1393 | } |
| 1394 | Tag::NonNegativeInt32_0 |
| 1395 | | Tag::NonNegativeInt32_32 |
| 1396 | | Tag::NonNegativeInt32_8 |
| 1397 | | Tag::NonNegativeInt32_16 |
| 1398 | | Tag::NonNegativeInt32_24 => { |
| 1399 | // SAFETY:`tag.actual_int_length()` is <= 32 for these tags, |
| 1400 | // and `data` is big enough because it was encoded validly. These assumptions |
| 1401 | // are checked in debug asserts. |
| 1402 | let i = i32::from_le_bytes(read_byte_array_extending_nonnegative( |
| 1403 | data, |
| 1404 | tag.actual_int_length() |
| 1405 | .expect("returns a value for variable-length-encoded integer tags"), |
| 1406 | )); |
| 1407 | Datum::Int32(i) |
| 1408 | } |
| 1409 | Tag::UInt32_0 | Tag::UInt32_8 | Tag::UInt32_16 | Tag::UInt32_24 | Tag::UInt32_32 => { |
| 1410 | let i = u32::from_le_bytes(read_byte_array_extending_nonnegative( |
no test coverage detected