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

tstack / lnav / 17589970077-2502

09 Sep 2025 05:00PM UTC coverage: 65.196% (-5.0%) from 70.225%
17589970077-2502

push

github

tstack
[format] add fields for source file/line

Knowing the source file/line context in a log
message can help find log messages when using
log2src.

56 of 70 new or added lines in 2 files covered. (80.0%)

13954 existing lines in 210 files now uncovered.

45516 of 69814 relevant lines covered (65.2%)

404154.37 hits per line

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

97.83
/src/byte_array.hh
1
/**
2
 * Copyright (c) 2007-2013, Timothy Stack
3
 *
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * * Redistributions of source code must retain the above copyright notice, this
10
 * list of conditions and the following disclaimer.
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 * this list of conditions and the following disclaimer in the documentation
13
 * and/or other materials provided with the distribution.
14
 * * Neither the name of Timothy Stack nor the names of its contributors
15
 * may be used to endorse or promote products derived from this software
16
 * without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
29
#ifndef byte_array_hh
30
#define byte_array_hh
31

32
#include <optional>
33
#include <ostream>
34
#include <string>
35

36
#include <stdio.h>
37
#include <string.h>
38
#include <sys/types.h>
39

40
#include "base/lnav_log.hh"
41
#include "fmt/format.h"
42

43
template<size_t COUNT, typename T = unsigned char>
44
struct byte_array {
45
    static constexpr size_t BYTE_COUNT = COUNT * sizeof(T);
46
    static constexpr size_t STRING_SIZE = BYTE_COUNT * 2 + 1;
47

48
    byte_array() = default;
2,728✔
49

50
    static byte_array from(std::initializer_list<T> bytes)
1✔
51
    {
52
        byte_array retval;
1✔
53
        size_t index = 0;
1✔
54

55
        for (const auto by : bytes) {
7✔
56
            retval.ba_data[index++] = by;
6✔
57
        }
58
        return retval;
1✔
59
    }
60

61
    byte_array(const byte_array& other)
62
    {
63
        memcpy(this->ba_data, other.ba_data, BYTE_COUNT);
64
    }
65

66
    bool operator<(const byte_array& other) const
67
    {
68
        return memcmp(this->ba_data, other.ba_data, BYTE_COUNT) < 0;
69
    }
70

71
    bool operator!=(const byte_array& other) const
49✔
72
    {
73
        return memcmp(this->ba_data, other.ba_data, BYTE_COUNT) != 0;
49✔
74
    }
75

76
    bool operator==(const byte_array& other) const
1✔
77
    {
78
        return memcmp(this->ba_data, other.ba_data, BYTE_COUNT) == 0;
1✔
79
    }
80

81
    void clear() { memset(this->ba_data, 0, BYTE_COUNT); }
604✔
82

83
    template<typename OutputIt>
84
    void to_string(OutputIt out,
1,865✔
85
                   std::optional<char> separator = std::nullopt) const
86
    {
87
        for (size_t lpc = 0; lpc < BYTE_COUNT; lpc++) {
31,695✔
88
            if (lpc > 0 && separator) {
29,830✔
89
                *out = separator.value();
20✔
90
            }
91
            fmt::format_to(out, FMT_STRING("{:02x}"), this->ba_data[lpc]);
119,320✔
92
        }
93
    }
1,865✔
94

95
    std::string to_uuid_string() const
3✔
96
    {
97
        return fmt::format(
98
            FMT_STRING("{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-"
6✔
99
                       "{:02x}{:02x}-{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}"),
100
            this->ba_data[0 % BYTE_COUNT],
3✔
101
            this->ba_data[1 % BYTE_COUNT],
3✔
102
            this->ba_data[2 % BYTE_COUNT],
3✔
103
            this->ba_data[3 % BYTE_COUNT],
3✔
104
            this->ba_data[4 % BYTE_COUNT],
3✔
105
            this->ba_data[5 % BYTE_COUNT],
3✔
106
            this->ba_data[6 % BYTE_COUNT],
3✔
107
            this->ba_data[7 % BYTE_COUNT],
3✔
108
            this->ba_data[8 % BYTE_COUNT],
3✔
109
            this->ba_data[9 % BYTE_COUNT],
3✔
110
            this->ba_data[10 % BYTE_COUNT],
3✔
111
            this->ba_data[11 % BYTE_COUNT],
3✔
112
            this->ba_data[12 % BYTE_COUNT],
3✔
113
            this->ba_data[13 % BYTE_COUNT],
3✔
114
            this->ba_data[14 % BYTE_COUNT],
3✔
115
            this->ba_data[15 % BYTE_COUNT]);
6✔
116
    }
117

118
    std::string to_string(std::optional<char> separator = std::nullopt) const
1,753✔
119
    {
120
        std::string retval;
1,753✔
121

122
        retval.reserve(STRING_SIZE);
1,753✔
123
        this->to_string(std::back_inserter(retval), separator);
1,753✔
124
        return retval;
1,753✔
UNCOV
125
    }
×
126

127
    const unsigned char* in() const { return this->ba_data; }
71✔
128

129
    T* out(int offset = 0)
15,854✔
130
    {
131
        T* ptr = (T*) this->ba_data;
15,854✔
132

133
        return &ptr[offset];
15,854✔
134
    }
135

136
    unsigned char ba_data[BYTE_COUNT]{};
137
};
138

139
template<size_t COUNT, typename T = unsigned char>
140
std::ostream&
141
operator<<(std::ostream& os, const byte_array<COUNT, T>& ba)
142
{
143
    os << ba.to_string();
144
    return os;
145
}
146

147
#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