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

KazDragon / telnetpp / 15539371610

09 Jun 2025 04:24PM UTC coverage: 97.534% (+0.03%) from 97.509%
15539371610

push

github

KazDragon
refactor: replace boost::ignore_unused with attribute

7 of 7 new or added lines in 3 files covered. (100.0%)

6 existing lines in 3 files now uncovered.

1068 of 1095 relevant lines covered (97.53%)

256.7 hits per line

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

97.85
/include/telnetpp/parser.hpp
1
#pragma once
2

3
#include "telnetpp/command.hpp"
4
#include "telnetpp/core.hpp"
5
#include "telnetpp/negotiation.hpp"
6
#include "telnetpp/subnegotiation.hpp"
7

8
#include <algorithm>
9

10
namespace telnetpp {
11

12
class parser final
13
{
14
public:
15
    template <typename Continuation>
16
    constexpr void operator()(telnetpp::bytes data, Continuation &&c)
69✔
17
    {
18
        std::ranges::for_each(
69✔
19
            data, [&](telnetpp::byte by) { parse_byte(by, c); });
190✔
20

21
        emit_plain_data(c);
69✔
22
    }
69✔
23

24
private:
25
    enum class parsing_state : std::uint8_t
26
    {
27
        state_idle,
28
        state_iac,
29
        state_negotiation,
30
        state_subnegotiation,
31
        state_subnegotiation_content,
32
        state_subnegotiation_content_iac
33
    };
34

35
    parsing_state state_{parsing_state::state_idle};
36

37
    telnetpp::byte_storage plain_data_;
38
    telnetpp::byte_storage subnegotiation_content_;
39
    telnetpp::negotiation_type negotiation_type_;
40
    telnetpp::option_type subnegotiation_option_;
41

42
    template <typename Continuation>
43
    constexpr void parse_byte(telnetpp::byte by, Continuation &&c)
190✔
44
    {
45
        switch (state_)
190✔
46
        {
47
            case parsing_state::state_idle:
79✔
48
                parse_idle(by, c);
79✔
49
                break;
79✔
50

51
            case parsing_state::state_iac:
45✔
52
                parse_iac(by, c);
45✔
53
                break;
45✔
54

55
            case parsing_state::state_negotiation:
15✔
56
                parse_negotiation(by, c);
15✔
57
                break;
15✔
58

59
            case parsing_state::state_subnegotiation:
11✔
60
                parse_subnegotiation(by, c);
11✔
61
                break;
11✔
62

63
            case parsing_state::state_subnegotiation_content:
31✔
64
                parse_subnegotiation_content(by, c);
31✔
65
                break;
31✔
66

67
            case parsing_state::state_subnegotiation_content_iac:
9✔
68
                parse_subnegotiation_content_iac(by, c);
9✔
69
                break;
9✔
70

UNCOV
71
            default:
×
UNCOV
72
                break;
×
73
        }
74
    }
190✔
75

76
    template <typename Continuation>
77
    constexpr void parse_idle(telnetpp::byte by, Continuation &&c)
79✔
78
    {
79
        switch (by)
79✔
80
        {
81
            case telnetpp::iac:
47✔
82
                state_ = parsing_state::state_iac;
47✔
83
                break;
47✔
84

85
            default:
32✔
86
                plain_data_.push_back(by);
32✔
87
                break;
32✔
88
        }
89
    }
79✔
90

91
    template <typename Continuation>
92
    constexpr void parse_iac(telnetpp::byte by, Continuation &&c)
45✔
93
    {
94
        switch (by)
45✔
95
        {
96
            case telnetpp::iac:
2✔
97
                plain_data_.push_back(by);
2✔
98
                state_ = parsing_state::state_idle;
2✔
99
                break;
2✔
100

101
            case telnetpp::will:  // fall-through
19✔
102
            case telnetpp::wont:  // fall-through
103
            case telnetpp::do_:   // fall-through
104
            case telnetpp::dont:
105
                emit_plain_data(c);
19✔
106
                negotiation_type_ = by;
19✔
107
                state_ = parsing_state::state_negotiation;
19✔
108
                break;
19✔
109

110
            case telnetpp::sb:
12✔
111
                emit_plain_data(c);
12✔
112
                state_ = parsing_state::state_subnegotiation;
12✔
113
                break;
12✔
114

115
            default:
12✔
116
                emit_plain_data(c);
12✔
117
                c(telnetpp::command{by});
12✔
118
                state_ = parsing_state::state_idle;
12✔
119
                break;
12✔
120
        }
121
    }
45✔
122

123
    template <typename Continuation>
124
    constexpr void parse_negotiation(telnetpp::byte by, Continuation &&c)
15✔
125
    {
126
        c(telnetpp::negotiation{negotiation_type_, by});
15✔
127
        state_ = parsing_state::state_idle;
15✔
128
    }
15✔
129

130
    template <typename Continuation>
131
    constexpr void parse_subnegotiation(telnetpp::byte by, Continuation &&c)
11✔
132
    {
133
        subnegotiation_option_ = by;
11✔
134
        subnegotiation_content_.clear();
11✔
135
        state_ = parsing_state::state_subnegotiation_content;
11✔
136
    }
11✔
137

138
    template <typename Continuation>
139
    constexpr void parse_subnegotiation_content(
31✔
140
        telnetpp::byte by, Continuation &&c)
141
    {
142
        switch (by)
31✔
143
        {
144
            case telnetpp::iac:
10✔
145
                state_ = parsing_state::state_subnegotiation_content_iac;
10✔
146
                break;
10✔
147

148
            default:
21✔
149
                subnegotiation_content_.push_back(by);
21✔
150
                break;
21✔
151
        }
152
    }
31✔
153

154
    template <typename Continuation>
155
    constexpr void parse_subnegotiation_content_iac(
9✔
156
        telnetpp::byte by, Continuation &&c)
157
    {
158
        switch (by)
9✔
159
        {
160
            case telnetpp::se:
8✔
161
                c(telnetpp::subnegotiation{
8✔
162
                    subnegotiation_option_, subnegotiation_content_});
8✔
163
                state_ = parsing_state::state_idle;
8✔
164
                break;
8✔
165

166
            default:
1✔
167
                subnegotiation_content_.push_back(by);
1✔
168
                state_ = parsing_state::state_subnegotiation_content;
1✔
169
                break;
1✔
170
        }
171
    }
9✔
172

173
    template <typename Continuation>
174
    constexpr void emit_plain_data(Continuation &&c)
112✔
175
    {
176
        if (!plain_data_.empty())
112✔
177
        {
178
            c(plain_data_);
20✔
179
            plain_data_.clear();
20✔
180
        }
181
    }
112✔
182
};
183

184
}  // namespace telnetpp
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