Skip to content
Start free evaluation

pdcomm_modbus_buffer_copy

Function

Copies a JSON reply buffer as UTF-8 without a terminator.

int32_t pdcomm_modbus_buffer_copy(pdcomm_modbus_handle buffer, uint8_t *output, size_t capacity, size_t *size)

Declared in: #include <pdcomm/modbus/pdcomm_modbus.h>

Pass a null output and zero capacity to query the size, then allocate and copy. The buffer is immutable and stays valid until it is released.

Parameters

NameDescription
bufferBuffer handle returned by pdcomm_modbus_call().
outputDestination, or null when capacity is zero.
capacitySize of output in bytes.
sizeReceives the buffer size in bytes; must not be null.

Returns

#PDCOMM_MODBUS_OK, #PDCOMM_MODBUS_BUFFER_TOO_SMALL when capacity is smaller than the buffer (the output is unchanged), #PDCOMM_MODBUS_INVALID_INPUT, or #PDCOMM_MODBUS_INVALID_HANDLE when buffer is not a live buffer handle.

Notes

  • Thread-safe; a buffer can be copied from any thread.