diff options
author | Sven Gothel <[email protected]> | 2020-12-10 05:24:55 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-12-10 05:24:55 +0100 |
commit | 5516f18c212d3e7f6ca56691647095636542efe8 (patch) | |
tree | e886f8da5bddf1cd12dc074069ec1febbb9197f0 /src | |
parent | 1c68f35a53cf4f759d473bb119954c2111e2f339 (diff) |
EUI48::toString(): Use fast jau::byteHexString() instead of snprintf()
Diffstat (limited to 'src')
-rw-r--r-- | src/direct_bt/BTTypes.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/direct_bt/BTTypes.cpp b/src/direct_bt/BTTypes.cpp index f1553941..894219b1 100644 --- a/src/direct_bt/BTTypes.cpp +++ b/src/direct_bt/BTTypes.cpp @@ -146,15 +146,14 @@ BLERandomAddressType EUI48::getBLERandomAddressType(const BDAddressType addressT } std::string EUI48::toString() const { - const int length = 17; std::string str; - str.reserve(length+1); // including EOS for snprintf - str.resize(length); + str.reserve(17); - const int count = snprintf(&str[0], str.capacity(), "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", - b[5], b[4], b[3], b[2], b[1], b[0]); - if( length != count ) { - throw jau::InternalError("EUI48 string not of length "+std::to_string(length)+" but "+std::to_string(count), E_FILE_LINE); + for(int i=6-1; 0 <= i; i--) { + jau::byteHexString(str, b[i], false /* lowerCase */); + if( 0 < i ) { + str.push_back(':'); + } } return str; } |