LCOV - code coverage report
Current view: top level - tests/integration/harness/gkfs.io - binary_buffer.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 21 21 100.0 %
Date: 2024-04-23 00:09:24 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   Copyright 2018-2024, Barcelona Supercomputing Center (BSC), Spain
       3             :   Copyright 2015-2024, Johannes Gutenberg Universitaet Mainz, Germany
       4             : 
       5             :   This software was partially supported by the
       6             :   EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).
       7             : 
       8             :   This software was partially supported by the
       9             :   ADA-FS project under the SPPEXA project funded by the DFG.
      10             : 
      11             :   This file is part of GekkoFS.
      12             : 
      13             :   GekkoFS is free software: you can redistribute it and/or modify
      14             :   it under the terms of the GNU General Public License as published by
      15             :   the Free Software Foundation, either version 3 of the License, or
      16             :   (at your option) any later version.
      17             : 
      18             :   GekkoFS is distributed in the hope that it will be useful,
      19             :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      20             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      21             :   GNU General Public License for more details.
      22             : 
      23             :   You should have received a copy of the GNU General Public License
      24             :   along with GekkoFS.  If not, see <https://www.gnu.org/licenses/>.
      25             : 
      26             :   SPDX-License-Identifier: GPL-3.0-or-later
      27             : */
      28             : 
      29             : #ifndef IO_BINARY_BUFFER_HPP
      30             : #define IO_BINARY_BUFFER_HPP
      31             : 
      32             : #include <nlohmann/json.hpp>
      33             : #include <utility>
      34             : #include <fmt/format.h>
      35             : 
      36             : 
      37             : namespace io {
      38             : 
      39         108 : struct buffer {
      40          43 :     buffer(::size_t size = 0) : m_data(size) {}
      41             : 
      42           1 :     buffer(nullptr_t p) {}
      43             : 
      44          42 :     buffer(const std::string& s) {
      45          42 :         m_data.clear();
      46          42 :         std::copy(s.begin(), s.end(), std::back_inserter(m_data));
      47          42 :     }
      48             : 
      49           4 :     buffer(std::vector<uint8_t> data) : m_data(std::move(data)) {}
      50             : 
      51             :     bool
      52          19 :     operator==(nullptr_t) const {
      53          19 :         return m_data.empty();
      54             :     }
      55             : 
      56             :     bool
      57             :     operator!=(nullptr_t) const {
      58             :         return !m_data.empty();
      59             :     }
      60             : 
      61             :     auto
      62          85 :     data() {
      63          85 :         return m_data.data();
      64             :     }
      65             : 
      66             :     auto
      67          18 :     storage() const {
      68          18 :         return m_data;
      69             :     }
      70             : 
      71             :     std::size_t
      72           4 :     size() const {
      73           4 :         return m_data.size();
      74             :     }
      75             : 
      76             :     std::vector<uint8_t> m_data;
      77             : };
      78             : 
      79             : inline void
      80          19 : to_json(nlohmann::json& record, const buffer& out) {
      81             : 
      82          19 :     if(out == nullptr) {
      83           1 :         record = nullptr;
      84             :     } else {
      85             : 
      86             :         //    record = fmt::format("x{:2x}", fmt::join(out, "x"));
      87          18 :         record = out.storage();
      88             :     }
      89          19 : }
      90             : 
      91             : } // namespace io
      92             : 
      93             : #endif // IO_BINARY_BUFFER_HPP

Generated by: LCOV version 1.16