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
use crate::frame::*;
use crate::query::QueryParams;
use crate::types::*;

/// The structure that represents a body of a frame of type `execute`.
#[derive(Debug)]
pub struct BodyReqExecute<'a> {
    /// Id of prepared query
    id: &'a CBytesShort,
    /// Query paramaters which have the same meaning as one for `query`
    /// TODO: clarify if it is QueryParams or its shortened variant
    query_parameters: QueryParams,
}

impl<'a> BodyReqExecute<'a> {
    /// The method which creates new instance of `BodyReqExecute`
    pub fn new(id: &CBytesShort, query_parameters: QueryParams) -> BodyReqExecute {
        BodyReqExecute {
            id: id,
            query_parameters: query_parameters,
        }
    }
}

impl<'a> IntoBytes for BodyReqExecute<'a> {
    fn into_cbytes(&self) -> Vec<u8> {
        let mut v: Vec<u8> = vec![];
        v.extend_from_slice(self.id.into_cbytes().as_slice());
        v.extend_from_slice(self.query_parameters.into_cbytes().as_slice());
        v
    }
}

impl Frame {
    /// **Note:** This function should be used internally for building query request frames.
    pub fn new_req_execute(
        id: &CBytesShort,
        query_parameters: QueryParams,
        flags: Vec<Flag>,
    ) -> Frame {
        let version = Version::Request;
        let opcode = Opcode::Execute;
        debug!(
            "prepared statement id{:?} getting executed with parameters {:?}",
            id, query_parameters
        );
        let body = BodyReqExecute::new(id, query_parameters);

        Frame::new(version, flags, opcode, body.into_cbytes(), None, vec![])
    }
}