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
use types::*;
use super::*;
use super::super::IntoBytes;

/// Struct that represents a body of a frame of type `prepare`
pub struct BodyReqPrepare {
    query: CStringLong
}

impl BodyReqPrepare {
    /// Creates new body of a frame of type `prepare` that prepares query `query`.
    pub fn new(query: String) -> BodyReqPrepare {
        return BodyReqPrepare {
            query: CStringLong::new(query)
        }
    }
}

impl IntoBytes for BodyReqPrepare {
    fn into_cbytes(&self) -> Vec<u8> {
        return self.query.into_cbytes();
    }
}

impl Frame {
    /// **Note:** This function should be used internally for building query request frames.
    pub fn new_req_prepare(query: String, flags: Vec<Flag>) -> Frame {
        let version = Version::Request;
        // sync client
        let stream: u64 = 0;
        let opcode = Opcode::Prepare;
        let body = BodyReqPrepare::new(query);

        return Frame {
            version: version,
            flags: flags,
            stream: stream,
            opcode: opcode,
            body: body.into_cbytes(),
            // for request frames it's always None
            tracing_id: None,
            warnings: vec![]
        };
    }
}