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
52
53
54
55
56
57
58
59
60
use crate::cassandra::error::*;
use crate::cassandra::util::Protected;
use crate::cassandra_sys::cass_custom_payload_free;
use crate::cassandra_sys::cass_custom_payload_new;
use crate::cassandra_sys::cass_custom_payload_set;
use crate::cassandra_sys::cass_custom_payload_set_n;
use crate::cassandra_sys::CassCustomPayload as _CassCustomPayload;
use std::collections::HashMap;
use std::os::raw::c_char;
pub type CustomPayloadResponse = HashMap<String, Vec<u8>>;
#[derive(Debug)]
pub struct CustomPayload(*mut _CassCustomPayload);
unsafe impl Send for CustomPayload {}
impl Protected<*mut _CassCustomPayload> for CustomPayload {
fn inner(&self) -> *mut _CassCustomPayload {
self.0
}
fn build(inner: *mut _CassCustomPayload) -> Self {
if inner.is_null() {
panic!("Unexpected null pointer")
};
CustomPayload(inner)
}
}
impl Default for CustomPayload {
fn default() -> Self {
unsafe { CustomPayload(cass_custom_payload_new()) }
}
}
impl CustomPayload {
pub fn set(&self, name: String, value: &[u8]) -> Result<()> {
unsafe {
let name_ptr = name.as_ptr() as *const c_char;
Ok(cass_custom_payload_set_n(
self.0,
name_ptr,
name.len(),
value.as_ptr(),
value.len(),
))
}
}
}
impl Drop for CustomPayload {
fn drop(&mut self) {
unsafe { cass_custom_payload_free(self.0) }
}
}