Skip to content

Commit

Permalink
Fix optional encode and decode (#15539)
Browse files Browse the repository at this point in the history
  • Loading branch information
austinh0 authored and pull[bot] committed Oct 20, 2023
1 parent 9f443ac commit 062970b
Show file tree
Hide file tree
Showing 6 changed files with 777 additions and 546 deletions.
4 changes: 3 additions & 1 deletion src/controller/java/templates/partials/decode_value.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ jobject {{target}};
if (!{{source}}.HasValue()) {
chip::JniReferences::GetInstance().CreateOptional(nullptr, {{target}});
} else {
{{>decode_value target=target source=(concat source ".Value()") cluster=cluster depth=(incrementDepth depth) isOptional=false omitDeclaration=true earlyReturn=earlyReturn}}
jobject {{target}}InsideOptional;
{{>decode_value target=(concat target "InsideOptional") source=(concat source ".Value()") cluster=cluster depth=(incrementDepth depth) isOptional=false omitDeclaration=true earlyReturn=earlyReturn}}
chip::JniReferences::GetInstance().CreateOptional({{target}}InsideOptional, {{target}});
}
{{else if isNullable}}
if ({{source}}.IsNull()) {
Expand Down
6 changes: 4 additions & 2 deletions src/controller/java/templates/partials/encode_value.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
if ({{source}} != nullptr) {
jobject optionalValue_{{depth}};
chip::JniReferences::GetInstance().GetOptionalValue({{source}}, optionalValue_{{depth}});
auto & definedValue_{{depth}} = {{target}}.Emplace();
{{>encode_value target=(concat "definedValue_" depth) source=(concat "optionalValue_" depth) cluster=cluster depth=(incrementDepth depth) isOptional=false}}
if (optionalValue_{{depth}} != nullptr) {
auto & definedValue_{{depth}} = {{target}}.Emplace();
{{>encode_value target=(concat "definedValue_" depth) source=(concat "optionalValue_" depth) cluster=cluster depth=(incrementDepth depth) isOptional=false}}
}
}
{{else if isNullable}}
if ({{source}} == nullptr) {
Expand Down
Loading

0 comments on commit 062970b

Please sign in to comment.