# FlutterMethodCodec

Objective-C

    @protocol FlutterMethodCodec

Swift

    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`.

- `+sharedInstance`

  Provides access to a shared instance this codec.

  #### Declaration

  Objective-C

      + (nonnull instancetype)sharedInstance;

  Swift

      static func sharedInstance() -> Self

  #### Return Value

  The shared instance.

- `-encodeMethodCall:`

  Encodes the specified method call into binary.

  #### Declaration

  Objective-C

      - (nonnull NSData *)encodeMethodCall:(nonnull FlutterMethodCall *)methodCall;

  Swift

      func encode(_ methodCall: FlutterMethodCall) -> Data

  #### Parameters

  `methodCall` | The method call. The arguments value must be supported by this codec.

  #### Return Value

  The binary encoding.

- `-decodeMethodCall:`

  Decodes the specified method call from binary.

  #### Declaration

  Objective-C

      - (nonnull FlutterMethodCall *)decodeMethodCall:(nonnull NSData *)methodCall;

  Swift

      func decodeMethodCall(_ methodCall: Data) -> FlutterMethodCall

  #### Parameters

  `methodCall` | The method call to decode.

  #### Return Value

  The decoded method call.

- `-encodeSuccessEnvelope:`

  Encodes the specified successful result into binary.

  #### Declaration

  Objective-C

      - (nonnull NSData *)encodeSuccessEnvelope:(id _Nullable)result;

  Swift

      func encodeSuccessEnvelope(_ result: Any?) -> Data

  #### Parameters

  `result` | The result. Must be a value supported by this codec.

  #### Return Value

  The binary encoding.

- `-encodeErrorEnvelope:`

  Encodes the specified error result into binary.

  #### Declaration

  Objective-C

      - (nonnull NSData *)encodeErrorEnvelope:(nonnull FlutterError *)error;

  Swift

      func encodeErrorEnvelope(_ error: FlutterError) -> Data

  #### Parameters

  `error` | The error object. The error details value must be supported by this codec.

  #### Return Value

  The binary encoding.

- `-decodeEnvelope:`

  Deccodes the specified result envelope from binary.

  #### Declaration

  Objective-C

      - (id _Nullable)decodeEnvelope:(nonnull NSData *)envelope;

  Swift

      func decodeEnvelope(_ envelope: Data) -> Any?

  #### Parameters

  `envelope` | The error object.

  #### Return Value

  The result value, if the envelope represented a successful result, or a `FlutterError` instance, if not.

© 2023 Flutter. All rights reserved. (Last updated: 2023-06-01)

Generated by jazzy ♪♫ v0.14.3, a Realm project.