[−][src]Struct kekbit::core::ShmReader
An implementation of the Reader which access a persistent channel through
memory mapping. A ShmReader
must be created using the shm_reader function.
Examples
use kekbit_core::shm::*; let writer_id = 1850; let channel_id = 42; let test_tmp_dir = tempdir::TempDir::new("kektest").unwrap(); let reader = shm_reader(&test_tmp_dir.path(), channel_id).unwrap(); println!("{:?}", reader.header());
Methods
impl ShmReader
[src]
pub fn header(&self) -> &Header
[src]
Returns a reference to the Header associated with this channel
pub fn position(&self) -> u32
[src]
Returns the current read position. It could be the total
amount of bytes read
so far(including bytes from record headers and the one used for record padding) if
no succesfull move_to operation was executed on this reader.
Trait Implementations
impl Debug for ShmReader
[src]
impl Reader for ShmReader
[src]
fn read(
&mut self,
handler: &mut impl FnMut(u32, &[u8]),
message_count: u16
) -> Result<u32, ReadError>
[src]
&mut self,
handler: &mut impl FnMut(u32, &[u8]),
message_count: u16
) -> Result<u32, ReadError>
Reads up to message_count
messages from the channel and for each message
calls the given handler. The handler it is not
called for heartbeat
messages.
This operation is non-blocking, if you want to wait for a message to be available, external
wait/spin mechanisms must be used.
Returns the amount of bytes read together and/or an error. Even if an error occurred there may have been messages which were correctly read, and for which the handler was called.
Arguments
handler
- The function which will be called every time a valid messages is read from the channel. The message is just binary data, it's up to the handler to interpret it properly.message_count
- Themaximum
number of messages to be read on this call.
Errors
Various errors may occur such: a writer
timeout is detected, end of channel is reached, channel is closed or channel data is corrupted.
However even in such situations, some valid records may have been processed.
Examples
use kekbit_core::shm::*; use crate::kekbit_core::api::Reader; let writer_id = 1850; let channel_id = 42; let test_tmp_dir = tempdir::TempDir::new("kektest").unwrap(); let mut reader = shm_reader(&test_tmp_dir.path(), channel_id).unwrap(); reader.read(&mut |pos,buf| println!("{}->{}",pos, std::str::from_utf8(buf).unwrap()), 10).unwrap();
fn move_to(&mut self, position: u32) -> Result<u32, InvalidPosition>
[src]
Tries to move this reader to a given position if it is valid.
Returns the position itself if the operation was successful otherwise some error.
Arguments
position
- Position where will try to point this reader. It must be a valid position on the channel
Errors
///
Examples
use kekbit_core::shm::*; use crate::kekbit_core::api::Reader; let writer_id = 1850; let channel_id = 42; let test_tmp_dir = tempdir::TempDir::new("kektest").unwrap(); let mut reader = shm_reader(&test_tmp_dir.path(), channel_id).unwrap(); reader.read(&mut |pos,buf| println!("{}->{}",pos, std::str::from_utf8(buf).unwrap()), 10).unwrap(); reader.move_to(0);//start reading from beginning again
Auto Trait Implementations
impl RefUnwindSafe for ShmReader
impl !Send for ShmReader
impl !Sync for ShmReader
impl Unpin for ShmReader
impl UnwindSafe for ShmReader
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,