arduino / arduino/ArduinoCore-API

Make String::copy public

オープン
#84 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
C++
スター
306
フォーク
150
PR マージ指標
30日以内にマージされた PR はありません

説明

I have a small feature request (and I am happy to provide the PR ), but why isn't .copy public? There is a use-case here which makes a lot of sense -- specifically when you are given a pointer to a char* that is not null-terminated (and instead are provided a length).

This is exactly how the PubSubClient MQTT library works. The topic callback provides you a byte *payload and length, but because it's byte * it's not null-terminated.

Currently you have to do this (or something like it) to get a String object:

```
void mqttCallback(char *topic, byte *payload, unsigned int length) {
String action;
char *payloadStr;

payloadStr = (char *)malloc(length + 1);
memcpy(payloadStr, payload, length);
payloadStr[length] = 0x0;
action = String(payloadStr);
free(payloadStr);
}
```

When what would make a lot more sense (since String doesn't provide a constructor for this) would be:

```
void mqttCallback(char *topic, byte *payload, unsigned int length) {
String action;
action.copy((char *)payload, length);
}
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

Arduino String API から始めて、既存の String::copy インターフェースと実装を調べます。char ポインターと長さをどのように処理するかを確認し、その後、null 終端されていない PubSubClient ペイロードを一時的なアロケーションなしでコピーでき、既存の String の動作が維持されることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
cpp
領域
api
issue の種類
機能追加
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。