| Crates.io | mssql-codec |
| lib.rs | mssql-codec |
| version | 0.6.0 |
| created_at | 2025-12-17 22:55:11.721331+00 |
| updated_at | 2026-01-13 22:17:57.372608+00 |
| description | Async TDS packet framing and codec for SQL Server |
| homepage | |
| repository | https://github.com/praxiomlabs/rust-mssql-driver |
| max_upload_size | |
| id | 1991263 |
| size | 58,169 |
Part of the rust-mssql-driver project.
Async framing layer for TDS packet handling.
This crate transforms raw byte streams into high-level TDS packets, handling packet reassembly across TCP segment boundaries and packet continuation for large messages. It sits between the raw TCP/TLS stream and the higher-level client.
TCP Stream -> TdsCodec (packet framing) -> MessageAssembler -> Client
Per ADR-005, the connection splits the TCP stream into read and write halves. This allows sending Attention packets for query cancellation even while blocked reading a large result set.
use mssql_codec::Connection;
let conn = Connection::new(tcp_stream);
let cancel = conn.cancel_handle();
// Cancel from another task
tokio::spawn(async move {
cancel.cancel().await?;
});
This crate is primarily used internally by mssql-client. Direct usage is for advanced scenarios:
use mssql_codec::{TdsCodec, Packet, Message, MessageAssembler};
use tokio_util::codec::Framed;
// Create a framed codec over a TCP stream
let framed = Framed::new(tcp_stream, TdsCodec::new());
// Or use the Connection wrapper for more features
let conn = Connection::new(tcp_stream);
| Module | Description |
|---|---|
connection |
High-level connection with cancel support |
packet_codec |
TDS packet encoding/decoding |
framed |
PacketReader and PacketWriter types |
message |
Multi-packet message assembly |
error |
Codec error types |
| Type | Description |
|---|---|
Connection |
High-level connection with IO splitting |
CancelHandle |
Handle for canceling queries from another task |
TdsCodec |
Tokio codec for TDS packet framing |
Packet |
Single TDS packet |
Message |
Complete TDS message (possibly from multiple packets) |
MessageAssembler |
Assembles packets into complete messages |
+--------+--------+--------+--------+--------+--------+--------+--------+
| Type | Status | Length (2) | SPID (2) | Pkt# | Window |
+--------+--------+--------+--------+--------+--------+--------+--------+
| Payload Data |
| ... |
+-----------------------------------------------------------------------+
MIT OR Apache-2.0