Skip to content

Commit 6eb3214

Browse files
authored
Add hex decode function with const char* (#28)
* add hex decode function with const char*
1 parent d4e6b08 commit 6eb3214

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/hex/hex.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ namespace arduino { namespace hex {
2828
}
2929

3030
bool decode(const String in, uint8_t* out, uint32_t size) {
31+
return decode(in.c_str(), out, size);
32+
}
33+
34+
bool decode(const char *in, uint8_t* out, uint32_t size) {
3135
unsigned int byteNumber;
32-
byteNumber = chex_decode(out, size, in.begin(), in.length());
33-
return byteNumber * 2 == in.length();
36+
size_t len = strlen(in);
37+
byteNumber = chex_decode(out, size, in, len);
38+
return byteNumber * 2 == len;
3439
}
3540

3641
}} // arduino::hex

src/hex/hex.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace arduino { namespace hex {
2020

2121
String encode(const uint8_t* in, uint32_t size);
2222
String encodeUpper(const uint8_t* in, uint32_t size);
23-
23+
bool decode(const char *in, uint8_t* out, uint32_t size);
2424
bool decode(const String in, uint8_t* out, uint32_t size);
2525
}} // arduino::hex
2626

@@ -37,4 +37,7 @@ class THEXT {
3737
return arduino::hex::decode(in, out, size);
3838
}
3939

40+
static inline bool decode(const char *in, uint8_t* out, uint32_t size) {
41+
return arduino::hex::decode(in, out, size);
42+
}
4043
};

0 commit comments

Comments
 (0)