Coverage Report

Created: 2025-07-18 06:55

/src/opendnp3/cpp/lib/src/app/HeaderWriter.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2013-2022 Step Function I/O, LLC
3
 *
4
 * Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
5
 * LLC (https://stepfunc.io) under one or more contributor license agreements.
6
 * See the NOTICE file distributed with this work for additional information
7
 * regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
8
 * this file to you under the Apache License, Version 2.0 (the "License"); you
9
 * may not use this file except in compliance with the License. You may obtain
10
 * a copy of the License at:
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
#include "HeaderWriter.h"
21
22
#include <ser4cpp/serialization/LittleEndian.h>
23
24
#include <cassert>
25
26
namespace opendnp3
27
{
28
29
15.8k
HeaderWriter::HeaderWriter(ser4cpp::wseq_t* position_) : position(position_) {}
30
31
size_t HeaderWriter::Remaining() const
32
10.0k
{
33
10.0k
    return position->length();
34
10.0k
}
35
36
void HeaderWriter::Mark()
37
0
{
38
0
    mark.set(*position);
39
0
}
40
41
bool HeaderWriter::Rollback()
42
0
{
43
0
    if (mark.is_set())
44
0
    {
45
0
        *position = mark.get();
46
0
        mark.clear();
47
0
        return true;
48
0
    }
49
50
0
    return false;
51
0
}
52
53
bool HeaderWriter::WriteHeader(GroupVariationID id, QualifierCode qc)
54
31.2k
{
55
31.2k
    if (position->length() < 3)
56
0
    {
57
0
        return false;
58
0
    }
59
60
31.2k
    ser4cpp::UInt8::write_to(*position, id.group);
61
31.2k
    ser4cpp::UInt8::write_to(*position, id.variation);
62
31.2k
    ser4cpp::UInt8::write_to(*position, QualifierCodeSpec::to_type(qc));
63
31.2k
    return true;
64
31.2k
}
65
66
bool HeaderWriter::WriteHeaderWithReserve(GroupVariationID id, QualifierCode qc, size_t reserve)
67
10.9k
{
68
10.9k
    return (position->length() < (3 + reserve)) ? false : WriteHeader(id, qc);
69
10.9k
}
70
71
} // namespace opendnp3