#[repr(C)]pub struct ByteView {
pub length: u32,
pub prefix: u32,
pub buffer_index: u32,
pub offset: u32,
}
Expand description
Helper to access views of GenericByteViewArray
(StringViewArray
and
BinaryViewArray
) where the length is greater than 12 bytes.
See Also:
GenericByteViewArray
for more information on the layout of the views.validate_binary_view
andvalidate_string_view
to validate
§Example: Create a new u128 view
// Create a view for a string of length 20
// first four bytes are "Rust"
// stored in buffer 3
// at offset 42
let prefix = "Rust";
let view = ByteView::new(20, prefix.as_bytes())
.with_buffer_index(3)
.with_offset(42);
// create the final u128
let v = view.as_u128();
assert_eq!(v, 0x2a000000037473755200000014);
§Example: decode a u128
into its constituent fields
// Convert a u128 to a ByteView
// See validate_{string,binary}_view functions to validate
let v = ByteView::from(0x2a000000037473755200000014);
assert_eq!(v.length, 20);
assert_eq!(v.prefix, 0x74737552);
assert_eq!(v.buffer_index, 3);
assert_eq!(v.offset, 42);
Fields§
§length: u32
The length of the string/bytes.
prefix: u32
First 4 bytes of string/bytes data.
buffer_index: u32
The buffer index.
offset: u32
The offset into the buffer.
Implementations§
Source§impl ByteView
impl ByteView
Sourcepub fn with_buffer_index(self, buffer_index: u32) -> Self
pub fn with_buffer_index(self, buffer_index: u32) -> Self
Set the Self::buffer_index
field
Sourcepub fn with_offset(self, offset: u32) -> Self
pub fn with_offset(self, offset: u32) -> Self
Set the Self::offset
field
Trait Implementations§
impl Copy for ByteView
Auto Trait Implementations§
impl Freeze for ByteView
impl RefUnwindSafe for ByteView
impl Send for ByteView
impl Sync for ByteView
impl Unpin for ByteView
impl UnwindSafe for ByteView
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