Skip to content

Commit

Permalink
encode as int
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrinneal committed Aug 8, 2023
1 parent 6b671d8 commit 0f05d58
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions packages/pigeon/lib/cpp_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1211,17 +1211,18 @@ 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()';
errorGetter = 'value';
} 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'
Expand All @@ -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}''';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 0f05d58

Please sign in to comment.