-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[pigeon] Fixed decoding code for null-safe classes. #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
**/doc/api/ | ||
**/ios/Flutter/.last_build_id | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
|
||
# Web related | ||
lib/generated_plugin_registrant.dart | ||
|
||
# Symbolication related | ||
app.*.symbols | ||
|
||
# Obfuscation related | ||
app.*.map.json | ||
|
||
# Android Studio will place build artifacts here | ||
/android/app/debug | ||
/android/app/profile | ||
/android/app/release |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: 6db3d61ed4a58ba89140d7fe1fd294b598cc29c5 | ||
channel: master | ||
|
||
project_type: app |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# flutter_unit_tests | ||
|
||
Unit test scaffold for null safe Flutter projects. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
// Autogenerated from Pigeon (v0.1.21), do not edit directly. | ||
// See also: https://pub.dev/packages/pigeon | ||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import | ||
// @dart = 2.12 | ||
Comment on lines
+1
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to add this file otherwise CI analysis steps fail. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, we disable the analysis for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the pointer. I'm on the fence as to whether it is a good idea or not. I think I'll keep it this way for now. |
||
import 'dart:async'; | ||
import 'dart:typed_data' show Uint8List, Int32List, Int64List, Float64List; | ||
|
||
import 'package:flutter/services.dart'; | ||
|
||
class SearchReply { | ||
String? result; | ||
String? error; | ||
|
||
Object encode() { | ||
final Map<Object?, Object?> pigeonMap = <Object?, Object?>{}; | ||
pigeonMap['result'] = result; | ||
pigeonMap['error'] = error; | ||
return pigeonMap; | ||
} | ||
|
||
static SearchReply decode(Object message) { | ||
final Map<Object?, Object?> pigeonMap = message as Map<Object?, Object?>; | ||
return SearchReply() | ||
..result = pigeonMap['result'] as String? | ||
..error = pigeonMap['error'] as String?; | ||
} | ||
} | ||
|
||
class SearchRequest { | ||
String? query; | ||
int? anInt; | ||
bool? aBool; | ||
|
||
Object encode() { | ||
final Map<Object?, Object?> pigeonMap = <Object?, Object?>{}; | ||
pigeonMap['query'] = query; | ||
pigeonMap['anInt'] = anInt; | ||
pigeonMap['aBool'] = aBool; | ||
return pigeonMap; | ||
} | ||
|
||
static SearchRequest decode(Object message) { | ||
final Map<Object?, Object?> pigeonMap = message as Map<Object?, Object?>; | ||
return SearchRequest() | ||
..query = pigeonMap['query'] as String? | ||
..anInt = pigeonMap['anInt'] as int? | ||
..aBool = pigeonMap['aBool'] as bool?; | ||
} | ||
} | ||
|
||
class Nested { | ||
SearchRequest? request; | ||
|
||
Object encode() { | ||
final Map<Object?, Object?> pigeonMap = <Object?, Object?>{}; | ||
pigeonMap['request'] = request == null ? null : request!.encode(); | ||
return pigeonMap; | ||
} | ||
|
||
static Nested decode(Object message) { | ||
final Map<Object?, Object?> pigeonMap = message as Map<Object?, Object?>; | ||
return Nested() | ||
..request = pigeonMap['request'] != null | ||
? SearchRequest.decode(pigeonMap['request']!) | ||
: null; | ||
} | ||
} | ||
|
||
abstract class FlutterSearchApi { | ||
SearchReply search(SearchRequest arg); | ||
static void setup(FlutterSearchApi? api) { | ||
{ | ||
const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>( | ||
'dev.flutter.pigeon.FlutterSearchApi.search', StandardMessageCodec()); | ||
if (api == null) { | ||
channel.setMessageHandler(null); | ||
} else { | ||
channel.setMessageHandler((Object? message) async { | ||
assert(message != null, | ||
'Argument for dev.flutter.pigeon.FlutterSearchApi.search was null. Expected SearchRequest.'); | ||
final SearchRequest input = SearchRequest.decode(message!); | ||
final SearchReply output = api.search(input); | ||
return output.encode(); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
|
||
class NestedApi { | ||
Future<SearchReply> search(Nested arg) async { | ||
final Object encoded = arg.encode(); | ||
const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>( | ||
'dev.flutter.pigeon.NestedApi.search', StandardMessageCodec()); | ||
final Map<Object?, Object?>? replyMap = | ||
await channel.send(encoded) as Map<Object?, Object?>?; | ||
if (replyMap == null) { | ||
throw PlatformException( | ||
code: 'channel-error', | ||
message: 'Unable to establish connection on channel.', | ||
details: null, | ||
); | ||
} else if (replyMap['error'] != null) { | ||
final Map<Object?, Object?> error = | ||
replyMap['error'] as Map<Object?, Object?>; | ||
throw PlatformException( | ||
code: error['code'] as String, | ||
message: error['message'] as String?, | ||
details: error['details'], | ||
); | ||
} else { | ||
return SearchReply.decode(replyMap['result']!); | ||
} | ||
} | ||
} | ||
|
||
class Api { | ||
Future<void> initialize() async { | ||
const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>( | ||
'dev.flutter.pigeon.Api.initialize', StandardMessageCodec()); | ||
final Map<Object?, Object?>? replyMap = | ||
await channel.send(null) as Map<Object?, Object?>?; | ||
if (replyMap == null) { | ||
throw PlatformException( | ||
code: 'channel-error', | ||
message: 'Unable to establish connection on channel.', | ||
details: null, | ||
); | ||
} else if (replyMap['error'] != null) { | ||
final Map<Object?, Object?> error = | ||
replyMap['error'] as Map<Object?, Object?>; | ||
throw PlatformException( | ||
code: error['code'] as String, | ||
message: error['message'] as String?, | ||
details: error['details'], | ||
); | ||
} else { | ||
// noop | ||
} | ||
} | ||
|
||
Future<SearchReply> search(SearchRequest arg) async { | ||
final Object encoded = arg.encode(); | ||
const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>( | ||
'dev.flutter.pigeon.Api.search', StandardMessageCodec()); | ||
final Map<Object?, Object?>? replyMap = | ||
await channel.send(encoded) as Map<Object?, Object?>?; | ||
if (replyMap == null) { | ||
throw PlatformException( | ||
code: 'channel-error', | ||
message: 'Unable to establish connection on channel.', | ||
details: null, | ||
); | ||
} else if (replyMap['error'] != null) { | ||
final Map<Object?, Object?> error = | ||
replyMap['error'] as Map<Object?, Object?>; | ||
throw PlatformException( | ||
code: error['code'] as String, | ||
message: error['message'] as String?, | ||
details: error['details'], | ||
); | ||
} else { | ||
return SearchReply.decode(replyMap['result']!); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: flutter_unit_tests | ||
description: Unit test scaffold for null safe Flutter projects. | ||
publish_to: 'none' # Remove this line if you wish to publish to pub.dev | ||
version: 1.0.0+1 | ||
environment: | ||
sdk: ">=2.12.0 <3.0.0" | ||
|
||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
|
||
dev_dependencies: | ||
flutter_test: | ||
sdk: flutter | ||
|
||
flutter: | ||
uses-material-design: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2020 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:flutter_unit_tests/null_safe_pigeon.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
test('with values filled', () { | ||
final SearchReply reply = SearchReply() | ||
..result = 'foo' | ||
..error = 'bar'; | ||
final Object encoded = reply.encode(); | ||
final SearchReply decoded = SearchReply.decode(encoded); | ||
expect(reply.result, decoded.result); | ||
expect(reply.error, decoded.error); | ||
}); | ||
|
||
test('with null value', () { | ||
final SearchReply reply = SearchReply() | ||
..result = 'foo' | ||
..error = null; | ||
final Object encoded = reply.encode(); | ||
final SearchReply decoded = SearchReply.decode(encoded); | ||
expect(reply.result, decoded.result); | ||
expect(reply.error, decoded.error); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual fix, other stuff is just testing infrastructure / tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense