rust/json: expose more of jansson to rust

pull/3288/head
Jason Ish 7 years ago committed by Victor Julien
parent dfdfc478ab
commit 57d9574839

@ -35,6 +35,7 @@ extern {
fn json_string(value: *const c_char) -> *mut JsonT;
fn json_integer(val: u64) -> *mut JsonT;
fn SCJsonDecref(value: *mut JsonT);
fn SCJsonBool(val: bool) -> *mut JsonT;
}
@ -44,6 +45,10 @@ pub struct Json {
impl Json {
pub fn decref(val: Json) {
unsafe{SCJsonDecref(val.js)};
}
pub fn object() -> Json {
return Json{
js: unsafe{json_object()},
@ -56,6 +61,18 @@ impl Json {
}
}
pub fn string(val: &str) -> Json {
return Json{
js: unsafe{json_string(to_cstring(val.as_bytes()).as_ptr())}
};
}
pub fn string_from_bytes(val: &[u8]) -> Json {
return Json{
js: unsafe{json_string(to_cstring(val).as_ptr())}
};
}
pub fn unwrap(&self) -> *mut JsonT {
return self.js;
}

@ -108,6 +108,15 @@ json_t *SCJsonBool(int val)
return (val ? json_true() : json_false());
}
/**
* Wrap json_decref. This is mainly to expose this function to Rust as its
* defined in the Jansson header file as an inline function.
*/
void SCJsonDecref(json_t *json)
{
json_decref(json);
}
/* Default Sensor ID value */
static int64_t sensor_id = -1; /* -1 = not defined */

@ -67,6 +67,7 @@ typedef struct OutputJsonCtx_ {
} OutputJsonCtx;
json_t *SCJsonBool(int val);
void SCJsonDecref(json_t *js);
#endif /* HAVE_LIBJANSSON */

Loading…
Cancel
Save