BlobReader

Struct BlobReader 

Source
pub struct BlobReader { /* private fields */ }
Expand description

Streaming reader for large binary objects (LOBs).

BlobReader implements AsyncRead to provide a streaming interface for reading large objects. Data can be read in chunks without allocating additional buffers for each read operation.

§Example

use mssql_client::blob::BlobReader;
use tokio::io::AsyncReadExt;

let data: Bytes = row.get("binary_column")?;
let mut reader = BlobReader::from_bytes(data);

// Read up to 4KB at a time
let mut buffer = vec![0u8; 4096];
let bytes_read = reader.read(&mut buffer).await?;

Implementations§

Source§

impl BlobReader

Source

pub fn from_bytes(buffer: Bytes) -> Self

Create a new BlobReader from a Bytes buffer.

This is the primary constructor for creating a blob reader from column data retrieved from a query result.

§Example
use bytes::Bytes;
use mssql_client::blob::BlobReader;

let data = Bytes::from_static(b"Hello, World!");
let reader = BlobReader::from_bytes(data);
assert_eq!(reader.len(), Some(13));
Source

pub fn empty() -> Self

Create an empty BlobReader.

Returns a reader with no data that will immediately return EOF.

Source

pub fn from_slice(data: &[u8]) -> Self

Create a BlobReader from a byte slice.

This copies the data into an owned Bytes buffer.

Source

pub fn len(&self) -> Option<u64>

Get the total length of the BLOB in bytes.

Returns Some(length) with the total size of the data. Returns None only for truly streaming implementations where the total length is unknown in advance.

§Example
use bytes::Bytes;
use mssql_client::blob::BlobReader;

let reader = BlobReader::from_bytes(Bytes::from_static(b"test"));
assert_eq!(reader.len(), Some(4));
Source

pub fn is_empty(&self) -> bool

Check if the BLOB is empty.

Returns true if the BLOB contains no data.

§Example
use bytes::Bytes;
use mssql_client::blob::BlobReader;

let empty = BlobReader::empty();
assert!(empty.is_empty());

let non_empty = BlobReader::from_bytes(Bytes::from_static(b"data"));
assert!(!non_empty.is_empty());
Source

pub fn bytes_read(&self) -> u64

Get the number of bytes read so far.

This tracks progress through the BLOB and can be used for progress reporting.

§Example
use bytes::Bytes;
use mssql_client::blob::BlobReader;

let reader = BlobReader::from_bytes(Bytes::from_static(b"Hello"));
assert_eq!(reader.bytes_read(), 0);
Source

pub fn remaining(&self) -> Option<u64>

Get the number of bytes remaining to be read.

Returns Some(remaining) if the total length is known.

Source

pub fn rewind(&mut self)

Reset the reader position to the beginning.

After calling this, bytes_read() will return 0 and subsequent reads will start from the beginning of the data.

Source

pub fn into_bytes(self) -> Bytes

Consume the reader and return the underlying Bytes buffer.

This returns the complete data, including any bytes already read. The buffer is not consumed by reads; it remains complete.

§Example
use bytes::Bytes;
use mssql_client::blob::BlobReader;

let data = Bytes::from_static(b"Hello");
let reader = BlobReader::from_bytes(data.clone());
let recovered = reader.into_bytes();
assert_eq!(recovered, data);
Source

pub fn as_bytes(&self) -> &Bytes

Get a reference to the underlying bytes.

Returns the complete buffer, not just unread bytes.

Source

pub fn unread_slice(&self) -> &[u8]

Get the unread portion as a slice.

Returns a slice of the data that hasn’t been read yet.

Source

pub fn is_exhausted(&self) -> bool

Check if all data has been read.

Returns true if bytes_read() == len().

Trait Implementations§

Source§

impl AsyncRead for BlobReader

Source§

fn poll_read( self: Pin<&mut Self>, _cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll<Result<()>>

Attempts to read from the AsyncRead into buf. Read more
Source§

impl Clone for BlobReader

Source§

fn clone(&self) -> Self

Clone the reader.

The cloned reader shares the underlying Bytes buffer (cheap clone) but has its own position, starting from the beginning.

1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BlobReader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BlobReader

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<&[u8]> for BlobReader

Source§

fn from(slice: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for BlobReader

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Bytes> for BlobReader

Source§

fn from(bytes: Bytes) -> Self

Converts to this type from the input type.
Source§

impl From<String> for BlobReader

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for BlobReader

Source§

fn from(vec: Vec<u8>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<R> AsyncReadExt for R
where R: AsyncRead + ?Sized,

Source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where Self: Sized, R: AsyncRead,

Creates a new AsyncRead instance that chains this stream with next. Read more
Source§

fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>
where Self: Unpin,

Pulls some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Source§

fn read_buf<'a, B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>
where Self: Unpin, B: BufMut + ?Sized,

Pulls some bytes from this source into the specified buffer, advancing the buffer’s internal cursor. Read more
Source§

fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>
where Self: Unpin,

Reads the exact number of bytes required to fill buf. Read more
Source§

fn read_u8(&mut self) -> ReadU8<&mut Self>
where Self: Unpin,

Reads an unsigned 8 bit integer from the underlying reader. Read more
Source§

fn read_i8(&mut self) -> ReadI8<&mut Self>
where Self: Unpin,

Reads a signed 8 bit integer from the underlying reader. Read more
Source§

fn read_u16(&mut self) -> ReadU16<&mut Self>
where Self: Unpin,

Reads an unsigned 16-bit integer in big-endian order from the underlying reader. Read more
Source§

fn read_i16(&mut self) -> ReadI16<&mut Self>
where Self: Unpin,

Reads a signed 16-bit integer in big-endian order from the underlying reader. Read more
Source§

fn read_u32(&mut self) -> ReadU32<&mut Self>
where Self: Unpin,

Reads an unsigned 32-bit integer in big-endian order from the underlying reader. Read more
Source§

fn read_i32(&mut self) -> ReadI32<&mut Self>
where Self: Unpin,

Reads a signed 32-bit integer in big-endian order from the underlying reader. Read more
Source§

fn read_u64(&mut self) -> ReadU64<&mut Self>
where Self: Unpin,

Reads an unsigned 64-bit integer in big-endian order from the underlying reader. Read more
Source§

fn read_i64(&mut self) -> ReadI64<&mut Self>
where Self: Unpin,

Reads an signed 64-bit integer in big-endian order from the underlying reader. Read more
Source§

fn read_u128(&mut self) -> ReadU128<&mut Self>
where Self: Unpin,

Reads an unsigned 128-bit integer in big-endian order from the underlying reader. Read more
Source§

fn read_i128(&mut self) -> ReadI128<&mut Self>
where Self: Unpin,

Reads an signed 128-bit integer in big-endian order from the underlying reader. Read more
Source§

fn read_f32(&mut self) -> ReadF32<&mut Self>
where Self: Unpin,

Reads an 32-bit floating point type in big-endian order from the underlying reader. Read more
Source§

fn read_f64(&mut self) -> ReadF64<&mut Self>
where Self: Unpin,

Reads an 64-bit floating point type in big-endian order from the underlying reader. Read more
Source§

fn read_u16_le(&mut self) -> ReadU16Le<&mut Self>
where Self: Unpin,

Reads an unsigned 16-bit integer in little-endian order from the underlying reader. Read more
Source§

fn read_i16_le(&mut self) -> ReadI16Le<&mut Self>
where Self: Unpin,

Reads a signed 16-bit integer in little-endian order from the underlying reader. Read more
Source§

fn read_u32_le(&mut self) -> ReadU32Le<&mut Self>
where Self: Unpin,

Reads an unsigned 32-bit integer in little-endian order from the underlying reader. Read more
Source§

fn read_i32_le(&mut self) -> ReadI32Le<&mut Self>
where Self: Unpin,

Reads a signed 32-bit integer in little-endian order from the underlying reader. Read more
Source§

fn read_u64_le(&mut self) -> ReadU64Le<&mut Self>
where Self: Unpin,

Reads an unsigned 64-bit integer in little-endian order from the underlying reader. Read more
Source§

fn read_i64_le(&mut self) -> ReadI64Le<&mut Self>
where Self: Unpin,

Reads an signed 64-bit integer in little-endian order from the underlying reader. Read more
Source§

fn read_u128_le(&mut self) -> ReadU128Le<&mut Self>
where Self: Unpin,

Reads an unsigned 128-bit integer in little-endian order from the underlying reader. Read more
Source§

fn read_i128_le(&mut self) -> ReadI128Le<&mut Self>
where Self: Unpin,

Reads an signed 128-bit integer in little-endian order from the underlying reader. Read more
Source§

fn read_f32_le(&mut self) -> ReadF32Le<&mut Self>
where Self: Unpin,

Reads an 32-bit floating point type in little-endian order from the underlying reader. Read more
Source§

fn read_f64_le(&mut self) -> ReadF64Le<&mut Self>
where Self: Unpin,

Reads an 64-bit floating point type in little-endian order from the underlying reader. Read more
Source§

fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>
where Self: Unpin,

Reads all bytes until EOF in this source, placing them into buf. Read more
Source§

fn read_to_string<'a>( &'a mut self, dst: &'a mut String, ) -> ReadToString<'a, Self>
where Self: Unpin,

Reads all bytes until EOF in this source, appending them to buf. Read more
Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adaptor which reads at most limit bytes from it. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more