Pigeon: Initial definitions for sendMessage
- Generated Pigeons for `HostApis` in Android and iOS
This commit is contained in:
parent
6e57474596
commit
503d4a7735
5 changed files with 364 additions and 0 deletions
|
|
@ -0,0 +1,117 @@
|
|||
// Autogenerated from Pigeon (v1.0.8), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
|
||||
package com.gianlucaparadise.flutter_cast_framework;
|
||||
|
||||
import io.flutter.plugin.common.BasicMessageChannel;
|
||||
import io.flutter.plugin.common.BinaryMessenger;
|
||||
import io.flutter.plugin.common.MessageCodec;
|
||||
import io.flutter.plugin.common.StandardMessageCodec;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
/** Generated class from Pigeon. */
|
||||
@SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"})
|
||||
public class HostApis {
|
||||
|
||||
/** Generated class from Pigeon that represents data sent in messages. */
|
||||
public static class CastMessage {
|
||||
private String namespace;
|
||||
public String getNamespace() { return namespace; }
|
||||
public void setNamespace(String setterArg) { this.namespace = setterArg; }
|
||||
|
||||
private String message;
|
||||
public String getMessage() { return message; }
|
||||
public void setMessage(String setterArg) { this.message = setterArg; }
|
||||
|
||||
Map<String, Object> toMap() {
|
||||
Map<String, Object> toMapResult = new HashMap<>();
|
||||
toMapResult.put("namespace", namespace);
|
||||
toMapResult.put("message", message);
|
||||
return toMapResult;
|
||||
}
|
||||
static CastMessage fromMap(Map<String, Object> map) {
|
||||
CastMessage fromMapResult = new CastMessage();
|
||||
Object namespace = map.get("namespace");
|
||||
fromMapResult.namespace = (String)namespace;
|
||||
Object message = map.get("message");
|
||||
fromMapResult.message = (String)message;
|
||||
return fromMapResult;
|
||||
}
|
||||
}
|
||||
private static class CastApiCodec extends StandardMessageCodec {
|
||||
public static final CastApiCodec INSTANCE = new CastApiCodec();
|
||||
private CastApiCodec() {}
|
||||
@Override
|
||||
protected Object readValueOfType(byte type, ByteBuffer buffer) {
|
||||
switch (type) {
|
||||
case (byte)128:
|
||||
return CastMessage.fromMap((Map<String, Object>) readValue(buffer));
|
||||
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void writeValue(ByteArrayOutputStream stream, Object value) {
|
||||
if (value instanceof CastMessage) {
|
||||
stream.write(128);
|
||||
writeValue(stream, ((CastMessage) value).toMap());
|
||||
} else
|
||||
{
|
||||
super.writeValue(stream, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Generated interface from Pigeon that represents a handler of messages from Flutter.*/
|
||||
public interface CastApi {
|
||||
void sendMessage(CastMessage message);
|
||||
|
||||
/** The codec used by CastApi. */
|
||||
static MessageCodec<Object> getCodec() {
|
||||
return CastApiCodec.INSTANCE;
|
||||
}
|
||||
|
||||
/** Sets up an instance of `CastApi` to handle messages through the `binaryMessenger`. */
|
||||
static void setup(BinaryMessenger binaryMessenger, CastApi api) {
|
||||
{
|
||||
BasicMessageChannel<Object> channel =
|
||||
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastApi.sendMessage", getCodec());
|
||||
if (api != null) {
|
||||
channel.setMessageHandler((message, reply) -> {
|
||||
Map<String, Object> wrapped = new HashMap<>();
|
||||
try {
|
||||
ArrayList<Object> args = (ArrayList<Object>)message;
|
||||
CastMessage messageArg = (CastMessage)args.get(0);
|
||||
if (messageArg == null) {
|
||||
throw new NullPointerException("messageArg unexpectedly null.");
|
||||
}
|
||||
api.sendMessage(messageArg);
|
||||
wrapped.put("result", null);
|
||||
}
|
||||
catch (Error | RuntimeException exception) {
|
||||
wrapped.put("error", wrapError(exception));
|
||||
}
|
||||
reply.reply(wrapped);
|
||||
});
|
||||
} else {
|
||||
channel.setMessageHandler(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private static Map<String, Object> wrapError(Throwable exception) {
|
||||
Map<String, Object> errorMap = new HashMap<>();
|
||||
errorMap.put("message", exception.toString());
|
||||
errorMap.put("code", exception.getClass().getSimpleName());
|
||||
errorMap.put("details", null);
|
||||
return errorMap;
|
||||
}
|
||||
}
|
||||
27
ios/Classes/HostApis.h
Normal file
27
ios/Classes/HostApis.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// Autogenerated from Pigeon (v1.0.8), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
#import <Foundation/Foundation.h>
|
||||
@protocol FlutterBinaryMessenger;
|
||||
@protocol FlutterMessageCodec;
|
||||
@class FlutterError;
|
||||
@class FlutterStandardTypedData;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class CastMessage;
|
||||
|
||||
@interface CastMessage : NSObject
|
||||
@property(nonatomic, copy, nullable) NSString * namespace;
|
||||
@property(nonatomic, copy, nullable) NSString * message;
|
||||
@end
|
||||
|
||||
/// The codec used by CastApi.
|
||||
NSObject<FlutterMessageCodec> *CastApiGetCodec(void);
|
||||
|
||||
@protocol CastApi
|
||||
- (void)sendMessageMessage:(CastMessage *)message error:(FlutterError *_Nullable *_Nonnull)error;
|
||||
@end
|
||||
|
||||
extern void CastApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastApi> *_Nullable api);
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
122
ios/Classes/HostApis.m
Normal file
122
ios/Classes/HostApis.m
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
// Autogenerated from Pigeon (v1.0.8), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
#import "HostApis.h"
|
||||
#import <Flutter/Flutter.h>
|
||||
|
||||
#if !__has_feature(objc_arc)
|
||||
#error File requires ARC to be enabled.
|
||||
#endif
|
||||
|
||||
static NSDictionary<NSString *, id> *wrapResult(id result, FlutterError *error) {
|
||||
NSDictionary *errorDict = (NSDictionary *)[NSNull null];
|
||||
if (error) {
|
||||
errorDict = @{
|
||||
@"code": (error.code ? error.code : [NSNull null]),
|
||||
@"message": (error.message ? error.message : [NSNull null]),
|
||||
@"details": (error.details ? error.details : [NSNull null]),
|
||||
};
|
||||
}
|
||||
return @{
|
||||
@"result": (result ? result : [NSNull null]),
|
||||
@"error": errorDict,
|
||||
};
|
||||
}
|
||||
|
||||
@interface CastMessage ()
|
||||
+ (CastMessage *)fromMap:(NSDictionary *)dict;
|
||||
- (NSDictionary *)toMap;
|
||||
@end
|
||||
|
||||
@implementation CastMessage
|
||||
+ (CastMessage *)fromMap:(NSDictionary *)dict {
|
||||
CastMessage *result = [[CastMessage alloc] init];
|
||||
result.namespace = dict[@"namespace"];
|
||||
if ((NSNull *)result.namespace == [NSNull null]) {
|
||||
result.namespace = nil;
|
||||
}
|
||||
result.message = dict[@"message"];
|
||||
if ((NSNull *)result.message == [NSNull null]) {
|
||||
result.message = nil;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
- (NSDictionary *)toMap {
|
||||
return [NSDictionary dictionaryWithObjectsAndKeys:(self.namespace ? self.namespace : [NSNull null]), @"namespace", (self.message ? self.message : [NSNull null]), @"message", nil];
|
||||
}
|
||||
@end
|
||||
|
||||
@interface CastApiCodecReader : FlutterStandardReader
|
||||
@end
|
||||
@implementation CastApiCodecReader
|
||||
- (nullable id)readValueOfType:(UInt8)type
|
||||
{
|
||||
switch (type) {
|
||||
case 128:
|
||||
return [CastMessage fromMap:[self readValue]];
|
||||
|
||||
default:
|
||||
return [super readValueOfType:type];
|
||||
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
@interface CastApiCodecWriter : FlutterStandardWriter
|
||||
@end
|
||||
@implementation CastApiCodecWriter
|
||||
- (void)writeValue:(id)value
|
||||
{
|
||||
if ([value isKindOfClass:[CastMessage class]]) {
|
||||
[self writeByte:128];
|
||||
[self writeValue:[value toMap]];
|
||||
} else
|
||||
{
|
||||
[super writeValue:value];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
@interface CastApiCodecReaderWriter : FlutterStandardReaderWriter
|
||||
@end
|
||||
@implementation CastApiCodecReaderWriter
|
||||
- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data {
|
||||
return [[CastApiCodecWriter alloc] initWithData:data];
|
||||
}
|
||||
- (FlutterStandardReader *)readerWithData:(NSData *)data {
|
||||
return [[CastApiCodecReader alloc] initWithData:data];
|
||||
}
|
||||
@end
|
||||
|
||||
NSObject<FlutterMessageCodec> *CastApiGetCodec() {
|
||||
static dispatch_once_t s_pred = 0;
|
||||
static FlutterStandardMessageCodec *s_sharedObject = nil;
|
||||
dispatch_once(&s_pred, ^{
|
||||
CastApiCodecReaderWriter *readerWriter = [[CastApiCodecReaderWriter alloc] init];
|
||||
s_sharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter];
|
||||
});
|
||||
return s_sharedObject;
|
||||
}
|
||||
|
||||
|
||||
void CastApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastApi> *api) {
|
||||
{
|
||||
FlutterBasicMessageChannel *channel =
|
||||
[FlutterBasicMessageChannel
|
||||
messageChannelWithName:@"dev.flutter.pigeon.CastApi.sendMessage"
|
||||
binaryMessenger:binaryMessenger
|
||||
codec:CastApiGetCodec()];
|
||||
if (api) {
|
||||
NSCAssert([api respondsToSelector:@selector(sendMessageMessage:error:)], @"CastApi api (%@) doesn't respond to @selector(sendMessageMessage:error:)", api);
|
||||
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
|
||||
NSArray *args = message;
|
||||
CastMessage *arg_message = args[0];
|
||||
FlutterError *error;
|
||||
[api sendMessageMessage:arg_message error:&error];
|
||||
callback(wrapResult(nil, error));
|
||||
}];
|
||||
}
|
||||
else {
|
||||
[channel setMessageHandler:nil];
|
||||
}
|
||||
}
|
||||
}
|
||||
87
lib/src/HostApis.dart
Normal file
87
lib/src/HostApis.dart
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
// Autogenerated from Pigeon (v1.0.8), 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, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name
|
||||
// @dart = 2.12
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data' show Uint8List, Int32List, Int64List, Float64List;
|
||||
|
||||
import 'package:flutter/foundation.dart' show WriteBuffer, ReadBuffer;
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class CastMessage {
|
||||
String? namespace;
|
||||
String? message;
|
||||
|
||||
Object encode() {
|
||||
final Map<Object?, Object?> pigeonMap = <Object?, Object?>{};
|
||||
pigeonMap['namespace'] = namespace;
|
||||
pigeonMap['message'] = message;
|
||||
return pigeonMap;
|
||||
}
|
||||
|
||||
static CastMessage decode(Object message) {
|
||||
final Map<Object?, Object?> pigeonMap = message as Map<Object?, Object?>;
|
||||
return CastMessage()
|
||||
..namespace = pigeonMap['namespace'] as String?
|
||||
..message = pigeonMap['message'] as String?;
|
||||
}
|
||||
}
|
||||
|
||||
class _CastApiCodec extends StandardMessageCodec {
|
||||
const _CastApiCodec();
|
||||
@override
|
||||
void writeValue(WriteBuffer buffer, Object? value) {
|
||||
if (value is CastMessage) {
|
||||
buffer.putUint8(128);
|
||||
writeValue(buffer, value.encode());
|
||||
} else
|
||||
{
|
||||
super.writeValue(buffer, value);
|
||||
}
|
||||
}
|
||||
@override
|
||||
Object? readValueOfType(int type, ReadBuffer buffer) {
|
||||
switch (type) {
|
||||
case 128:
|
||||
return CastMessage.decode(readValue(buffer)!);
|
||||
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CastApi {
|
||||
/// Constructor for [CastApi]. The [binaryMessenger] named argument is
|
||||
/// available for dependency injection. If it is left null, the default
|
||||
/// BinaryMessenger will be used which routes to the host platform.
|
||||
CastApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger;
|
||||
|
||||
final BinaryMessenger? _binaryMessenger;
|
||||
|
||||
static const MessageCodec<Object?> codec = _CastApiCodec();
|
||||
|
||||
Future<void> sendMessage(CastMessage arg_message) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.CastApi.sendMessage', codec, binaryMessenger: _binaryMessenger);
|
||||
final Map<Object?, Object?>? replyMap =
|
||||
await channel.send(<Object>[arg_message]) 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
lib/src/HostApisDefinition.dart
Normal file
11
lib/src/HostApisDefinition.dart
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import 'package:pigeon/pigeon.dart';
|
||||
|
||||
class CastMessage {
|
||||
String? namespace;
|
||||
String? message;
|
||||
}
|
||||
|
||||
@HostApi()
|
||||
abstract class CastApi {
|
||||
void sendMessage(CastMessage message);
|
||||
}
|
||||
Loading…
Reference in a new issue