Struct mz_pgwire_common::Cursor
source · pub struct Cursor<'a> {
buf: &'a [u8],
}
Expand description
Decodes data within pgwire messages.
The API provided is very similar to bytes::Buf
, but operations return
errors rather than panicking. This is important for safety, as we don’t want
to crash if the user sends us malformed pgwire messages.
There are also some special-purpose methods, like Cursor::read_cstr
,
that are specific to pgwire messages.
Fields§
§buf: &'a [u8]
Implementations§
source§impl<'a> Cursor<'a>
impl<'a> Cursor<'a>
sourcepub fn new(buf: &'a [u8]) -> Cursor<'_>
pub fn new(buf: &'a [u8]) -> Cursor<'_>
Constructs a new Cursor
from a byte slice. The cursor will begin
decoding from the beginning of the slice.
sourcepub fn peek_byte(&self) -> Result<u8, Error>
pub fn peek_byte(&self) -> Result<u8, Error>
Returns the next byte without advancing the cursor.
sourcepub fn read_byte(&mut self) -> Result<u8, Error>
pub fn read_byte(&mut self) -> Result<u8, Error>
Returns the next byte, advancing the cursor by one byte.
sourcepub fn read_cstr(&mut self) -> Result<&'a str, Error>
pub fn read_cstr(&mut self) -> Result<&'a str, Error>
Returns the next null-terminated string. The null character is not included the returned string. The cursor is advanced past the null- terminated string.
If there is no null byte remaining in the string, returns
CodecError::StringNoTerminator
. If the string is not valid UTF-8,
returns an io::Error
with an error kind of
io::ErrorKind::InvalidInput
.
NOTE(benesch): it is possible that returning a string here is wrong, and we should be returning bytes, so that we can support messages that are not UTF-8 encoded. At the moment, we’ve not discovered a need for this, though, and using proper strings is convenient.
sourcepub fn read_i16(&mut self) -> Result<i16, Error>
pub fn read_i16(&mut self) -> Result<i16, Error>
Reads the next 16-bit signed integer, advancing the cursor by two bytes.
sourcepub fn read_i32(&mut self) -> Result<i32, Error>
pub fn read_i32(&mut self) -> Result<i32, Error>
Reads the next 32-bit signed integer, advancing the cursor by four bytes.
sourcepub fn read_u32(&mut self) -> Result<u32, Error>
pub fn read_u32(&mut self) -> Result<u32, Error>
Reads the next 32-bit unsigned integer, advancing the cursor by four bytes.
sourcepub fn read_format(&mut self) -> Result<Format, Error>
pub fn read_format(&mut self) -> Result<Format, Error>
Reads the next 16-bit format code, advancing the cursor by two bytes.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Cursor<'a>
impl<'a> RefUnwindSafe for Cursor<'a>
impl<'a> Send for Cursor<'a>
impl<'a> Sync for Cursor<'a>
impl<'a> Unpin for Cursor<'a>
impl<'a> UnwindSafe for Cursor<'a>
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
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request