Skip to content

Commit

Permalink
coap_handler: Translate from coap_handler::Reporting to gcoap::WithLi…
Browse files Browse the repository at this point in the history
…nkEncoder
  • Loading branch information
chrysn committed Feb 22, 2023
1 parent c27a215 commit 3dd98df
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/coap_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,49 @@ where
}
}

impl<H> crate::gcoap::WithLinkEncoder for GcoapHandler<H>
where
H: coap_handler::Handler + coap_handler::Reporting,
{
fn encode(&self, writer: &mut crate::gcoap::LinkEncoder) {
use coap_handler::Record;
for record in self.0.report() {
writer.write_comma_maybe();
writer.write(b"<");
for pathelement in record.path() {
writer.write(b"/");
writer.write(pathelement.as_ref().as_bytes());
}
writer.write(b">");
if let Some(rel) = record.rel() {
// Not trying to be smart about whether or not we need the quotes
writer.write(b";rel=\"");
writer.write(rel.as_bytes());
writer.write(b"\"");
}
for attr in record.attributes() {
use coap_handler::Attribute::*;
match attr {
Observable => writer.write(b";obs"),
Interface(i) => {
writer.write(b";if=\"");
writer.write(i.as_bytes());
writer.write(b"\"");
}
ResourceType(r) => {
writer.write(b";rt=\"");
writer.write(r.as_bytes());
writer.write(b"\"");
}
// FIXME: deduplicate with what's somewhere in coap-handler-implementations;
// implement remaining items
_ => (),
}
}
}
}
}

/// Blanket implementation for mutex wrapped resources
///
/// This is useful in combination with the defauilt implementation for Option as well.
Expand Down

0 comments on commit 3dd98df

Please sign in to comment.