riot_sys

Function coap_build_reply

Source
pub unsafe extern "C" fn coap_build_reply(
    pkt: *mut coap_pkt_t,
    code: c_uint,
    rbuf: *mut u8,
    rlen: c_uint,
    payload_len: c_uint,
) -> ssize_t
Expand description

@brief Build reply to CoAP request

This function can be used to create a reply to any CoAP request packet. It will create the reply packet header based on parameters from the request (e.g., id, token).

Passing a non-zero @p payload_len will ensure the payload fits into the buffer along with the header. For this validation, payload_len must include any options, the payload marker, as well as the payload proper.

@param[in] pkt packet to reply to @param[in] code reply code (e.g., COAP_CODE_204) @param[out] rbuf buffer to write reply to @param[in] rlen size of @p rbuf @param[in] payload_len length of payload

@returns size of reply packet on success

         Note that this size can be severely shortened if due to a No-Response option there
         is only an empty ACK to be sent back. The caller may just continue populating the
         payload (the space was checked to suffice), but may also skip that needless step
         if the returned length is less than the requested payload length.

@returns 0 if no response should be sent due to a No-Response option in the request @returns <0 on error @returns -ENOSPC if @p rbuf too small