1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use crate::conn::AmConnCore;
use crate::protocol::parts::hdb_value::HdbValue;
use crate::protocol::parts::parameter_descriptor::ParameterDescriptor;
use crate::protocol::parts::parameter_descriptor::ParameterDescriptors;
use crate::protocol::util;
use crate::serde_db_impl::de::DeserializableOutputParameters;
use crate::HdbResult;
use serde_db::de::DeserializableRow;
#[derive(Debug)]
pub struct OutputParameters {
descriptors: Vec<ParameterDescriptor>,
values: Vec<HdbValue<'static>>,
}
impl OutputParameters {
pub fn try_into<'de, T>(self) -> HdbResult<T>
where
T: serde::de::Deserialize<'de>,
{
trace!("OutputParameters::into_typed()");
Ok(DeserializableRow::into_typed(
DeserializableOutputParameters::new(self),
)?)
}
pub fn descriptors(&self) -> &Vec<ParameterDescriptor> {
&(self.descriptors)
}
pub fn into_values(self) -> Vec<HdbValue<'static>> {
self.values
}
pub fn into_descriptors_and_values(self) -> (Vec<ParameterDescriptor>, Vec<HdbValue<'static>>) {
(self.descriptors, self.values)
}
pub(crate) fn parse(
o_am_conn_core: Option<&AmConnCore>,
parameter_descriptors: &ParameterDescriptors,
rdr: &mut dyn std::io::Read,
) -> std::io::Result<Self> {
trace!("OutputParameters::parse()");
let am_conn_core = o_am_conn_core
.ok_or_else(|| util::io_error("Cannot parse output parameters without am_conn_core"))?;
let mut descriptors = Vec::<ParameterDescriptor>::new();
let mut values = Vec::<HdbValue<'static>>::new();
for descriptor in parameter_descriptors.iter_out() {
trace!("Parsing value with descriptor {}", descriptor);
let value = HdbValue::parse_from_reply(
descriptor.type_id(),
descriptor.is_array_type(),
descriptor.scale(),
descriptor.is_nullable(),
am_conn_core,
&None,
rdr,
)?;
trace!("Found value {:?}", value);
descriptors.push(descriptor.clone());
values.push(value);
}
Ok(Self {
descriptors,
values,
})
}
}
impl std::fmt::Display for OutputParameters {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
writeln!(fmt)?;
for parameter_descriptor in &self.descriptors {
write!(fmt, "{}, ", parameter_descriptor.name().unwrap_or(""))?;
}
writeln!(fmt)?;
for value in &self.values {
write!(fmt, "{}, ", value)?;
}
writeln!(fmt)?;
Ok(())
}
}