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

Method process_from_bytes_key

crates/table/src/table_index/bytes_key.rs:502–538  ·  view source on GitHub ↗
(mut slice: &'a mut [u8], ty: &AlgebraicType)

Source from the content-addressed store, hash-verified

500 }
501
502 fn process_from_bytes_key<'a>(mut slice: &'a mut [u8], ty: &AlgebraicType) -> &'a mut [u8] {
503 use AlgebraicType::*;
504 match ty {
505 // For sums, read the tag and process the active variant.
506 Sum(ty) => {
507 let (&mut tag, rest) = slice.split_first_mut().unwrap();
508 let ty = &ty.variants[tag as usize].algebraic_type;
509 Self::process_from_bytes_key(rest, ty)
510 }
511 // For products, just process each field in sequence.
512 Product(ty) => {
513 for ty in &ty.elements {
514 slice = Self::process_from_bytes_key(slice, &ty.algebraic_type);
515 }
516 slice
517 }
518 // No need to do anything as these are only a single byte long.
519 Bool | U8 => &mut slice[1..],
520 // For unsigned integers, read them as LE and write back as BE.
521 U16 => split_map_write_back(slice, |b| u16::from_le_bytes(b).to_be_bytes()),
522 U32 => split_map_write_back(slice, |b| u32::from_le_bytes(b).to_be_bytes()),
523 U64 => split_map_write_back(slice, |b| u64::from_le_bytes(b).to_be_bytes()),
524 U128 => split_map_write_back(slice, |b| u128::from_le_bytes(b).to_be_bytes()),
525 U256 => split_map_write_back(slice, |b| u256::from_le_bytes(b).to_be_bytes()),
526 // For signed integers, read them as LE, make them unsigned, and write back as BE.
527 I8 => split_map_write_back(slice, |b| i8::from_le_bytes(b).wrapping_sub(i8::MIN).to_be_bytes()),
528 I16 => split_map_write_back(slice, |b| i16::from_le_bytes(b).wrapping_sub(i16::MIN).to_be_bytes()),
529 I32 => split_map_write_back(slice, |b| i32::from_le_bytes(b).wrapping_sub(i32::MIN).to_be_bytes()),
530 I64 => split_map_write_back(slice, |b| i64::from_le_bytes(b).wrapping_sub(i64::MIN).to_be_bytes()),
531 I128 => split_map_write_back(slice, |b| i128::from_le_bytes(b).wrapping_sub(i128::MIN).to_be_bytes()),
532 I256 => split_map_write_back(slice, |b| i256::from_le_bytes(b).wrapping_sub(i256::MIN).to_be_bytes()),
533 // Refs don't exist here and
534 // arrays and strings are of unbounded length.
535 // For floats, we haven't considred them yet.
536 Ref(_) | Array(_) | String | F32 | F64 => unreachable!(),
537 }
538 }
539
540 fn to_bytes_key(key: Self, ty: &AlgebraicType) -> BytesKey<N> {
541 fn process<'a>(mut slice: &'a mut [u8], ty: &AlgebraicType) -> &'a mut [u8] {

Callers

nothing calls this directly

Calls 3

split_map_write_backFunction · 0.85
wrapping_subMethod · 0.80
unwrapMethod · 0.45

Tested by

no test coverage detected