-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic codegen and Encode/Decode support for nullable and optional…
… struct/command/event fields (#10891) * Add basic support for nullable and optional fields. Affects command fields, event fields, struct fields. * Add some unit tests for nullable and optional encode/decode * Add simple optional/nullable end-to-end test.
- Loading branch information
1 parent
19a8dcd
commit 1493868
Showing
41 changed files
with
2,115 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 17 additions & 3 deletions
20
examples/chip-tool/templates/partials/test_cluster_command_value.zapt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* | ||
* Copyright (c) 2020-2021 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <lib/core/Optional.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace DataModel { | ||
|
||
/* | ||
* Dedicated type for nullable things, to differentiate them from optional | ||
* things. | ||
*/ | ||
template <typename T> | ||
struct Nullable : protected Optional<T> | ||
{ | ||
// | ||
// The following 'using' statement is needed to make visible | ||
// all constructors of the base class within this derived class. | ||
// | ||
using Optional<T>::Optional; | ||
|
||
// Pull in APIs that make sense on Nullable with the same names as on | ||
// Optional. | ||
using Optional<T>::Value; | ||
|
||
constexpr void SetNull() { Optional<T>::ClearValue(); } | ||
constexpr bool IsNull() const { return !Optional<T>::HasValue(); } | ||
|
||
template <class... Args> | ||
constexpr T & SetNonNull(Args &&... args) | ||
{ | ||
return Optional<T>::Emplace(std::forward<Args>(args)...); | ||
} | ||
}; | ||
|
||
} // namespace DataModel | ||
} // namespace app | ||
} // namespace chip |
Oops, something went wrong.