Skip to content

Commit

Permalink
net: golioth: Kconfig for max CBOR RPC response
Browse files Browse the repository at this point in the history
Introduce GOLIOTH_RPC_MAX_RESPONSE_LEN which allows applications to change
the max size of the CBOR response returned from an RPC method. This solves
the issue of receiving an error when the RPC response is too large: <err>
golioth: QCBOREncode_FinishGetSize error: 1 (QCBOR_ERR_BUFFER_TOO_SMALL)

Signed-off-by: Mike Szczys <mike@golioth.io>
  • Loading branch information
szczys committed May 18, 2023
1 parent 2a52bb9 commit f01824d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 9 additions & 0 deletions net/golioth/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ config GOLIOTH_RPC_MAX_NUM_METHODS
Maximum number of Golioth Remote Procedure Call methods that can
be registered.

config GOLIOTH_RPC_MAX_RESPONSE_LEN
int "Maximum length of the CBOR response"
depends on GOLIOTH_RPC
default 256
help
Maximum length of the CBOR response returned by Golioth RPC methods.
If this value is too small for the returned package, a
QCBOR_ERR_BUFFER_TOO_SMALL will occur.

config GOLIOTH_SETTINGS
bool "Settings cloud service"
select QCBOR
Expand Down
3 changes: 1 addition & 2 deletions net/golioth/rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ LOG_MODULE_DECLARE(golioth);

#define GOLIOTH_RPC_PATH ".rpc"
#define GOLIOTH_RPC_STATUS_PATH ".rpc/status"
#define GOLIOTH_RPC_MAX_RESPONSE_LEN 256

static int send_response(struct golioth_client *client,
uint8_t *coap_payload, size_t coap_payload_len)
Expand Down Expand Up @@ -87,7 +86,7 @@ static int on_rpc(struct golioth_req_rsp *rsp)
}

/* Start encoding response */
uint8_t response_buf[GOLIOTH_RPC_MAX_RESPONSE_LEN];
uint8_t response_buf[CONFIG_GOLIOTH_RPC_MAX_RESPONSE_LEN];
UsefulBuf response_bufc = { response_buf, sizeof(response_buf) };
QCBOREncodeContext encode_ctx;

Expand Down

0 comments on commit f01824d

Please sign in to comment.