pdcomm_buffer_create
Function
Copies caller bytes into a new owned buffer.
PdcommStatus pdcomm_buffer_create(const uint8_t *data, size_t length, size_t max_bytes, PdcommBuffer **out)The input is copied; the caller keeps ownership of data.
Parameters
| Name | Description |
|---|---|
data | Bytes to copy. May be NULL when length is 0. |
length | Number of bytes at data. |
max_bytes | Largest length the application allows. This is application policy, not a protocol constant. |
out | Receives the new buffer handle. Set to NULL before any other check, so it is NULL after every failure. Must not overlap data. |
Returns
#PDCOMM_OK on success; #PDCOMM_INVALID_ARGUMENT when out is NULL, data is NULL with a nonzero length, or length exceeds PTRDIFF_MAX; #PDCOMM_LIMIT_EXCEEDED when length exceeds max_bytes; #PDCOMM_ALLOCATION_FAILED when memory could not be allocated; #PDCOMM_INTERNAL_ERROR when a panic was contained.
Notes
- Ownership: release the handle exactly once with pdcomm_buffer_destroy().