mirror of
https://github.com/flutter/packages.git
synced 2026-03-13 10:40:37 +08:00
[pigeon] fix int bug (#7725)
fixes https://github.com/flutter/flutter/issues/155512
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
## 22.4.1
|
||||
|
||||
* [dart] Fixes bug where special handling of ints is ignored if no custom types are used.
|
||||
|
||||
## 22.4.0
|
||||
|
||||
* Adds support for non-nullable types in collections.
|
||||
|
||||
@@ -339,44 +339,42 @@ class DartGenerator extends StructuredGenerator<DartOptions> {
|
||||
indent.write('class $_pigeonCodec extends StandardMessageCodec');
|
||||
indent.addScoped(' {', '}', () {
|
||||
indent.writeln('const $_pigeonCodec();');
|
||||
if (enumeratedTypes.isNotEmpty) {
|
||||
indent.writeln('@override');
|
||||
indent.write('void writeValue(WriteBuffer buffer, Object? value) ');
|
||||
indent.addScoped('{', '}', () {
|
||||
indent.writeScoped('if (value is int) {', '}', () {
|
||||
indent.writeln('buffer.putUint8(4);');
|
||||
indent.writeln('buffer.putInt64(value);');
|
||||
}, addTrailingNewline: false);
|
||||
indent.writeln('@override');
|
||||
indent.write('void writeValue(WriteBuffer buffer, Object? value) ');
|
||||
indent.addScoped('{', '}', () {
|
||||
indent.writeScoped('if (value is int) {', '}', () {
|
||||
indent.writeln('buffer.putUint8(4);');
|
||||
indent.writeln('buffer.putInt64(value);');
|
||||
}, addTrailingNewline: false);
|
||||
|
||||
enumerate(enumeratedTypes,
|
||||
(int index, final EnumeratedType customType) {
|
||||
writeEncodeLogic(customType);
|
||||
});
|
||||
indent.addScoped(' else {', '}', () {
|
||||
indent.writeln('super.writeValue(buffer, value);');
|
||||
});
|
||||
enumerate(enumeratedTypes,
|
||||
(int index, final EnumeratedType customType) {
|
||||
writeEncodeLogic(customType);
|
||||
});
|
||||
indent.newln();
|
||||
indent.writeln('@override');
|
||||
indent.write('Object? readValueOfType(int type, ReadBuffer buffer) ');
|
||||
indent.addScoped(' else {', '}', () {
|
||||
indent.writeln('super.writeValue(buffer, value);');
|
||||
});
|
||||
});
|
||||
indent.newln();
|
||||
indent.writeln('@override');
|
||||
indent.write('Object? readValueOfType(int type, ReadBuffer buffer) ');
|
||||
indent.addScoped('{', '}', () {
|
||||
indent.write('switch (type) ');
|
||||
indent.addScoped('{', '}', () {
|
||||
indent.write('switch (type) ');
|
||||
indent.addScoped('{', '}', () {
|
||||
for (final EnumeratedType customType in enumeratedTypes) {
|
||||
if (customType.enumeration < maximumCodecFieldKey) {
|
||||
writeDecodeLogic(customType);
|
||||
}
|
||||
for (final EnumeratedType customType in enumeratedTypes) {
|
||||
if (customType.enumeration < maximumCodecFieldKey) {
|
||||
writeDecodeLogic(customType);
|
||||
}
|
||||
if (root.requiresOverflowClass) {
|
||||
writeDecodeLogic(overflowClass);
|
||||
}
|
||||
indent.writeln('default:');
|
||||
indent.nest(1, () {
|
||||
indent.writeln('return super.readValueOfType(type, buffer);');
|
||||
});
|
||||
}
|
||||
if (root.requiresOverflowClass) {
|
||||
writeDecodeLogic(overflowClass);
|
||||
}
|
||||
indent.writeln('default:');
|
||||
indent.nest(1, () {
|
||||
indent.writeln('return super.readValueOfType(type, buffer);');
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import 'ast.dart';
|
||||
/// The current version of pigeon.
|
||||
///
|
||||
/// This must match the version in pubspec.yaml.
|
||||
const String pigeonVersion = '22.4.0';
|
||||
const String pigeonVersion = '22.4.1';
|
||||
|
||||
/// Read all the content from [stdin] to a String.
|
||||
String readStdin() {
|
||||
|
||||
@@ -21,6 +21,23 @@ PlatformException _createConnectionError(String channelName) {
|
||||
|
||||
class _PigeonCodec extends StandardMessageCodec {
|
||||
const _PigeonCodec();
|
||||
@override
|
||||
void writeValue(WriteBuffer buffer, Object? value) {
|
||||
if (value is int) {
|
||||
buffer.putUint8(4);
|
||||
buffer.putInt64(value);
|
||||
} else {
|
||||
super.writeValue(buffer, value);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Object? readValueOfType(int type, ReadBuffer buffer) {
|
||||
switch (type) {
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class BackgroundApi2Host {
|
||||
|
||||
@@ -32,6 +32,23 @@ List<Object?> wrapResponse(
|
||||
|
||||
class _PigeonCodec extends StandardMessageCodec {
|
||||
const _PigeonCodec();
|
||||
@override
|
||||
void writeValue(WriteBuffer buffer, Object? value) {
|
||||
if (value is int) {
|
||||
buffer.putUint8(4);
|
||||
buffer.putInt64(value);
|
||||
} else {
|
||||
super.writeValue(buffer, value);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Object? readValueOfType(int type, ReadBuffer buffer) {
|
||||
switch (type) {
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MultipleArityHostApi {
|
||||
|
||||
@@ -32,6 +32,23 @@ List<Object?> wrapResponse(
|
||||
|
||||
class _PigeonCodec extends StandardMessageCodec {
|
||||
const _PigeonCodec();
|
||||
@override
|
||||
void writeValue(WriteBuffer buffer, Object? value) {
|
||||
if (value is int) {
|
||||
buffer.putUint8(4);
|
||||
buffer.putInt64(value);
|
||||
} else {
|
||||
super.writeValue(buffer, value);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Object? readValueOfType(int type, ReadBuffer buffer) {
|
||||
switch (type) {
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NullableReturnHostApi {
|
||||
|
||||
@@ -32,6 +32,23 @@ List<Object?> wrapResponse(
|
||||
|
||||
class _PigeonCodec extends StandardMessageCodec {
|
||||
const _PigeonCodec();
|
||||
@override
|
||||
void writeValue(WriteBuffer buffer, Object? value) {
|
||||
if (value is int) {
|
||||
buffer.putUint8(4);
|
||||
buffer.putInt64(value);
|
||||
} else {
|
||||
super.writeValue(buffer, value);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Object? readValueOfType(int type, ReadBuffer buffer) {
|
||||
switch (type) {
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PrimitiveHostApi {
|
||||
|
||||
@@ -2,7 +2,7 @@ name: pigeon
|
||||
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
|
||||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+pigeon%22
|
||||
version: 22.4.0 # This must match the version in lib/generator_tools.dart
|
||||
version: 22.4.1 # This must match the version in lib/generator_tools.dart
|
||||
|
||||
environment:
|
||||
sdk: ^3.3.0
|
||||
|
||||
@@ -1771,4 +1771,35 @@ name: foobar
|
||||
final String mainCode = mainCodeSink.toString();
|
||||
expect(mainCode, contains('List<Object?> wrapResponse('));
|
||||
});
|
||||
|
||||
test('writes custom int codec without custom types', () {
|
||||
final Root root = Root(
|
||||
apis: <Api>[
|
||||
AstHostApi(name: 'Api', methods: <Method>[
|
||||
Method(
|
||||
name: 'doit',
|
||||
location: ApiLocation.host,
|
||||
returnType: const TypeDeclaration(
|
||||
baseName: 'int',
|
||||
isNullable: true,
|
||||
),
|
||||
parameters: <Parameter>[])
|
||||
])
|
||||
],
|
||||
classes: <Class>[],
|
||||
enums: <Enum>[],
|
||||
);
|
||||
final StringBuffer sink = StringBuffer();
|
||||
const DartGenerator generator = DartGenerator();
|
||||
generator.generate(
|
||||
const DartOptions(),
|
||||
root,
|
||||
sink,
|
||||
dartPackageName: DEFAULT_PACKAGE_NAME,
|
||||
);
|
||||
final String code = sink.toString();
|
||||
expect(code, contains('if (value is int) {'));
|
||||
expect(code, contains('buffer.putUint8(4);'));
|
||||
expect(code, contains('buffer.putInt64(value);'));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user