Skip to main content

cdrs/frame/
frame_execute.rs

1use rand;
2
3use crate::frame::*;
4use crate::query::QueryParams;
5use crate::types::*;
6
7/// The structure that represents a body of a frame of type `execute`.
8#[derive(Debug)]
9pub struct BodyReqExecute<'a> {
10    /// Id of prepared query
11    id: &'a CBytesShort,
12    /// Query paramaters which have the same meaning as one for `query`
13    /// TODO: clarify if it is QueryParams or its shortened variant
14    query_parameters: QueryParams,
15}
16
17impl<'a> BodyReqExecute<'a> {
18    /// The method which creates new instance of `BodyReqExecute`
19    pub fn new(id: &CBytesShort, query_parameters: QueryParams) -> BodyReqExecute {
20        BodyReqExecute {
21            id: id,
22            query_parameters: query_parameters,
23        }
24    }
25}
26
27impl<'a> IntoBytes for BodyReqExecute<'a> {
28    fn into_cbytes(&self) -> Vec<u8> {
29        let mut v: Vec<u8> = vec![];
30        v.extend_from_slice(self.id.into_cbytes().as_slice());
31        v.extend_from_slice(self.query_parameters.into_cbytes().as_slice());
32        v
33    }
34}
35
36impl Frame {
37    /// **Note:** This function should be used internally for building query request frames.
38    pub fn new_req_execute(
39        id: &CBytesShort,
40        query_parameters: QueryParams,
41        flags: Vec<Flag>,
42    ) -> Frame {
43        let version = Version::Request;
44        let stream = rand::random::<u16>();
45        let opcode = Opcode::Execute;
46        debug!(
47            "prepared statement id{:?} getting executed with parameters {:?}",
48            id, query_parameters
49        );
50        let body = BodyReqExecute::new(id, query_parameters);
51
52        Frame {
53            version: version,
54            flags: flags,
55            stream: stream,
56            opcode: opcode,
57            body: body.into_cbytes(),
58            // for request frames it's always None
59            tracing_id: None,
60            warnings: vec![],
61        }
62    }
63}