tiberius/tds/codec/column_data/
var_len.rs
1use crate::{sql_read_bytes::SqlReadBytes, tds::codec::VarLenContext, ColumnData, VarLenType};
2
3pub(crate) async fn decode<R>(
4 src: &mut R,
5 ctx: &VarLenContext,
6) -> crate::Result<ColumnData<'static>>
7where
8 R: SqlReadBytes + Unpin,
9{
10 use VarLenType::*;
11
12 let ty = ctx.r#type();
13 let len = ctx.len();
14 let collation = ctx.collation();
15
16 let res = match ty {
17 Bitn => super::bit::decode(src).await?,
18 Intn => super::int::decode(src, len).await?,
19 Floatn => super::float::decode(src, len).await?,
20 Guid => super::guid::decode(src).await?,
21 BigChar | BigVarChar | NChar | NVarchar => {
22 ColumnData::String(super::string::decode(src, ty, len, collation).await?)
23 }
24 Money => {
25 let len = src.read_u8().await?;
26 super::money::decode(src, len).await?
27 }
28 Datetimen => {
29 let rlen = src.read_u8().await?;
30 super::datetimen::decode(src, rlen, len as u8).await?
31 }
32 #[cfg(feature = "tds73")]
33 Daten => super::date::decode(src).await?,
34 #[cfg(feature = "tds73")]
35 Timen => super::time::decode(src, len).await?,
36 #[cfg(feature = "tds73")]
37 Datetime2 => super::datetime2::decode(src, len).await?,
38 #[cfg(feature = "tds73")]
39 DatetimeOffsetn => super::datetimeoffsetn::decode(src, len).await?,
40 BigBinary | BigVarBin => super::binary::decode(src, len).await?,
41 Text => super::text::decode(src, collation).await?,
42 NText => super::text::decode(src, None).await?,
43 Image => super::image::decode(src).await?,
44 t => unimplemented!("{:?}", t),
45 };
46
47 Ok(res)
48}