Skip to content

Commit 06dcabd

Browse files
committed
refactor: common bool2string code
1 parent 0c160e1 commit 06dcabd

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

src/Point.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <Arduino.h>
3131
#include "WritePrecision.h"
32+
#include "util/helpers.h"
3233

3334
/**
3435
* Class Point represents InfluxDB point in line protocol.
@@ -49,7 +50,7 @@ friend class InfluxDBClient;
4950
void addField(String name, unsigned int value) { putField(name, String(value)+"i"); }
5051
void addField(String name, long value) { putField(name, String(value)+"i"); }
5152
void addField(String name, unsigned long value) { putField(name, String(value)+"i"); }
52-
void addField(String name, bool value) { putField(name,value?"true":"false"); }
53+
void addField(String name, bool value) { putField(name, bool2string(value)); }
5354
void addField(String name, String value) { addField(name, value.c_str()); }
5455
void addField(String name, const char *value);
5556
// Set timestamp to `now()` and store it in specified precision, nanoseconds by default. Date and time must be already set. See `configTime` in the device API

src/query/HttpStreamScanner.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
// Uncomment bellow in case of a problem and rebuild sketch
3030
//#define INFLUXDB_CLIENT_DEBUG_ENABLE
3131
#include "util/debug.h"
32+
#include "util/helpers.h"
3233

3334
HttpStreamScanner::HttpStreamScanner(HTTPClient *client, bool chunked)
3435
{
@@ -37,7 +38,7 @@ HttpStreamScanner::HttpStreamScanner(HTTPClient *client, bool chunked)
3738
_chunked = chunked;
3839
_chunkHeader = chunked;
3940
_len = client->getSize();
40-
INFLUXDB_CLIENT_DEBUG("[D] HttpStreamScanner: chunked: %s, size: %d\n", _chunked?"true":"false", _len);
41+
INFLUXDB_CLIENT_DEBUG("[D] HttpStreamScanner: chunked: %s, size: %d\n", bool2string(_chunked), _len);
4142
}
4243

4344
bool HttpStreamScanner::next() {

src/util/helpers.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,6 @@ bool isValidID(const char *idString) {
161161
return true;
162162
}
163163

164+
const char *bool2string(bool val) {
165+
return (val?"true":"false");
166+
}

src/util/helpers.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ String escapeValue(const char *value);
5050
String urlEncode(const char* src);
5151
// Returns true of string contains valid InfluxDB ID type
5252
bool isValidID(const char *idString);
53-
53+
// Return "true" if val is true, otherwise "false"
54+
const char *bool2string(bool val);
5455

5556
#endif //_INFLUXDB_CLIENT_HELPERS_H

0 commit comments

Comments
 (0)