ausocean / ausocean/client

ESP/Speaker: Avoid dynamic string allocation in the NetSender HTTP response path

Open
#159 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
0
Forks
0
Avg merge
1h 27m
Merged PRs (30d)
1

Description

## Problem

NetSender already receives HTTP responses into the fixed-size `resp_buf`, but several request/response paths copy that data into `std::string` objects and create additional temporary strings while extracting fields.

Examples include:

```cpp
std::string json_resp(resp_buf);
```
and temporary strings created for extracted response fields.

This adds unnecessary copying and may introduce dynamic allocations in a periodically executed HTTP path.

The goal is to make response processing allocation-free after the initial fixed buffers have been initialized.

## Proposed change

Change JSON field extraction to operate directly on the response buffer:
```cpp
bool netsender_extract_json(
const char *json,
const char *name,
char *out,
size_t out_len);
```

Use bounded writes and explicit length checks so extraction cannot overflow the destination buffer.

Update callers to pass fixed-size character buffers rather than constructing temporary `std::string` objects.

For HTTP response codes, parse the numeric status once and pass an integer to the response handler rather than converting it to and from `std::string`.

## Notes

The replacement parser must preserve the behavior of the existing parser for the JSON format actually used by NetSender. A simple `strstr()` implementation should not be assumed to be a complete JSON parser; quoting, escaping, whitespace, and field-name matching need to be handled correctly for the supported input.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating NetSender, netsender_extract_json, resp_buf, and the response handler, then trace every HTTP response path that constructs std::string values. Compare the existing parser behavior for supported JSON responses and verify that callers use fixed buffers, bounded extraction, and one numeric status parse with no post-initialization allocations.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot, networking
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.