Flutter Engine
The Flutter Engine
Instance Methods | Class Methods | List of all members
FlutterJSONMethodCodec Class Reference

#import <FlutterCodecs.h>

Inheritance diagram for FlutterJSONMethodCodec:

Instance Methods

(NSData *) - encodeMethodCall: [implementation]
 
(NSData *) - encodeSuccessEnvelope: [implementation]
 
(NSData *) - encodeErrorEnvelope: [implementation]
 
(FlutterMethodCall *) - decodeMethodCall: [implementation]
 
(id- decodeEnvelope: [implementation]
 
(id- wrapNil: [implementation]
 
(id- unwrapNil: [implementation]
 

Class Methods

(instancetype) + sharedInstance [implementation]
 

Detailed Description

An arbitrarily large integer value, used with FlutterStandardMessageCodec and FlutterStandardMethodCodec. 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.

Returns
The shared instance. Encodes the specified method call into binary.
Parameters
methodCallThe method call. The arguments value must be supported by this codec.
Returns
The binary encoding. Decodes the specified method call from binary.
Parameters
methodCallThe method call to decode.
Returns
The decoded method call. Encodes the specified successful result into binary.
Parameters
resultThe result. Must be a value supported by this codec.
Returns
The binary encoding. Encodes the specified error result into binary.
Parameters
errorThe error object. The error details value must be supported by this codec.
Returns
The binary encoding. Deccodes the specified result envelope from binary.
Parameters
envelopeThe error object.
Returns
The result value, if the envelope represented a successful result, or a FlutterError instance, if not. A FlutterMethodCodec using UTF-8 encoded JSON method calls and result envelopes.

This codec is guaranteed to be compatible with the corresponding JSONMethodCodec on the Dart side. These parts of the Flutter SDK are evolved synchronously.

Values supported as methods arguments and result payloads are those supported as top-level or leaf values by FlutterJSONMessageCodec.

Definition at line 455 of file FlutterCodecs.h.

Method Documentation

◆ decodeEnvelope:

- (id) decodeEnvelope: (NSData*)  envelope
implementation

Definition at line 9 of file FlutterCodecs.mm.

152 :(NSData*)envelope {
153 NSArray* array = [[FlutterJSONMessageCodec sharedInstance] decode:envelope];
154 if (array.count == 1) {
155 return [self unwrapNil:array[0]];
156 }
157 NSAssert(array.count == 3, @"Invalid JSON envelope");
158 id code = array[0];
159 id message = [self unwrapNil:array[1]];
160 id details = [self unwrapNil:array[2]];
161 NSAssert([code isKindOfClass:[NSString class]], @"Invalid JSON envelope");
162 NSAssert(message == nil || [message isKindOfClass:[NSString class]], @"Invalid JSON envelope");
163 return [FlutterError errorWithCode:code message:message details:details];
164}
instancetype errorWithCode:message:details:(NSString *code,[message] NSString *_Nullable message,[details] id _Nullable details)
instancetype sharedInstance()
Win32Message message

◆ decodeMethodCall:

- (FlutterMethodCall *) decodeMethodCall: (NSData*)  message
implementation

Definition at line 9 of file FlutterCodecs.mm.

144 :(NSData*)message {
145 NSDictionary* dictionary = [[FlutterJSONMessageCodec sharedInstance] decode:message];
146 id method = dictionary[@"method"];
147 id arguments = [self unwrapNil:dictionary[@"args"]];
148 NSAssert([method isKindOfClass:[NSString class]], @"Invalid JSON method call");
149 return [FlutterMethodCall methodCallWithMethodName:method arguments:arguments];
150}
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)

◆ encodeErrorEnvelope:

- (NSData *) encodeErrorEnvelope: (FlutterError*)  error
implementation

Definition at line 9 of file FlutterCodecs.mm.

137 return [[FlutterJSONMessageCodec sharedInstance] encode:@[
138 error.code,
139 [self wrapNil:error.message],
140 [self wrapNil:error.details],
141 ]];
142}
const uint8_t uint32_t uint32_t GError ** error

◆ encodeMethodCall:

- (NSData *) encodeMethodCall: (FlutterMethodCall*)  call
implementation

Definition at line 9 of file FlutterCodecs.mm.

126 return [[FlutterJSONMessageCodec sharedInstance] encode:@{
127 @"method" : call.method,
128 @"args" : [self wrapNil:call.arguments],
129 }];
130}
def call(args)
Definition: dom.py:159

◆ encodeSuccessEnvelope:

- (NSData *) encodeSuccessEnvelope: (id result
implementation

Definition at line 9 of file FlutterCodecs.mm.

132 :(id)result {
133 return [[FlutterJSONMessageCodec sharedInstance] encode:@[ [self wrapNil:result] ]];
134}
GAsyncResult * result
const uintptr_t id

◆ sharedInstance

+ (instancetype) sharedInstance
implementation

Definition at line 9 of file FlutterCodecs.mm.

117 {
118 static id _sharedInstance = nil;
119 if (!_sharedInstance) {
120 _sharedInstance = [[FlutterJSONMethodCodec alloc] init];
121 }
122 return _sharedInstance;
123}

◆ unwrapNil:

- (id) unwrapNil: (id value
implementation

Definition at line 9 of file FlutterCodecs.mm.

169 :(id)value {
170 return value == [NSNull null] ? nil : value;
171}
uint8_t value

◆ wrapNil:

- (id) wrapNil: (id value
implementation

Definition at line 9 of file FlutterCodecs.mm.

166 :(id)value {
167 return value == nil ? [NSNull null] : value;
168}

The documentation for this class was generated from the following files: