Coverage Report

Created: 2025-09-05 06:52

/src/serenity/Userland/Libraries/LibDNS/Name.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3
 * Copyright (c) 2021, Sergey Bugaev <bugaevc@serenityos.org>
4
 *
5
 * SPDX-License-Identifier: BSD-2-Clause
6
 */
7
8
#pragma once
9
10
#include <AK/ByteString.h>
11
#include <AK/Forward.h>
12
13
namespace DNS {
14
15
class Name {
16
public:
17
824k
    Name() = default;
18
    Name(ByteString const&);
19
20
    static ErrorOr<Name> parse(ReadonlyBytes data, size_t& offset, size_t recursion_level = 0);
21
22
    size_t serialized_size() const;
23
5.93M
    ByteString const& as_string() const { return m_name; }
24
    ErrorOr<void> write_to_stream(Stream&) const;
25
26
    void randomize_case();
27
28
0
    bool operator==(Name const& other) const { return Traits::equals(*this, other); }
29
30
    class Traits : public AK::Traits<Name> {
31
    public:
32
        static unsigned hash(Name const& name);
33
        static bool equals(Name const&, Name const&);
34
    };
35
36
private:
37
    ByteString m_name;
38
};
39
40
}
41
42
template<>
43
struct AK::Formatter<DNS::Name> : Formatter<StringView> {
44
    ErrorOr<void> format(FormatBuilder& builder, DNS::Name const& value)
45
0
    {
46
0
        return Formatter<StringView>::format(builder, value.as_string());
47
0
    }
48
};