commit | a7ec8ba8fb31fe182f19a128e30fbe7b4f97aebd | [log] [tgz] |
---|---|---|
author | Steven Moreland <smoreland@google.com> | Fri Jul 23 18:10:35 2021 -0700 |
committer | Steven Moreland <smoreland@google.com> | Thu Jul 29 21:55:38 2021 +0000 |
tree | 23eb34f11a2406b890a0ec5c141edf9c3c243193 | |
parent | 18c2bd4f3607cb300bb96e543df91dfdda6a9655 [diff] |
libbase: hex.h adds HexString This requires a few lines of code to implement in C++, but the 'standard' implementation also triggers ubsan implicit-conversion, so it can be more involved in some places. It's really common to convert binary data into hex strings. Future considerations: - adding the reverse direction (parse binary data into uint8_t*) - adding templated versions, which can be useful while debugging certain issues (though, perhaps a bit overkill) template <typename T> std::string HexObject(const T& t) { return HexString(reinterpret_cast<void*>(&t), sizeof(T)); } Bug: N/A Test: libbase_test Change-Id: I93d3708a9740a0682c8cbd91f067e2dfeab35380
This library is a collection of convenience functions to make common tasks easier and less error-prone.
In this context, "error-prone" covers both "hard to do correctly" and "hard to do with good performance", but as a general purpose library, libbase's primary focus is on making it easier to do things easily and correctly when a compromise has to be made between "simplest API" on the one hand and "fastest implementation" on the other. Though obviously the ideal is to have both.
The intention is to cover the 80% use cases, not be all things to all users.
If you have a routine that's really useful in your project, congratulations. But that doesn't mean it should be here rather than just in your project.
The question for libbase is "should everyone be doing this?"/"does this make everyone's code cleaner/safer?". Historically we've considered the bar for inclusion to be "are there at least three unrelated projects that would be cleaned up by doing so".
If your routine is actually something from a future C++ standard (that isn't yet in libc++), or it's widely used in another library, that helps show that there's precedent. Being able to say "so-and-so has used this API for n years" is a good way to reduce concerns about API choices.
Unlike most Android code, code in libbase has to build for Mac and Windows too.
Code here is also expected to have good test coverage.
By its nature, it's difficult to change libbase API. It's often best to start using your routine just in your project, and let it "graduate" after you're certain that the API is solid.