#[macro_export]
macro_rules! coap {
(@none $($tokens:tt)+) => {
$crate::parse!(@none $($tokens)+)
};
(@json $($tokens:tt)+) => {
$crate::parse!(@json $($tokens)+)
};
(@cbor $($tokens:tt)+) => {
$crate::parse!(@cbor $($tokens)+)
};
(@cbormin $($tokens:tt)+) => {
$crate::parse!(@cbormin $($tokens)+)
};
}
#[macro_export]
macro_rules! parse {
(@$enc:ident @object $object:ident () () ()) => {};
(@none @object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => {
d!(TODO: add key: $($key)+, value: $value, to object: $object);
$crate::parse!(@none @object $object () ($($rest)*) ($($rest)*));
};
(@$enc:ident @object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => {
d!(add1 key: $($key)+ value: $value to object: $object);
$crate::coap_item_str!(@$enc $object, $($key)+, $value);
"--------------------";
$crate::parse!(@$enc @object $object () ($($rest)*) ($($rest)*));
};
(@$enc:ident @object $object:ident [$($key:tt)+] ($value:expr) $unexpected:tt $($rest:tt)*) => {
unexpected_token!($unexpected);
};
(@$enc:ident @object $object:ident [$($key:tt)+] ($value:expr)) => {
d!(TODO: add2 key: $($key)+ value: $value to object: $object);
};
(@$enc:ident @object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => {
$crate::parse!(@$enc @object $object [$($key)+]
($crate::parse!(@$enc null)) $($rest)*);
};
(@$enc:ident @object $object:ident ($($key:tt)+) (: true $($rest:tt)*) $copy:tt) => {
$crate::parse!(@$enc @object $object [$($key)+]
($crate::parse!(@$enc true)) $($rest)*);
};
(@$enc:ident @object $object:ident ($($key:tt)+) (: false $($rest:tt)*) $copy:tt) => {
$crate::parse!(@$enc @object $object [$($key)+]
($crate::parse!(@$enc false)) $($rest)*);
};
(@$enc:ident @object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => {
$crate::parse!(@$enc @object $object [$($key)+]
($crate::parse!(@$enc [$($array)*])) $($rest)*);
};
(@$enc:ident @object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => {
$crate::parse!(@$enc @object $object [$($key)+]
($crate::parse!(@$enc {$($map)*})) $($rest)*);
};
(@$enc:ident @object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => {
$crate::parse!(@$enc @object $object [$($key)+]
($crate::parse!(@$enc $value)) , $($rest)*);
};
(@$enc:ident @object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => {
$crate::parse!(@$enc @object $object [$($key)+]
($crate::parse!(@$enc $value)));
};
(@$enc:ident @object $object:ident ($($key:tt)+) (:) $copy:tt) => {
$crate::parse!();
};
(@none @object $object:ident ($($key:tt)+) () $copy:tt) => {
d!(TODO: extract key, value from _sensor_value: $($key)+ and add to _object: $object);
"--------------------";
};
(@json @object $object:ident ($($key:tt)+) () $copy:tt) => {
"--------------------";
$crate::coap_item_int_val!(@json
$object,
$($key)+
);
"--------------------";
};
(@cbor @object $object:ident ($($key:tt)+) () $copy:tt) => {
"--------------------";
$crate::coap_item_int_val!(@cbor
$object,
$($key)+
);
"--------------------";
};
(@cbormin @object $object:ident ($($key:tt)+) () $copy:tt) => {
"--------------------";
$crate::coap_set_int_val!(@cbor
$object,
$($key)+
);
"--------------------";
};
(@$enc:ident @object $object:ident () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => {
$crate::unexpected_token!($colon);
};
(@none @object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => {
d!(TODO: extract key, value from _sensor_value: $($key)* and add to _object: $object);
"--------------------";
$crate::parse!(@none @object $object () ($($rest)*) ($($rest)*));
};
(@json @object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => {
"--------------------";
$crate::coap_item_int_val!(@json
$object,
$($key)*
);
"--------------------";
$crate::parse!(@json @object $object () ($($rest)*) ($($rest)*));
};
(@cbor @object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => {
"--------------------";
$crate::coap_item_int_val!(@cbor
$object,
$($key)*
);
"--------------------";
$crate::parse!(@cbor @object $object () ($($rest)*) ($($rest)*));
};
(@cbormin @object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => {
"--------------------";
$crate::coap_set_int_val!(@cbor
$object,
$($key)*
);
"--------------------";
$crate::parse!(@cbor @object $object () ($($rest)*) ($($rest)*));
};
(@$enc:ident @object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => {
d!( got () );
$crate::parse!(@$enc @object $object ($key) (: $($rest)*) (: $($rest)*));
};
(@$enc:ident @object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => {
$crate::nx!( ($($key)*), ($tt), ($($rest)*) );
$crate::parse!(@$enc @object $object ($($key)* $tt) ($($rest)*) ($($rest)*));
};
(@$enc:ident @array [$($elems:expr,)*]) => {
parse_vector![$($elems,)*]
};
(@$enc:ident @array [$($elems:expr),*]) => {
parse_vector![$($elems),*]
};
(@$enc:ident @array [$($elems:expr,)*] null $($rest:tt)*) => {
$crate::parse!(@$enc @array [$($elems,)*
$crate::parse!(@$enc null)] $($rest)*)
};
(@$enc:ident @array [$($elems:expr,)*] true $($rest:tt)*) => {
$crate::parse!(@$enc @array [$($elems,)*
$crate::parse!(@$enc true)] $($rest)*)
};
(@$enc:ident @array [$($elems:expr,)*] false $($rest:tt)*) => {
$crate::parse!(@$enc @array [$($elems,)*
$crate::parse!(@$enc false)] $($rest)*)
};
(@$enc:ident @array [$($elems:expr,)*] [$($array:tt)*] $($rest:tt)*) => {
$crate::parse!(@$enc @array [$($elems,)*
$crate::parse!(@$enc [$($array)*])] $($rest)*)
};
(@$enc:ident @array [$($elems:expr,)*] {$($map:tt)*} $($rest:tt)*) => {
$crate::parse!(@$enc @array [$($elems,)*
$crate::parse!(@$enc {$($map)*})] $($rest)*)
};
(@$enc:ident @array [$($elems:expr,)*] $next:expr, $($rest:tt)*) => {
$crate::parse!(@$enc @array [$($elems,)*
$crate::parse!(@$enc $next),] $($rest)*)
};
(@$enc:ident @array [$($elems:expr,)*] $last:expr) => {
$crate::parse!(@$enc @array [$($elems,)*
$crate::parse!(@$enc $last)])
};
(@$enc:ident @array [$($elems:expr),*] , $($rest:tt)*) => {
$crate::parse!(@$enc @array [$($elems,)*] $($rest)*)
};
(@$enc:ident @array [$($elems:expr),*] $unexpected:tt $($rest:tt)*) => {
$crate::unexpected_token!($unexpected)
};
(@$enc:ident null) => {{
d!(TODO: null); "null"
}};
(@$enc:ident true) => {
{ d!(true); "true" }
};
(@$enc:ident false) => {
{ d!(false); "false" }
};
(@$enc:ident []) => {
{ d!([ TODO ]); "[ TODO ]" }
};
(@$enc:ident [ $($tt:tt)+ ]) => {
{
d!(begin array);
_array = $crate::parse!(@$enc @array [] $($tt)+);
d!(end array);
"[ TODO ]"
}
};
(@$enc:ident {}) => {
{ d!({ TODO }); "{ TODO }" }
};
(@none { $($tt:tt)+ }) => {{
d!(begin none root);
let root = _ROOT;
$crate::parse!(@none @object root () ($($tt)+) ($($tt)+));
d!(end none root);
d!(return none root to caller);
root
}};
(@json { $($tt:tt)+ }) => {{
d!(begin json root);
$crate::coap_root!(@json COAP_CONTEXT {
$crate::coap_array!(@json COAP_CONTEXT, values, {
$crate::parse!(@json @object COAP_CONTEXT () ($($tt)+) ($($tt)+));
});
});
d!(end json root);
()
}};
(@cbor { $($tt:tt)+ }) => {{
d!(begin cbor root);
$crate::coap_root!(@cbor root {
$crate::coap_array!(@cbor root, values, {
$crate::parse!(@cbor @object values () ($($tt)+) ($($tt)+));
});
});
d!(end cbor root);
()
}};
(@cbormin { $($tt:tt)+ }) => {{
d!(begin cbor root);
$crate::coap_root!(@cbormin COAP_CONTEXT {
$crate::parse!(@cbormin @object COAP_CONTEXT () ($($tt)+) ($($tt)+));
});
d!(end cbor root);
()
}};
(@$enc:ident $other:expr) => {
$other
};
}
#[macro_export]
macro_rules! parse_vector {
($($content:tt)*) => {
$crate::vec![$($content)*]
};
}
#[macro_export]
macro_rules! unexpected_token {
() => {};
}
#[macro_export]
macro_rules! coap_root {
(@cbor $context:ident $children0:block) => {{
d!(begin cbor coap_root);
unsafe { mynewt::libs::sensor_network::prepare_post(mynewt::encoding::APPLICATION_CBOR) ? ; }
$crate::oc_rep_start_root_object!($context);
$children0;
$crate::oc_rep_end_root_object!($context);
d!(end cbor coap_root);
}};
(@json $context:ident $children0:block) => {{
d!(begin json coap_root);
unsafe { mynewt::libs::sensor_network::prepare_post(mynewt::encoding::APPLICATION_JSON) ? ; }
unsafe { mynewt::libs::sensor_coap::json_rep_start_root_object(); }
$children0;
unsafe { mynewt::libs::sensor_coap::json_rep_end_root_object(); }
d!(end json coap_root);
}};
}
#[macro_export]
macro_rules! coap_array {
(@cbor $object0:ident, $key0:ident, $children0:block) => {{
d!(begin cbor coap_array, object: $object0, key: $key0);
$crate::oc_rep_set_array!($object0, $key0);
$children0;
$crate::oc_rep_close_array!($object0, $key0);
d!(end cbor coap_array);
}};
(@json $object0:ident, $key0:ident, $children0:block) => {{
d!(begin json coap_array, object: $object0, key: $key0);
$crate::json_rep_set_array!($object0, $key0);
$children0;
$crate::json_rep_close_array!($object0, $key0);
d!(end json coap_array);
}};
}
#[macro_export]
macro_rules! coap_item_int {
(@cbor $array0:ident, $key0:expr, $value0:expr, $geo0:expr) => {{
d!(begin cbor coap_item_int, key: $key0, value: $value0);
$crate::coap_item!(@cbor $array0, {
$crate::oc_rep_set_text_string!($array0, "key", $key0);
$crate::oc_rep_set_int!( $array0, "value", $value0);
});
d!(end cbor coap_item_int);
}};
(@json $array0:ident, $key0:expr, $value0:expr, $geo0:expr) => {{
d!(begin json coap_item_int, key: $key0, value: $value0);
$crate::coap_item!(@json $array0, {
$crate::json_rep_set_text_string!($array0, "key", $key0);
$crate::json_rep_set_int!( $array0, "value", $value0);
unsafe { $array0.json_set_geolocation(strn!("geo"), strn!("lat"), strn!("long"), $geo0) };
});
d!(end json coap_item_int);
}};
}
#[macro_export]
macro_rules! coap_item_str {
(@cbor $parent:ident, $key:expr, $val:expr) => {{
d!(begin cbor coap_item_str, parent: $parent, key: $key, val: $val);
$crate::coap_item!(@cbor
$parent,
{
$crate::oc_rep_set_text_string!($parent, "key", $key);
$crate::oc_rep_set_text_string!($parent, "value", $val);
}
);
d!(end cbor coap_item_str);
}};
(@json $parent:ident, $key:expr, $val:expr) => {{
d!(begin json coap_item_str, parent: $parent, key: $key, val: $val);
$crate::coap_item!(@json
$parent,
{
$crate::json_rep_set_text_string!($parent, key, $key);
$crate::json_rep_set_text_string!($parent, value, $val);
}
);
d!(end json coap_item_str);
}};
}
#[macro_export]
macro_rules! coap_item {
(@cbor $context:ident, $children0:block) => {{
d!(begin cbor coap_item, array: $context);
$crate::oc_rep_object_array_start_item!($context);
$children0;
$crate::oc_rep_object_array_end_item!($context);
d!(end cbor coap_item);
}};
(@json $context:ident, $children0:block) => {{
d!(begin json coap_item, array: $context);
$crate::json_rep_object_array_start_item!($context);
$children0;
$crate::json_rep_object_array_end_item!($context);
d!(end json coap_item);
}};
}
#[macro_export]
macro_rules! coap_set_int_val {
(@cbor $context:ident, $val0:expr) => {{
d!(begin cbor coap_set_int_val, c: $context, val: $val0);
if let SensorValueType::Uint(val) = $val0.value {
$crate::oc_rep_set_int!($context, $val0.key, val);
} else {
unsafe { COAP_CONTEXT.fail(CoapError::VALUE_NOT_UINT) };
}
d!(end cbor coap_set_int_val);
}};
(@json $context:ident, $val0:expr) => {{
d!(begin json coap_set_int_val, c: $context, val: $val0);
if let SensorValueType::Uint(val) = $val0.value {
$crate::json_rep_set_int!($context, $val0.key, val);
} else {
unsafe { COAP_CONTEXT.fail(CoapError::VALUE_NOT_UINT) };
}
d!(end json coap_set_int_val);
}};
}
#[macro_export]
macro_rules! coap_item_int_val {
(@cbor $context:ident, $val0:expr) => {{
d!(begin cbor coap_item_int_val, c: $context, val: $val0);
let geo = $val0.geo;
if let SensorValueType::Uint(val) = $val0.value {
$crate::coap_item_int!(@cbor $context, $val0.key, val, geo);
} else {
unsafe { COAP_CONTEXT.fail(CoapError::VALUE_NOT_UINT) };
}
d!(end cbor coap_item_int_val);
}};
(@json $context:ident, $val0:expr) => {{
d!(begin json coap_item_int_val, c: $context, val: $val0);
let geo = $val0.geo;
if let SensorValueType::Uint(val) = $val0.value {
$crate::coap_item_int!(@json $context, $val0.key, val, geo);
} else {
unsafe { COAP_CONTEXT.fail(CoapError::VALUE_NOT_UINT) };
}
d!(end json coap_item_int_val);
}};
}
#[macro_export]
macro_rules! json_rep_set_array {
($context:ident, $key:ident) => {{
concat!(
"<< jarri ",
", o: ", stringify!($context),
", k: ", stringify!($key)
);
let key_with_null: &str = $crate::stringify_null!($key);
unsafe {
mynewt::libs::mynewt_rust::json_helper_set_array(
$context.to_void_ptr(),
$context.key_to_cstr(key_with_null.as_bytes())
);
};
}};
($context:ident, $key:expr) => {{
concat!(
"<< jarre ",
", o: ", stringify!($context),
", k: ", stringify!($key)
);
let key_with_opt_null: &[u8] = $key.to_bytes_optional_nul();
unsafe {
mynewt::libs::mynewt_rust::json_helper_set_array(
$context.to_void_ptr(),
$context.key_to_cstr(key_with_opt_null)
);
};
}};
}
#[macro_export]
macro_rules! json_rep_close_array {
($context:ident, $key:ident) => {{
concat!(
">>"
);
let key_with_null: &str = $crate::stringify_null!($key);
unsafe {
mynewt::libs::mynewt_rust::json_helper_close_array(
$context.to_void_ptr(),
$context.key_to_cstr(key_with_null.as_bytes())
)
};
}};
($context:ident, $key:expr) => {{
concat!(
">>"
);
let key_with_opt_null: &[u8] = $key.to_bytes_optional_nul();
unsafe {
mynewt::libs::mynewt_rust::json_helper_close_array(
$context.to_void_ptr(),
$context.key_to_cstr(key_with_opt_null)
)
};
}};
}
#[macro_export]
macro_rules! json_rep_object_array_start_item {
($context:ident) => {{
concat!(
"<< jitmi",
" c: ", stringify!($context)
);
let key_with_null: &str = $crate::stringify_null!($context);
unsafe {
mynewt::libs::mynewt_rust::json_helper_object_array_start_item(
$context.key_to_cstr(key_with_null.as_bytes())
)
};
}};
($context:ident) => {{
concat!(
"<< jitme",
" c: ", stringify!($context)
);
let key_with_opt_null: &[u8] = $context.to_bytes_optional_nul();
unsafe {
mynewt::libs::mynewt_rust::json_helper_object_array_start_item(
$context.key_to_cstr(key_with_opt_null)
)
};
}};
}
#[macro_export]
macro_rules! json_rep_object_array_end_item {
($context:ident) => {{
concat!(
">>"
);
let key_with_null: &str = $crate::stringify_null!($context);
unsafe {
mynewt::libs::mynewt_rust::json_helper_object_array_end_item(
$context.key_to_cstr(key_with_null.as_bytes())
)
};
}};
($context:ident) => {{
concat!(
">>"
);
let key_with_opt_null: &[u8] = $context.to_bytes_optional_nul();
unsafe {
mynewt::libs::mynewt_rust::json_helper_object_array_end_item(
$context.key_to_cstr(key_with_opt_null)
)
};
}};
}
#[macro_export]
macro_rules! json_rep_set_int {
($context:ident, $key:ident, $value:expr) => {{
concat!(
"-- jinti",
" o: ", stringify!($context),
", k: ", stringify!($key),
", v: ", stringify!($value)
);
let key_with_null: &str = $crate::stringify_null!($key);
let value = $value as u64;
unsafe {
mynewt::libs::mynewt_rust::json_helper_set_int(
$context.to_void_ptr(),
$context.key_to_cstr(key_with_null.as_bytes()),
value
)
};
}};
($context:ident, $key:expr, $value:expr) => {{
concat!(
"-- jinte",
" o: ", stringify!($context),
", k: ", stringify!($key),
", v: ", stringify!($value)
);
let key_with_opt_null: &[u8] = $key.to_bytes_optional_nul();
let value = $value as u64;
unsafe {
mynewt::libs::mynewt_rust::json_helper_set_int(
$context.to_void_ptr(),
$context.key_to_cstr(key_with_opt_null),
value
)
};
}};
}
#[macro_export]
macro_rules! json_rep_set_text_string {
($context:ident, $key:ident, $value:expr) => {{
concat!(
"-- jtxti",
" o: ", stringify!($context),
", k: ", stringify!($key),
", v: ", stringify!($value)
);
let key_strn: &Strn = strn!(stringify!($key));
let value_strn: &Strn = strn!($value);
unsafe { $context.json_set_text_string(key_strn, value_strn) };
}};
($context:ident, $key:expr, $value:expr) => {{
concat!(
"-- jtxte",
" o: ", stringify!($context),
", k: ", stringify!($key),
", v: ", stringify!($value)
);
let key_with_opt_null: &[u8] = $key.to_bytes_optional_nul();
let value_with_opt_null: &[u8] = $value.to_bytes_optional_nul();
unsafe {
mynewt::libs::mynewt_rust::json_helper_set_text_string(
$context.to_void_ptr(),
$context.key_to_cstr(key_with_opt_null),
$context.value_to_cstr(value_with_opt_null)
)
};
}};
}
#[macro_export]
macro_rules! oc_rep_start_root_object {
($obj:ident) => {{
d!(begin oc_rep_start_root_object);
mynewt_macros::try_cbor!({
let encoder = COAP_CONTEXT.encoder(_ROOT, _MAP);
cbor_encoder_create_map(
COAP_CONTEXT.global_encoder(),
encoder,
mynewt::encoding::tinycbor::CborIndefiniteLength
);
});
d!(end oc_rep_start_root_object);
}};
}
#[macro_export]
macro_rules! oc_rep_end_root_object {
($obj:ident) => {{
d!(begin oc_rep_end_root_object);
mynewt_macros::try_cbor!({
let encoder = COAP_CONTEXT.encoder(_ROOT, _MAP);
cbor_encoder_close_container(
COAP_CONTEXT.global_encoder(),
encoder
);
});
d!(end oc_rep_end_root_object);
}};
}
#[macro_export]
macro_rules! oc_rep_start_object {
($parent:ident, $key:ident, $parent_suffix:ident) => {{
concat!(
"begin oc_rep_start_object ",
", parent: ", stringify!($parent), stringify!($parent_suffix),
", key: ", stringify!($key),
", child: ", stringify!($key), "_map"
);
mynewt_macros::try_cbor!({
let parent_encoder = COAP_CONTEXT.encoder(
stringify!($parent),
stringify!($parent_suffix)
);
let encoder = COAP_CONTEXT.new_encoder(
stringify!($key),
_MAP
);
cbor_encoder_create_map(
parent_encoder,
encoder,
mynewt::encoding::tinycbor::CborIndefiniteLength
);
});
d!(end oc_rep_start_object);
}};
}
#[macro_export]
macro_rules! oc_rep_end_object {
($parent:ident, $key:ident, $parent_suffix:ident) => {{
concat!(
"begin oc_rep_end_object ",
", parent: ", stringify!($parent), stringify!($parent_suffix),
", key: ", stringify!($key),
", child: ", stringify!($key), "_map"
);
mynewt_macros::try_cbor!({
let parent_encoder = COAP_CONTEXT.encoder(
stringify!($parent),
stringify!($parent_suffix)
);
let encoder = COAP_CONTEXT.encoder(
stringify!($key),
_MAP
);
cbor_encoder_close_container(
parent_encoder,
encoder
);
});
d!(end oc_rep_end_object);
}};
}
#[macro_export]
macro_rules! oc_rep_start_array {
($parent:ident, $key:ident, $parent_suffix:ident) => {{
concat!(
"begin oc_rep_start_array ",
", parent: ", stringify!($parent), stringify!($parent_suffix),
", key: ", stringify!($key),
", child: ", stringify!($key), "_array"
);
mynewt_macros::try_cbor!({
let parent_encoder = COAP_CONTEXT.encoder(
stringify!($parent),
stringify!($parent_suffix)
);
let encoder = COAP_CONTEXT.new_encoder(
stringify!($key),
_ARRAY
);
cbor_encoder_create_array(
parent_encoder,
encoder,
mynewt::encoding::tinycbor::CborIndefiniteLength
);
});
d!(end oc_rep_start_array);
}};
}
#[macro_export]
macro_rules! oc_rep_end_array {
($parent:ident, $key:ident, $parent_suffix:ident) => {{
concat!(
"begin oc_rep_end_array ",
", parent: ", stringify!($parent), stringify!($parent_suffix),
", key: ", stringify!($key),
", child: ", stringify!($key), "_array"
);
mynewt_macros::try_cbor!({
let parent_encoder = COAP_CONTEXT.encoder(
stringify!($parent),
stringify!($parent_suffix)
);
let encoder = COAP_CONTEXT.encoder(
stringify!($key),
_ARRAY
);
cbor_encoder_close_container(
parent_encoder,
encoder
);
});
d!(end oc_rep_end_array);
}};
}
#[macro_export]
macro_rules! oc_rep_set_array {
($object:ident, $key:ident) => {{
concat!(
"begin oc_rep_set_array ",
", object: ", stringify!($object),
", key: ", stringify!($key),
", child: ", stringify!($object), "_map"
);
let key_with_opt_null: &[u8] = stringify!($key).to_bytes_optional_nul();
mynewt_macros::try_cbor!({
let encoder = COAP_CONTEXT.encoder(
stringify!($object),
_MAP
);
cbor_encode_text_string(
encoder,
COAP_CONTEXT.key_to_cstr(key_with_opt_null),
COAP_CONTEXT.cstr_len(key_with_opt_null)
);
});
$crate::oc_rep_start_array!($object, $key, _map);
d!(end oc_rep_set_array);
}};
}
#[macro_export]
macro_rules! oc_rep_close_array {
($object:ident, $key:ident) => {{
concat!(
"begin oc_rep_close_array ",
", object: ", stringify!($object),
", key: ", stringify!($key),
", child: ", stringify!($object), "_map"
);
$crate::oc_rep_end_array!($object, $key, _map);
d!(end oc_rep_close_array);
}};
}
#[macro_export]
macro_rules! oc_rep_object_array_start_item {
($key:ident) => {{
concat!(
"begin oc_rep_object_array_start_item ",
", key: ", stringify!($key),
", child: ", stringify!($key), "_array",
);
$crate::oc_rep_start_object!($key, $key, _array);
d!(end oc_rep_object_array_start_item);
}};
}
#[macro_export]
macro_rules! oc_rep_object_array_end_item {
($key:ident) => {{
concat!(
"begin oc_rep_object_array_end_item ",
", key: ", stringify!($key),
", child: ", stringify!($key), "_array",
);
$crate::oc_rep_end_object!($key, $key, _array);
d!(end oc_rep_object_array_end_item);
}};
}
#[macro_export]
macro_rules! oc_rep_set_int {
($obj:ident, $key:ident, $value:expr) => {
concat!(
"-- cinti",
" c: ", stringify!($obj),
", k: ", stringify!($key),
", v: ", stringify!($value)
);
let key_with_null: &str = $crate::stringify_null!($key);
let value = $value as i64;
mynewt_macros::try_cbor!({
let encoder = COAP_CONTEXT.encoder(
stringify!($obj),
_MAP
);
cbor_encode_text_string(
encoder,
COAP_CONTEXT.key_to_cstr(key_with_null.as_bytes()),
COAP_CONTEXT.cstr_len(key_with_null.as_bytes())
);
cbor_encode_int(
encoder,
value
);
});
};
($obj:ident, $key:expr, $value:expr) => {
concat!(
"-- cinte",
" c: ", stringify!($obj),
", k: ", stringify!($key),
", v: ", stringify!($value)
);
let key_with_opt_null: &[u8] = $key.to_bytes_optional_nul();
let value = $value as i64;
mynewt_macros::try_cbor!({
let encoder = COAP_CONTEXT.encoder(
stringify!($obj),
_MAP
);
cbor_encode_text_string(
encoder,
COAP_CONTEXT.key_to_cstr(key_with_opt_null),
COAP_CONTEXT.cstr_len( key_with_opt_null)
);
cbor_encode_int(
encoder,
value
);
});
};
}
#[macro_export]
macro_rules! oc_rep_set_text_string {
($obj:ident, $key:expr, $value:expr) => {{
concat!(
"begin oc_rep_set_text_string ",
", c: ", stringify!($obj),
", k: ", stringify!($key),
", v: ", stringify!($value),
", ch: ", stringify!($obj), "_map"
);
let key_with_opt_null: &[u8] = $key.to_bytes_optional_nul();
let value_with_opt_null: &[u8] = $value.to_bytes_optional_nul();
mynewt_macros::try_cbor!({
let encoder = COAP_CONTEXT.encoder(
stringify!($obj),
_MAP
);
cbor_encode_text_string(
encoder,
COAP_CONTEXT.key_to_cstr(key_with_opt_null),
COAP_CONTEXT.cstr_len( key_with_opt_null)
);
cbor_encode_text_string(
encoder,
COAP_CONTEXT.value_to_cstr(value_with_opt_null),
COAP_CONTEXT.cstr_len( value_with_opt_null)
);
});
d!(end oc_rep_set_text_string);
}};
}