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 strDatabase schema (e.g., “dbo”). Empty for default.
type_name: &'a strType name as defined in the database.
columns: &'a [TvpColumnDef]Column definitions.
Implementations§
Source§impl<'a> TvpEncoder<'a>
impl<'a> TvpEncoder<'a>
Sourcepub const fn new(
schema: &'a str,
type_name: &'a str,
columns: &'a [TvpColumnDef],
) -> Self
pub const fn new( schema: &'a str, type_name: &'a str, columns: &'a [TvpColumnDef], ) -> Self
Create a new TVP encoder.
Sourcepub fn encode_metadata(&self, buf: &mut BytesMut)
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.
Sourcepub fn encode_metadata_with_collation(
&self,
buf: &mut BytesMut,
collation: Option<&Collation>,
)
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.
Sourcepub fn encode_row<F>(&self, buf: &mut BytesMut, encode_values: F)
pub fn encode_row<F>(&self, buf: &mut BytesMut, encode_values: F)
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).
Sourcepub fn encode_end(&self, buf: &mut BytesMut)
pub fn encode_end(&self, buf: &mut BytesMut)
Encode the TVP end marker.
This must be called after all rows have been encoded.