• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

afxres / binary-cxx / 13052939166

30 Jan 2025 01:02PM UTC coverage: 98.741% (-0.9%) from 99.633%
13052939166

push

github

afxres
Fix header usages

14 of 16 new or added lines in 4 files covered. (87.5%)

3 existing lines in 1 file now uncovered.

549 of 556 relevant lines covered (98.74%)

71.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.0
/next/binary/include/binary/Converter.hpp
1
#ifndef BINARY_CONVERTER_HPP
2
#define BINARY_CONVERTER_HPP
3

4
#include <cstddef>
5
#include <span>
6

7
#include "binary/Allocator.hpp"
8
#include "binary/ConverterExtensions.hpp"
9
#include "binary/IConverter.hpp"
10
#include "binary/internal/AllocatorUnsafeAccessor.hpp"
11

12
namespace binary {
13
template <typename T>
14
    requires std::same_as<T, std::remove_cv_t<T>>
15
class Converter : public IConverter {
16
public:
17
    Converter()
159✔
18
        : IConverter(typeid(Converter<T>)) {}
159✔
19

20
    Converter(size_t length)
353✔
21
        : IConverter(typeid(Converter<T>), length) {}
353✔
22

23
    virtual void Encode(Allocator& allocator, const T& item) = 0;
24

25
    virtual void EncodeAuto(Allocator& allocator, const T& item) {
60✔
26
        size_t length = Length();
60✔
27
        if (length != 0) {
60✔
28
            Encode(allocator, item);
58✔
29
        } else {
30
            EncodeWithLengthPrefix(allocator, item);
2✔
31
        }
32
    }
60✔
33

34
    virtual void EncodeWithLengthPrefix(Allocator& allocator, const T& item) {
6✔
35
        size_t anchor = internal::AllocatorUnsafeAccessor::Anchor(allocator);
6✔
36
        Encode(allocator, item);
6✔
37
        internal::AllocatorUnsafeAccessor::FinishAnchor(allocator, anchor);
6✔
38
    }
6✔
39

40
    virtual T Decode(const std::span<const std::byte>& span) = 0;
41

42
    virtual T DecodeAuto(std::span<const std::byte>& span) {
58✔
43
        size_t length = Length();
58✔
44
        if (length != 0) {
58✔
45
            T result = Decode(span);
58✔
46
            span = span.subspan(length);
58✔
47
            return result;
58✔
48
        } else {
×
UNCOV
49
            return DecodeWithLengthPrefix(span);
×
50
        }
51
    }
52

UNCOV
53
    virtual T DecodeWithLengthPrefix(std::span<const std::byte>& span) {
×
UNCOV
54
        return Decode(::binary::DecodeWithLengthPrefix(span));
×
55
    }
56
};
57
}
58

59
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc