Skip to content

Overhaul Utils/Binary implementation

Enrico Gamberini requested to merge overhaul-binary into master

This MR overhauls and reimplements the BLOB wrapper daqutils::Binary. The class now wraps around a std::vector instead of a void* for simplicity, and no calls are made to the shared global logger. If an internal allocation fails the m_error field will be set to Binary::error_code::alloc; if instead an invalid argument is passed to a ctor, it is set to Binary::error_code::invalid_arg. The status of the Binary instance can be checked with std::optional<error_code> Binary::error(). Usage of a Binary in an error state is currently undefined behavior (asserts block the way presently).

Other notable changes is the addition of a move constructor and assignment operator. void* Binary::data() has been templated to T Binary::data<T>(), where T must be a pointer type and defaults to void*. Finally, std::ostream& operator<<(std::ostream&, const Binary&) has been altered to write a xxd(1)-like representation of its content, e.g.:

00000000: 736f 6d65 2073 7472 696e 673b 2075 6e70  some string; unp
00000010: 7269 6e74 6162 6c65 2063 6861 7273 3a20  rintable chars:
00000020: 0102 0304 05                             .....
Edited by Enrico Gamberini

Merge request reports