cassandra_proto/frame/
frame_prepare.rs

1use rand;
2
3use crate::types::*;
4use crate::frame::*;
5
6/// Struct that represents a body of a frame of type `prepare`
7#[derive(Debug)]
8pub struct BodyReqPrepare {
9    query: CStringLong,
10}
11
12impl BodyReqPrepare {
13    /// Creates new body of a frame of type `prepare` that prepares query `query`.
14    pub fn new(query: String) -> BodyReqPrepare {
15        BodyReqPrepare { query: CStringLong::new(query), }
16    }
17}
18
19impl IntoBytes for BodyReqPrepare {
20    fn into_cbytes(&self) -> Vec<u8> {
21        self.query.into_cbytes()
22    }
23}
24
25impl Frame {
26    /// **Note:** This function should be used internally for building query request frames.
27    pub fn new_req_prepare(query: String, flags: Vec<Flag>) -> Frame {
28        let version = Version::Request;
29        let stream = rand::random::<u16>();
30        let opcode = Opcode::Prepare;
31        let body = BodyReqPrepare::new(query);
32
33        Frame { version: version,
34                flags: flags,
35                stream: stream,
36                opcode: opcode,
37                body: body.into_cbytes(),
38                // for request frames it's always None
39                tracing_id: None,
40                warnings: vec![], }
41    }
42}