cassandra_proto/frame/
frame_execute.rs

1use rand;
2
3use crate::types::*;
4use crate::frame::*;
5use crate::query::QueryParams;
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 { id: id,
21                         query_parameters: query_parameters, }
22    }
23}
24
25impl<'a> IntoBytes for BodyReqExecute<'a> {
26    fn into_cbytes(&self) -> Vec<u8> {
27        let mut v: Vec<u8> = vec![];
28        v.extend_from_slice(self.id.into_cbytes().as_slice());
29        v.extend_from_slice(self.query_parameters.into_cbytes().as_slice());
30        v
31    }
32}
33
34impl Frame {
35    /// **Note:** This function should be used internally for building query request frames.
36    pub fn new_req_execute(id: &CBytesShort,
37                           query_parameters: QueryParams,
38                           flags: Vec<Flag>)
39                           -> Frame {
40        let version = Version::Request;
41        let stream = rand::random::<u16>();
42        let opcode = Opcode::Execute;
43        debug!("prepared statement id{:?} getting executed  with parameters  {:?}",
44               id, query_parameters);
45        let body = BodyReqExecute::new(id, query_parameters);
46
47        Frame { version: version,
48                flags: flags,
49                stream: stream,
50                opcode: opcode,
51                body: body.into_cbytes(),
52                // for request frames it's always None
53                tracing_id: None,
54                warnings: vec![], }
55    }
56}