Conversation
benpicco
left a comment
There was a problem hiding this comment.
This is all pretty straightforward. Using void * for buffers would make for a nicer to use API.
Would it make sense to
typedef gcoap_pkt_t coap_pkt_t
? Tbh I can't quite yet wrap my head around why those wrappers are needed in the first place, but I suppose they will be extended later?
sys/include/net/gcoap.h
Outdated
| * @name Buffer manipulation | ||
| * @{ | ||
| */ | ||
| static inline uint8_t *gcoap_pkt_get_buf(coap_pkt_t *pdu) |
There was a problem hiding this comment.
| static inline uint8_t *gcoap_pkt_get_buf(coap_pkt_t *pdu) | |
| static inline void *gcoap_pkt_get_buf(coap_pkt_t *pdu) |
should be more flexible
sys/include/net/gcoap.h
Outdated
| return (uint8_t *)pdu->hdr; | ||
| } | ||
|
|
||
| static inline void gcoap_pkt_set_buf(coap_pkt_t *pdu, uint8_t *buf) |
There was a problem hiding this comment.
same here
| static inline void gcoap_pkt_set_buf(coap_pkt_t *pdu, uint8_t *buf) | |
| static inline void gcoap_pkt_set_buf(coap_pkt_t *pdu, void *buf) |
Yes, that will be done as soon as I find some time to continue on this.
See #16855. Also, if you look at libOSCORE's API you will find, that having these wrappers will be very useful to make the access transparent to the user ;-). |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
|
Not needed anymore, thanks to unicoap. |
Contribution description
This PR aims to address the first three tasks in #16855.
This is still WIP, but before I start changing types and documentation, I wanted to have some input.
I followed the following strategies for the wrappers:
nanocoapfunction in an inline function)nanocoapsometimes casting is necessary; I aimed to keep the types consistent in the wrappers\0-terminated and length variants for adding strings (with the\0-terminated variants callingstrlen()most of the time, so I decided to use the length variants only.nanocoapfunctions usecoap_pkt_t, some usecoap_hdr_t, some use just raw buffers as the object acted upon. I decided for the wrapper to always usecoap_pkt_tas the object acted upon to simplify things towards the front-end. Only exception isgcoap_pkt_build_hdr(), ascoap_pkt_init()requires the headers inbufalready to be initialized, but it also setspkt->hdrto the buffer pointer. So requiringpkt->hdrto be already initialized ingcoap_pkt_build_hdr()would lead topkt->hdrto be initialized twice (once by the caller ofgcoap_pkt_build_hdr()and once to incoap_pkt_init(). As such, I decided to have just an opaque buffer be the object acted upon bygcoap_pkt_build_hdr()(while writing this I reallized that as such the namegcoap_build_hdr()might be better suited, but I leave this up to discussion).nanocoapfunctions are always used with other functions (e.g. setting the payload always adds the payload marker first) ingcoapand its applications), so the wrapper always does this as well.Future TODOs:
gcoap-specific type wrappers fornanocoaptypesgcoaptypes to always be prefixed withgcoapgcoap-specific types in newly introduced functionsgcoapand the applications.Testing procedure
examples/gcoapshould still compile. Currently, the new wrappers are not used yet, so nothing to test.Issues/PRs references
Addresse parts of #16855