pub enum Endianness {
Little,
Big,
}Expand description
Endianness. Either big or little.
Variants§
Implementations§
Source§impl Endianness
impl Endianness
Sourcepub fn native() -> Endianness
pub fn native() -> Endianness
Returns the native endianness of the CPU.
Examples found in repository?
examples/custom_data_type_fixed_size.rs (line 222)
216 fn encode<'a>(
217 &self,
218 bytes: std::borrow::Cow<'a, [u8]>,
219 endianness: Option<zarrs_metadata::Endianness>,
220 ) -> Result<std::borrow::Cow<'a, [u8]>, BytesCodecEndiannessMissingError> {
221 if let Some(endianness) = endianness {
222 if endianness != Endianness::native() {
223 let mut bytes = bytes.into_owned();
224 for bytes in bytes
225 .as_chunks_mut::<{ size_of::<CustomDataTypeFixedSizeBytes>() }>()
226 .0
227 {
228 let value = CustomDataTypeFixedSizeElement::from_ne_bytes(bytes);
229 if endianness == Endianness::Little {
230 *bytes = value.to_le_bytes();
231 } else {
232 *bytes = value.to_be_bytes();
233 }
234 }
235 Ok(Cow::Owned(bytes))
236 } else {
237 Ok(bytes)
238 }
239 } else {
240 Err(BytesCodecEndiannessMissingError)
241 }
242 }
243
244 fn decode<'a>(
245 &self,
246 bytes: std::borrow::Cow<'a, [u8]>,
247 endianness: Option<zarrs_metadata::Endianness>,
248 ) -> Result<std::borrow::Cow<'a, [u8]>, BytesCodecEndiannessMissingError> {
249 if let Some(endianness) = endianness {
250 if endianness != Endianness::native() {
251 let mut bytes = bytes.into_owned();
252 for bytes in bytes
253 .as_chunks_mut::<{ size_of::<u64>() + size_of::<f32>() }>()
254 .0
255 {
256 let value = if endianness == Endianness::Little {
257 CustomDataTypeFixedSizeElement::from_le_bytes(bytes)
258 } else {
259 CustomDataTypeFixedSizeElement::from_be_bytes(bytes)
260 };
261 *bytes = value.to_ne_bytes();
262 }
263 Ok(Cow::Owned(bytes))
264 } else {
265 Ok(bytes)
266 }
267 } else {
268 Err(BytesCodecEndiannessMissingError)
269 }
270 }Trait Implementations§
Source§impl Clone for Endianness
impl Clone for Endianness
Source§fn clone(&self) -> Endianness
fn clone(&self) -> Endianness
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Endianness
impl Debug for Endianness
Source§impl<'de> Deserialize<'de> for Endianness
impl<'de> Deserialize<'de> for Endianness
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Endianness, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Endianness, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for Endianness
impl Display for Endianness
Source§impl PartialEq for Endianness
impl PartialEq for Endianness
Source§impl Serialize for Endianness
impl Serialize for Endianness
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Copy for Endianness
impl Eq for Endianness
impl StructuralPartialEq for Endianness
Auto Trait Implementations§
impl Freeze for Endianness
impl Send for Endianness
impl Sync for Endianness
impl RefUnwindSafe for Endianness
impl Unpin for Endianness
impl UnsafeUnpin for Endianness
impl UnwindSafe for Endianness
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more