tustvold commented on code in PR #3578:
URL: https://github.com/apache/arrow-rs/pull/3578#discussion_r1082671978


##########
parquet/src/util/bit_util.rs:
##########
@@ -17,76 +17,104 @@
 
 use std::{cmp, mem::size_of};
 
-use crate::data_type::AsBytes;
+use crate::data_type::{AsBytes, ByteArray, FixedLenByteArray, Int96};
+use crate::errors::{ParquetError, Result};
 use crate::util::bit_pack::{unpack16, unpack32, unpack64, unpack8};
 use crate::util::memory::ByteBufferPtr;
 
 #[inline]
-pub fn from_ne_slice<T: FromBytes>(bs: &[u8]) -> T {
-    let mut b = T::Buffer::default();
-    {
-        let b = b.as_mut();
-        let bs = &bs[..b.len()];
-        b.copy_from_slice(bs);
-    }
-    T::from_ne_bytes(b)
+pub fn from_le_slice<T: FromBytes>(bs: &[u8]) -> T {
+    // TODO: propagate the error (#3577)
+    T::try_from_le_slice(bs).unwrap()
 }
 
 #[inline]
-pub fn from_le_slice<T: FromBytes>(bs: &[u8]) -> T {
-    let mut b = T::Buffer::default();
-    {
-        let b = b.as_mut();
-        let bs = &bs[..b.len()];
-        b.copy_from_slice(bs);
+fn array_from_slice<const N: usize>(bs: &[u8]) -> Result<[u8; N]> {
+    // Need to slice as may be called with zero-padded values
+    match bs.get(..N) {
+        Some(b) => Ok(b.try_into().unwrap()),
+        None => Err(general_err!(
+            "error converting value, expected {} bytes got {}",
+            N,
+            bs.len()
+        )),
     }
-    T::from_le_bytes(b)
 }
 
 pub trait FromBytes: Sized {

Review Comment:
   Note: this trait is not part of the public API



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to