From 0f05d5874e5ecb5435cbbb45b70c51710569b160 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Tue, 8 Aug 2023 10:24:52 -0700 Subject: [PATCH] encode as int --- packages/pigeon/lib/cpp_generator.dart | 11 ++++++----- .../test_plugin/windows/pigeon/core_tests.gen.cpp | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 1cc3dc228172..c35e3e5beca0 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -1211,6 +1211,10 @@ return EncodableValue(EncodableList{ final String errorGetter; const String nullValue = 'EncodableValue()'; + String enumPrefix = ''; + if (isEnum(root, returnType)) { + enumPrefix = '(int) '; + } if (returnType.isVoid) { nonErrorPath = '${prefix}wrapped.push_back($nullValue);'; errorCondition = 'output.has_value()'; @@ -1218,10 +1222,7 @@ return EncodableValue(EncodableList{ } else { final HostDatatype hostType = getHostDatatype(returnType, root.classes, root.enums, _shortBaseCppTypeForBuiltinDartType); - String enumPrefix = ''; - if (isEnum(root, returnType)) { - enumPrefix = '(int) '; - } + const String extractedValue = 'std::move(output).TakeValue()'; final String wrapperType = hostType.isBuiltin || isEnum(root, returnType) ? 'EncodableValue' @@ -1232,7 +1233,7 @@ return EncodableValue(EncodableList{ nonErrorPath = ''' ${prefix}auto output_optional = $extractedValue; ${prefix}if (output_optional) { -$prefix\twrapped.push_back($wrapperType(std::move(output_optional).value())); +$prefix\twrapped.push_back($wrapperType(${enumPrefix}std::move(output_optional).value())); $prefix} else { $prefix\twrapped.push_back($nullValue); $prefix}'''; diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp index 00b831d42e6b..6f7f5a80a1af 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp @@ -1743,7 +1743,7 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, auto output_optional = std::move(output).TakeValue(); if (output_optional) { wrapped.push_back( - EncodableValue(std::move(output_optional).value())); + EncodableValue((int)std::move(output_optional).value())); } else { wrapped.push_back(EncodableValue()); }