mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 07:08:10 +08:00
[pigeon] wrap encodable lists in encodable value before reply (#2968)
* wrap encodable lists before reply * Changelog * changelog * basic test * positive test and move * nit
This commit is contained in:
@ -1,3 +1,7 @@
|
|||||||
|
## 4.2.14
|
||||||
|
|
||||||
|
* [c++] Fixes reply sending non EncodableValue wrapped lists.
|
||||||
|
|
||||||
## 4.2.13
|
## 4.2.13
|
||||||
|
|
||||||
* Add documentation comment support for Enum members.
|
* Add documentation comment support for Enum members.
|
||||||
|
@ -590,7 +590,7 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() {
|
|||||||
indent.write('if ($encodableArgName.IsNull()) ');
|
indent.write('if ($encodableArgName.IsNull()) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.scoped('{', '}', () {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'reply(WrapError("$argName unexpectedly null."));');
|
'reply(flutter::EncodableValue(WrapError("$argName unexpectedly null.")));');
|
||||||
indent.writeln('return;');
|
indent.writeln('return;');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -656,7 +656,7 @@ $prefix\t}${indent.newline}''';
|
|||||||
if (method.isAsynchronous) {
|
if (method.isAsynchronous) {
|
||||||
methodArgument.add(
|
methodArgument.add(
|
||||||
'[&wrapped, &reply]($returnTypeName&& output) {${indent.newline}'
|
'[&wrapped, &reply]($returnTypeName&& output) {${indent.newline}'
|
||||||
'${wrapResponse('\treply(wrapped);${indent.newline}', method.returnType)}'
|
'${wrapResponse('\treply(flutter::EncodableValue(std::move(wrapped)));${indent.newline}', method.returnType)}'
|
||||||
'}',
|
'}',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -673,11 +673,13 @@ $prefix\t}${indent.newline}''';
|
|||||||
indent.scoped('{', '}', () {
|
indent.scoped('{', '}', () {
|
||||||
indent.writeln('wrapped = WrapError(exception.what());');
|
indent.writeln('wrapped = WrapError(exception.what());');
|
||||||
if (method.isAsynchronous) {
|
if (method.isAsynchronous) {
|
||||||
indent.writeln('reply(wrapped);');
|
indent.writeln(
|
||||||
|
'reply(flutter::EncodableValue(std::move(wrapped)));');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!method.isAsynchronous) {
|
if (!method.isAsynchronous) {
|
||||||
indent.writeln('reply(wrapped);');
|
indent.writeln(
|
||||||
|
'reply(flutter::EncodableValue(std::move(wrapped)));');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -9,7 +9,7 @@ import 'dart:mirrors';
|
|||||||
import 'ast.dart';
|
import 'ast.dart';
|
||||||
|
|
||||||
/// The current version of pigeon. This must match the version in pubspec.yaml.
|
/// The current version of pigeon. This must match the version in pubspec.yaml.
|
||||||
const String pigeonVersion = '4.2.13';
|
const String pigeonVersion = '4.2.14';
|
||||||
|
|
||||||
/// Read all the content from [stdin] to a String.
|
/// Read all the content from [stdin] to a String.
|
||||||
String readStdin() {
|
String readStdin() {
|
||||||
|
@ -2,7 +2,7 @@ name: pigeon
|
|||||||
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
|
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
|
||||||
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
|
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
|
||||||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
|
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
|
||||||
version: 4.2.13 # This must match the version in lib/generator_tools.dart
|
version: 4.2.14 # This must match the version in lib/generator_tools.dart
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.12.0 <3.0.0"
|
sdk: ">=2.12.0 <3.0.0"
|
||||||
|
@ -1203,4 +1203,74 @@ void main() {
|
|||||||
final String code = sink.toString();
|
final String code = sink.toString();
|
||||||
expect(code, contains(' : public flutter::StandardCodecSerializer'));
|
expect(code, contains(' : public flutter::StandardCodecSerializer'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Does not send unwrapped EncodableLists', () {
|
||||||
|
final Root root = Root(apis: <Api>[
|
||||||
|
Api(name: 'Api', location: ApiLocation.host, methods: <Method>[
|
||||||
|
Method(
|
||||||
|
name: 'doSomething',
|
||||||
|
arguments: <NamedType>[
|
||||||
|
NamedType(
|
||||||
|
name: 'aBool',
|
||||||
|
type: const TypeDeclaration(
|
||||||
|
baseName: 'bool',
|
||||||
|
isNullable: false,
|
||||||
|
)),
|
||||||
|
NamedType(
|
||||||
|
name: 'anInt',
|
||||||
|
type: const TypeDeclaration(
|
||||||
|
baseName: 'int',
|
||||||
|
isNullable: false,
|
||||||
|
)),
|
||||||
|
NamedType(
|
||||||
|
name: 'aString',
|
||||||
|
type: const TypeDeclaration(
|
||||||
|
baseName: 'String',
|
||||||
|
isNullable: false,
|
||||||
|
)),
|
||||||
|
NamedType(
|
||||||
|
name: 'aList',
|
||||||
|
type: const TypeDeclaration(
|
||||||
|
baseName: 'List',
|
||||||
|
typeArguments: <TypeDeclaration>[
|
||||||
|
TypeDeclaration(baseName: 'Object', isNullable: true)
|
||||||
|
],
|
||||||
|
isNullable: false,
|
||||||
|
)),
|
||||||
|
NamedType(
|
||||||
|
name: 'aMap',
|
||||||
|
type: const TypeDeclaration(
|
||||||
|
baseName: 'Map',
|
||||||
|
typeArguments: <TypeDeclaration>[
|
||||||
|
TypeDeclaration(baseName: 'String', isNullable: true),
|
||||||
|
TypeDeclaration(baseName: 'Object', isNullable: true),
|
||||||
|
],
|
||||||
|
isNullable: false,
|
||||||
|
)),
|
||||||
|
NamedType(
|
||||||
|
name: 'anObject',
|
||||||
|
type: const TypeDeclaration(
|
||||||
|
baseName: 'ParameterObject',
|
||||||
|
isNullable: false,
|
||||||
|
)),
|
||||||
|
],
|
||||||
|
returnType: const TypeDeclaration.voidDeclaration(),
|
||||||
|
),
|
||||||
|
])
|
||||||
|
], classes: <Class>[
|
||||||
|
Class(name: 'ParameterObject', fields: <NamedType>[
|
||||||
|
NamedType(
|
||||||
|
type: const TypeDeclaration(
|
||||||
|
baseName: 'bool',
|
||||||
|
isNullable: false,
|
||||||
|
),
|
||||||
|
name: 'aValue'),
|
||||||
|
]),
|
||||||
|
], enums: <Enum>[]);
|
||||||
|
final StringBuffer sink = StringBuffer();
|
||||||
|
generateCppSource(const CppOptions(), root, sink);
|
||||||
|
final String code = sink.toString();
|
||||||
|
expect(code, isNot(contains('reply(wrap')));
|
||||||
|
expect(code, contains('reply(flutter::EncodableValue('));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user