aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--host/lib/transport/nirio/nifpga_lvbitx.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/host/lib/transport/nirio/nifpga_lvbitx.cpp b/host/lib/transport/nirio/nifpga_lvbitx.cpp
index 2d8b63293..ef4a02aff 100644
--- a/host/lib/transport/nirio/nifpga_lvbitx.cpp
+++ b/host/lib/transport/nirio/nifpga_lvbitx.cpp
@@ -17,21 +17,31 @@ namespace uhd { namespace niusrprio {
std::string nifpga_lvbitx::_get_bitstream_checksum(const std::string& file_path)
{
- std::string checksum;
+ const boost::regex md5_regex(
+ "<BitstreamMD5>([a-fA-F0-9]{32})<\\/BitstreamMD5>",
+ boost::regex::icase);
+
std::ifstream lvbitx_stream(file_path.c_str());
- if (lvbitx_stream.is_open()) {
- std::string lvbitx_contents;
- lvbitx_stream.seekg(0, std::ios::end);
- lvbitx_contents.reserve(static_cast<size_t>(lvbitx_stream.tellg()));
- lvbitx_stream.seekg(0, std::ios::beg);
- lvbitx_contents.assign((std::istreambuf_iterator<char>(lvbitx_stream)), std::istreambuf_iterator<char>());
+ if (!lvbitx_stream.is_open()) {
+ return std::string();
+ }
+
+ std::string checksum, line;
+ while (std::getline(lvbitx_stream, line))
+ {
try {
+ // short-circuiting the regex search with a simple find is faster
+ // for cases where the tag doesn't exist
boost::smatch md5_match;
- if (boost::regex_search(lvbitx_contents, md5_match, boost::regex("<BitstreamMD5>([a-zA-Z0-9]{32})<\\/BitstreamMD5>", boost::regex::icase))) {
+ if (line.find("<BitstreamMD5>") != std::string::npos &&
+ boost::regex_search(line, md5_match, md5_regex))
+ {
checksum = std::string(md5_match[1].first, md5_match[1].second);
+ break;
}
- } catch (boost::exception&) {
- checksum = "";
+ }
+ catch (boost::exception&) {
+
}
}
boost::to_upper(checksum);