Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
io.flutter.plugin.common.StandardMethodCodec Class Reference
Inheritance diagram for io.flutter.plugin.common.StandardMethodCodec:
io.flutter.plugin.common.MethodCodec

Public Member Functions

 StandardMethodCodec (@NonNull StandardMessageCodec messageCodec)
 
ByteBuffer encodeMethodCall (@NonNull MethodCall methodCall)
 
MethodCall decodeMethodCall (@NonNull ByteBuffer methodCall)
 
ByteBuffer encodeSuccessEnvelope (@NonNull Object result)
 
ByteBuffer encodeErrorEnvelope ( @NonNull String errorCode, @NonNull String errorMessage, @NonNull Object errorDetails)
 
ByteBuffer encodeErrorEnvelopeWithStacktrace ( @NonNull String errorCode, @NonNull String errorMessage, @NonNull Object errorDetails, @NonNull String errorStacktrace)
 
Object decodeEnvelope (@NonNull ByteBuffer envelope)
 
- Public Member Functions inherited from io.flutter.plugin.common.MethodCodec
ByteBuffer encodeSuccessEnvelope (@Nullable Object result)
 
ByteBuffer encodeErrorEnvelope ( @NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails)
 
ByteBuffer encodeErrorEnvelopeWithStacktrace ( @NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails, @Nullable String errorStacktrace)
 

Static Public Attributes

static final StandardMethodCodec INSTANCE
 

Detailed Description

A MethodCodec using the Flutter standard binary encoding.

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

Values supported as method arguments and result payloads are those supported by StandardMessageCodec.

Definition at line 23 of file StandardMethodCodec.java.

Constructor & Destructor Documentation

◆ StandardMethodCodec()

io.flutter.plugin.common.StandardMethodCodec.StandardMethodCodec ( @NonNull StandardMessageCodec  messageCodec)
inline

Creates a new method codec based on the specified message codec.

Definition at line 29 of file StandardMethodCodec.java.

29 {
30 this.messageCodec = messageCodec;
31 }

Member Function Documentation

◆ decodeEnvelope()

Object io.flutter.plugin.common.StandardMethodCodec.decodeEnvelope ( @NonNull ByteBuffer  envelope)
inline

Decodes a result envelope from binary.

Parameters
envelopethe binary encoding of a result envelope as a ByteBuffer.
Returns
the enveloped result Object.
Exceptions
FlutterExceptionif the envelope was an error envelope.

Implements io.flutter.plugin.common.MethodCodec.

Definition at line 109 of file StandardMethodCodec.java.

109 {
110 envelope.order(ByteOrder.nativeOrder());
111 final byte flag = envelope.get();
112 switch (flag) {
113 case 0:
114 {
115 final Object result = messageCodec.readValue(envelope);
116 if (!envelope.hasRemaining()) {
117 return result;
118 }
119 }
120 // Falls through intentionally.
121 case 1:
122 {
123 final Object code = messageCodec.readValue(envelope);
124 final Object message = messageCodec.readValue(envelope);
125 final Object details = messageCodec.readValue(envelope);
126 if (code instanceof String
127 && (message == null || message instanceof String)
128 && !envelope.hasRemaining()) {
129 throw new FlutterException((String) code, (String) message, details);
130 }
131 }
132 }
133 throw new IllegalArgumentException("Envelope corrupted");
134 }
final Object readValue(@NonNull ByteBuffer buffer)
FlutterSemanticsFlag flag
GAsyncResult * result
Win32Message message

◆ decodeMethodCall()

MethodCall io.flutter.plugin.common.StandardMethodCodec.decodeMethodCall ( @NonNull ByteBuffer  methodCall)
inline

Decodes a message call from binary.

Parameters
methodCallthe binary encoding of the method call as a ByteBuffer.
Returns
a MethodCall representation of the bytes between the given buffer's current position and its limit.

Implements io.flutter.plugin.common.MethodCodec.

Definition at line 46 of file StandardMethodCodec.java.

46 {
47 methodCall.order(ByteOrder.nativeOrder());
48 final Object method = messageCodec.readValue(methodCall);
49 final Object arguments = messageCodec.readValue(methodCall);
50 if (method instanceof String && !methodCall.hasRemaining()) {
51 return new MethodCall((String) method, arguments);
52 }
53 throw new IllegalArgumentException("Method call corrupted");
54 }
static ::testing::Matcher< GBytes * > MethodCall(const std::string &name, ::testing::Matcher< FlValue * > args)

◆ encodeErrorEnvelope()

ByteBuffer io.flutter.plugin.common.StandardMethodCodec.encodeErrorEnvelope ( @NonNull String  errorCode,
@NonNull String  errorMessage,
@NonNull Object  errorDetails 
)
inline

Definition at line 69 of file StandardMethodCodec.java.

70 {
71 final ExposedByteArrayOutputStream stream = new ExposedByteArrayOutputStream();
72 stream.write(1);
73 messageCodec.writeValue(stream, errorCode);
74 messageCodec.writeValue(stream, errorMessage);
75 if (errorDetails instanceof Throwable) {
76 messageCodec.writeValue(stream, Log.getStackTraceString((Throwable) errorDetails));
77 } else {
78 messageCodec.writeValue(stream, errorDetails);
79 }
80 final ByteBuffer buffer = ByteBuffer.allocateDirect(stream.size());
81 buffer.put(stream.buffer(), 0, stream.size());
82 return buffer;
83 }
void writeValue(@NonNull ByteArrayOutputStream stream, @Nullable Object value)
static const uint8_t buffer[]
void Log(const char *format,...) SK_PRINTF_LIKE(1

◆ encodeErrorEnvelopeWithStacktrace()

ByteBuffer io.flutter.plugin.common.StandardMethodCodec.encodeErrorEnvelopeWithStacktrace ( @NonNull String  errorCode,
@NonNull String  errorMessage,
@NonNull Object  errorDetails,
@NonNull String  errorStacktrace 
)
inline

Definition at line 87 of file StandardMethodCodec.java.

91 {
92 final ExposedByteArrayOutputStream stream = new ExposedByteArrayOutputStream();
93 stream.write(1);
94 messageCodec.writeValue(stream, errorCode);
95 messageCodec.writeValue(stream, errorMessage);
96 if (errorDetails instanceof Throwable) {
97 messageCodec.writeValue(stream, Log.getStackTraceString((Throwable) errorDetails));
98 } else {
99 messageCodec.writeValue(stream, errorDetails);
100 }
101 messageCodec.writeValue(stream, errorStacktrace);
102 final ByteBuffer buffer = ByteBuffer.allocateDirect(stream.size());
103 buffer.put(stream.buffer(), 0, stream.size());
104 return buffer;
105 }

◆ encodeMethodCall()

ByteBuffer io.flutter.plugin.common.StandardMethodCodec.encodeMethodCall ( @NonNull MethodCall  methodCall)
inline

Encodes a message call into binary.

Parameters
methodCalla MethodCall.
Returns
a ByteBuffer containing the encoding between position 0 and the current position.

Implements io.flutter.plugin.common.MethodCodec.

Definition at line 35 of file StandardMethodCodec.java.

35 {
36 final ExposedByteArrayOutputStream stream = new ExposedByteArrayOutputStream();
37 messageCodec.writeValue(stream, methodCall.method);
38 messageCodec.writeValue(stream, methodCall.arguments);
39 final ByteBuffer buffer = ByteBuffer.allocateDirect(stream.size());
40 buffer.put(stream.buffer(), 0, stream.size());
41 return buffer;
42 }

◆ encodeSuccessEnvelope()

ByteBuffer io.flutter.plugin.common.StandardMethodCodec.encodeSuccessEnvelope ( @NonNull Object  result)
inline

Definition at line 58 of file StandardMethodCodec.java.

58 {
59 final ExposedByteArrayOutputStream stream = new ExposedByteArrayOutputStream();
60 stream.write(0);
61 messageCodec.writeValue(stream, result);
62 final ByteBuffer buffer = ByteBuffer.allocateDirect(stream.size());
63 buffer.put(stream.buffer(), 0, stream.size());
64 return buffer;
65 }

Member Data Documentation

◆ INSTANCE

final StandardMethodCodec io.flutter.plugin.common.StandardMethodCodec.INSTANCE
static
Initial value:
=
new StandardMethodCodec(StandardMessageCodec.INSTANCE)
StandardMethodCodec(@NonNull StandardMessageCodec messageCodec)

Definition at line 24 of file StandardMethodCodec.java.


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