| 449 | } |
| 450 | |
| 451 | std::vector<char> VlrCatalog::fetchWithDescription(const std::string& userId, uint16_t recordId, |
| 452 | std::string& outDescrip) const |
| 453 | { |
| 454 | // We don't lock m_entries because we assume that the load has already occurred at the |
| 455 | // time you want to fetch. |
| 456 | std::vector<char> vlrdata; |
| 457 | const Entry& e = find(userId, recordId); |
| 458 | |
| 459 | // We don't support VLRs with size > 4GB |
| 460 | if (e.length == 0 || e.length > (std::numeric_limits<uint32_t>::max)()) |
| 461 | return vlrdata; |
| 462 | |
| 463 | uint64_t offset = e.offset; |
| 464 | uint32_t length = (uint32_t)e.length; |
| 465 | |
| 466 | // Load the data plus the description. |
| 467 | const int DescripLen = 32; |
| 468 | assert(offset > DescripLen); |
| 469 | // Add space for the description that precedes the data |
| 470 | std::vector<char> v = m_fetch(offset - DescripLen, length + DescripLen); |
| 471 | |
| 472 | // Only make the string with non-null characters. |
| 473 | int len = DescripLen - 1; |
| 474 | while (len >= 0) |
| 475 | { |
| 476 | if (v[len]) |
| 477 | break; |
| 478 | len--; |
| 479 | } |
| 480 | outDescrip.assign(v.data(), v.data() + len + 1); |
| 481 | |
| 482 | // Assign the payload of the VLR to the output VLR. |
| 483 | vlrdata.assign(v.data() + DescripLen, v.data() + v.size()); |
| 484 | return vlrdata; |
| 485 | } |
| 486 | |
| 487 | |
| 488 | } // namespace las |
no test coverage detected