This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f6d522
commit 2493f7d
Showing
11 changed files
with
30 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#![deny(missing_docs)] | ||
#![forbid(unsafe_code)] | ||
//! Read and write from and to Apache Avro | ||
|
||
pub mod read; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,17 @@ | ||
use crate::trusted_len::TrustedLen; | ||
|
||
use std::{convert::TryInto, hint::unreachable_unchecked}; | ||
use std::convert::TryInto; | ||
|
||
use parquet2::types::NativeType; | ||
|
||
pub struct ExactChunksIter<'a, T: NativeType> { | ||
chunks: std::slice::ChunksExact<'a, u8>, | ||
phantom: std::marker::PhantomData<T>, | ||
} | ||
|
||
impl<'a, T: NativeType> ExactChunksIter<'a, T> { | ||
#[inline] | ||
pub fn new(slice: &'a [u8]) -> Self { | ||
assert_eq!(slice.len() % std::mem::size_of::<T>(), 0); | ||
let chunks = slice.chunks_exact(std::mem::size_of::<T>()); | ||
Self { | ||
chunks, | ||
phantom: std::marker::PhantomData, | ||
} | ||
} | ||
} | ||
|
||
impl<'a, T: NativeType> Iterator for ExactChunksIter<'a, T> { | ||
type Item = T; | ||
|
||
#[inline] | ||
fn next(&mut self) -> Option<Self::Item> { | ||
self.chunks.next().map(|chunk| { | ||
let chunk: <T as NativeType>::Bytes = match chunk.try_into() { | ||
Ok(v) => v, | ||
Err(_) => unsafe { unreachable_unchecked() }, | ||
}; | ||
T::from_le_bytes(chunk) | ||
}) | ||
} | ||
use crate::trusted_len::TrustedLen; | ||
|
||
#[inline] | ||
fn size_hint(&self) -> (usize, Option<usize>) { | ||
self.chunks.size_hint() | ||
} | ||
pub fn chunks<T: NativeType>(bytes: &[u8]) -> impl TrustedLen<Item = T> + '_ { | ||
assert_eq!(bytes.len() % std::mem::size_of::<T>(), 0); | ||
let chunks = bytes.chunks_exact(std::mem::size_of::<T>()); | ||
chunks.map(|chunk| { | ||
let chunk: <T as NativeType>::Bytes = match chunk.try_into() { | ||
Ok(v) => v, | ||
Err(_) => unreachable!(), | ||
}; | ||
T::from_le_bytes(chunk) | ||
}) | ||
} | ||
|
||
unsafe impl<'a, T: NativeType> TrustedLen for ExactChunksIter<'a, T> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters