Skip to main content

TvpEncoder

Struct TvpEncoder 

Source
pub struct TvpEncoder<'a> {
    pub schema: &'a str,
    pub type_name: &'a str,
    pub columns: &'a [TvpColumnDef],
}
Expand description

TVP value encoder.

This provides the complete TVP encoding logic for RPC parameters.

Fields§

§schema: &'a str

Database schema (e.g., “dbo”). Empty for default.

§type_name: &'a str

Type name as defined in the database.

§columns: &'a [TvpColumnDef]

Column definitions.

Implementations§

Source§

impl<'a> TvpEncoder<'a>

Source

pub const fn new( schema: &'a str, type_name: &'a str, columns: &'a [TvpColumnDef], ) -> Self

Create a new TVP encoder.

Source

pub fn encode_metadata(&self, buf: &mut BytesMut)

Encode the complete TVP type info and metadata.

This encodes:

  • TVP type ID (0xF3)
  • TVP_TYPENAME (DbName, OwningSchema, TypeName)
  • TVP_COLMETADATA
  • TVP_END_TOKEN (marks end of column metadata)

After calling this, use Self::encode_row for each row, then Self::encode_end to finish.

String columns are declared with the default Latin1_General_CI_AS collation; use Self::encode_metadata_with_collation to declare the server’s actual collation.

Source

pub fn encode_metadata_with_collation( &self, buf: &mut BytesMut, collation: Option<&Collation>, )

Encode the complete TVP type info and metadata, declaring collation for string columns.

Pass the collation captured from the login ENVCHANGE so VARCHAR cell bytes (encoded with the same collation) are interpreted in the right codepage by the server.

Source

pub fn encode_row<F>(&self, buf: &mut BytesMut, encode_values: F)
where F: FnOnce(&mut BytesMut),

Encode a TVP row.

§Arguments
  • encode_values - A closure that encodes the column values into the buffer. Each value should be encoded according to its type (similar to RPC param encoding).
Source

pub fn encode_end(&self, buf: &mut BytesMut)

Encode the TVP end marker.

This must be called after all rows have been encoded.

Trait Implementations§

Source§

impl<'a> Debug for TvpEncoder<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for TvpEncoder<'a>

§

impl<'a> RefUnwindSafe for TvpEncoder<'a>

§

impl<'a> Send for TvpEncoder<'a>

§

impl<'a> Sync for TvpEncoder<'a>

§

impl<'a> Unpin for TvpEncoder<'a>

§

impl<'a> UnsafeUnpin for TvpEncoder<'a>

§

impl<'a> UnwindSafe for TvpEncoder<'a>

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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.