Struct pgwire::codec::Cursor[][src]

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 malformatted pgwire messages.

There are also some special-purpose methods, like Cursor::read_cstr, that are specific to pgwire messages.

Fields

buf: &'a [u8]

Implementations

Constructs a new Cursor from a byte slice. The cursor will begin decoding from the beginning of the slice.

Returns the next byte without advancing the cursor.

Returns the next byte, advancing the cursor by one byte.

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.

Reads the next 16-bit signed integer, advancing the cursor by two bytes.

Reads the next 32-bit signed integer, advancing the cursor by four bytes.

Reads the next 32-bit unsigned integer, advancing the cursor by four bytes.

Reads the next 16-bit format code, advancing the cursor by two bytes.

Advances the cursor by n bytes.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

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

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

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

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