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>
sourcefn new(buf: &'a [u8]) -> Cursor<'_>
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.
sourcefn read_byte(&mut self) -> Result<u8, Error>
fn read_byte(&mut self) -> Result<u8, Error>
Returns the next byte, advancing the cursor by one byte.
sourcefn read_cstr(&mut self) -> Result<&'a str, Error>
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.
sourcefn read_i16(&mut self) -> Result<i16, Error>
fn read_i16(&mut self) -> Result<i16, Error>
Reads the next 16-bit signed integer, advancing the cursor by two bytes.
sourcefn read_i32(&mut self) -> Result<i32, Error>
fn read_i32(&mut self) -> Result<i32, Error>
Reads the next 32-bit signed integer, advancing the cursor by four bytes.
sourcefn read_u32(&mut self) -> Result<u32, Error>
fn read_u32(&mut self) -> Result<u32, Error>
Reads the next 32-bit unsigned integer, advancing the cursor by four bytes.
sourcefn read_format(&mut self) -> Result<Format, Error>
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> 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
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
impl<P, R> ProtoType<R> for Pwhere R: RustType<P>,
source§fn into_rust(self) -> Result<R, TryFromProtoError>
fn into_rust(self) -> Result<R, TryFromProtoError>
RustType::from_proto
.source§fn from_rust(rust: &R) -> P
fn from_rust(rust: &R) -> P
RustType::into_proto
.