FlutterMethodCodec
@protocol FlutterMethodCodec
A codec for method calls and enveloped results.
Method calls are encoded as binary messages with enough structure that the
codec can extract a method name NSString
and an arguments NSObject
,
possibly nil
. These data items are used to populate a FlutterMethodCall
.
Result envelopes are encoded as binary messages with enough structure that
the codec can determine whether the result was successful or an error. In
the former case, the codec can extract the result NSObject
, possibly nil
.
In the latter case, the codec can extract an error code NSString
, a
human-readable NSString
error message (possibly nil
), and a custom
error details NSObject
, possibly nil
. These data items are used to
populate a FlutterError
.
-
Provides access to a shared instance this codec.
Declaration
Objective-C
+ (nonnull instancetype)sharedInstance;
Return Value
The shared instance.
-
Encodes the specified method call into binary.
Declaration
Objective-C
- (nonnull NSData *)encodeMethodCall:(nonnull FlutterMethodCall *)methodCall;
Parameters
methodCall
The method call. The arguments value must be supported by this codec.
Return Value
The binary encoding.
-
Decodes the specified method call from binary.
Declaration
Objective-C
- (nonnull FlutterMethodCall *)decodeMethodCall:(nonnull NSData *)methodCall;
Parameters
methodCall
The method call to decode.
Return Value
The decoded method call.
-
Encodes the specified successful result into binary.
Declaration
Objective-C
- (nonnull NSData *)encodeSuccessEnvelope:(id _Nullable)result;
Parameters
result
The result. Must be a value supported by this codec.
Return Value
The binary encoding.
-
Encodes the specified error result into binary.
Declaration
Objective-C
- (nonnull NSData *)encodeErrorEnvelope:(nonnull FlutterError *)error;
Parameters
error
The error object. The error details value must be supported by this codec.
Return Value
The binary encoding.
-
Deccodes the specified result envelope from binary.
Declaration
Objective-C
- (id _Nullable)decodeEnvelope:(nonnull NSData *)envelope;
Parameters
envelope
The error object.
Return Value
The result value, if the envelope represented a successful result, or a
FlutterError
instance, if not.