Coverage Report

Created: 2025-09-02 06:46

/src/connectedhomeip/src/app/MessageDef/AttributeDataIBs.cpp
Line
Count
Source (jump to first uncovered line)
1
/**
2
 *
3
 *    Copyright (c) 2020 Project CHIP Authors
4
 *    Copyright (c) 2018 Google LLC.
5
 *    Copyright (c) 2016-2017 Nest Labs, Inc.
6
 *    Licensed under the Apache License, Version 2.0 (the "License");
7
 *    you may not use this file except in compliance with the License.
8
 *    You may obtain a copy of the License at
9
 *
10
 *        http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 *    Unless required by applicable law or agreed to in writing, software
13
 *    distributed under the License is distributed on an "AS IS" BASIS,
14
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 *    See the License for the specific language governing permissions and
16
 *    limitations under the License.
17
 */
18
/**
19
 *    @file
20
 *      This file defines AttributeDataIBs parser and builder in CHIP interaction model
21
 *
22
 */
23
24
#include "AttributeDataIBs.h"
25
26
#include "MessageDefHelper.h"
27
28
#include <inttypes.h>
29
#include <stdarg.h>
30
#include <stdio.h>
31
32
#include <app/AppConfig.h>
33
34
using namespace chip;
35
using namespace chip::TLV;
36
37
namespace chip {
38
namespace app {
39
#if CHIP_CONFIG_IM_PRETTY_PRINT
40
CHIP_ERROR AttributeDataIBs::Parser::PrettyPrint() const
41
0
{
42
0
    CHIP_ERROR err        = CHIP_NO_ERROR;
43
0
    size_t numDataElement = 0;
44
0
    chip::TLV::TLVReader reader;
45
46
0
    PRETTY_PRINT("AttributeDataIBs =");
47
0
    PRETTY_PRINT("[");
48
49
    // make a copy of the reader
50
0
    reader.Init(mReader);
51
52
0
    while (CHIP_NO_ERROR == (err = reader.Next()))
53
0
    {
54
0
        VerifyOrReturnError(TLV::AnonymousTag() == reader.GetTag(), CHIP_ERROR_INVALID_TLV_TAG);
55
0
        VerifyOrReturnError(TLV::kTLVType_Structure == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
56
57
0
        {
58
0
            AttributeDataIB::Parser data;
59
0
            ReturnErrorOnFailure(data.Init(reader));
60
61
0
            PRETTY_PRINT_INCDEPTH();
62
0
            ReturnErrorOnFailure(data.PrettyPrint());
63
0
            PRETTY_PRINT_DECDEPTH();
64
0
        }
65
66
0
        ++numDataElement;
67
0
    }
68
69
0
    PRETTY_PRINT("],");
70
0
    PRETTY_PRINT_BLANK_LINE();
71
72
    // if we have exhausted this container
73
0
    if (CHIP_END_OF_TLV == err)
74
0
    {
75
        // if we have at least one data element
76
0
        if (numDataElement > 0)
77
0
        {
78
0
            err = CHIP_NO_ERROR;
79
0
        }
80
0
    }
81
0
    ReturnErrorOnFailure(err);
82
0
    return reader.ExitContainer(mOuterContainerType);
83
0
}
84
#endif // CHIP_CONFIG_IM_PRETTY_PRINT
85
86
AttributeDataIB::Builder & AttributeDataIBs::Builder::CreateAttributeDataIBBuilder()
87
0
{
88
    // skip if error has already been set
89
0
    VerifyOrExit(CHIP_NO_ERROR == mError, mAttributeDataIBBuilder.ResetError(mError));
90
91
0
    mError = mAttributeDataIBBuilder.Init(mpWriter);
92
93
0
exit:
94
95
    // on error, mAttributeDataIBBuilder would be un-/partial initialized and cannot be used to write anything
96
0
    return mAttributeDataIBBuilder;
97
0
}
98
99
AttributeDataIB::Builder & AttributeDataIBs::Builder::GetAttributeDataIBBuilder()
100
0
{
101
0
    return mAttributeDataIBBuilder;
102
0
}
103
104
CHIP_ERROR AttributeDataIBs::Builder::EndOfAttributeDataIBs()
105
0
{
106
0
    EndOfContainer();
107
108
0
    return GetError();
109
0
}
110
111
}; // namespace app
112
}; // namespace chip