Skip to content

Commit

Permalink
Change where we enforce endianness
Browse files Browse the repository at this point in the history
  • Loading branch information
westonpace committed Nov 13, 2024
1 parent 2e43b23 commit 7d8a714
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rust/lance-encoding/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ impl LanceBuffer {
/// Reinterprets a LanceBuffer into a Vec<T>
///
/// If the underlying buffer is not properly aligned, this will involve a copy of the data
#[cfg(target_endian = "little")]
///
/// Note: doing this sort of re-interpretation generally makes assumptions about the endianness
/// of the data. Lance does not support big-endian machines so this is safe. However, if we end
/// up supporting big-endian machines in the future, then any use of this method will need to be
/// carefully reviewed.
pub fn borrow_to_typed_slice<T: ArrowNativeType>(&mut self) -> impl AsRef<[T]> {
let align = std::mem::align_of::<T>();
let is_aligned = self.as_ptr().align_offset(align) == 0;
Expand Down
6 changes: 6 additions & 0 deletions rust/lance-encoding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ pub mod statistics;
pub mod testing;
pub mod version;

// We can definitely add support for big-endian machines someday. However, it's not a priority and
// would involve extensive testing (probably through emulation) to ensure that the encodings are
// correct.
#[cfg(not(target_endian = "little"))]
compile_error!("Lance encodings only support little-endian systems.");

/// A trait for an I/O service
///
/// This represents the I/O API that the encoders and decoders need in order to operate.
Expand Down

0 comments on commit 7d8a714

Please sign in to comment.