Flutter Engine
The Flutter Engine
MethodCodec.java
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package io.flutter.plugin.common;
6
7import androidx.annotation.NonNull;
8import androidx.annotation.Nullable;
9import java.nio.ByteBuffer;
10
11/**
12 * A codec for method calls and enveloped results.
13 *
14 * <p>Method calls are encoded as binary messages with enough structure that the codec can extract a
15 * method name String and an arguments Object. These data items are used to populate a {@link
16 * MethodCall}.
17 *
18 * <p>All operations throw {@link IllegalArgumentException}, if conversion fails.
19 */
20public interface MethodCodec {
21 /**
22 * Encodes a message call into binary.
23 *
24 * @param methodCall a {@link MethodCall}.
25 * @return a {@link ByteBuffer} containing the encoding between position 0 and the current
26 * position.
27 */
28 @NonNull
29 ByteBuffer encodeMethodCall(@NonNull MethodCall methodCall);
30
31 /**
32 * Decodes a message call from binary.
33 *
34 * @param methodCall the binary encoding of the method call as a {@link ByteBuffer}.
35 * @return a {@link MethodCall} representation of the bytes between the given buffer's current
36 * position and its limit.
37 */
38 @NonNull
39 MethodCall decodeMethodCall(@NonNull ByteBuffer methodCall);
40
41 /**
42 * Encodes a successful result into a binary envelope message.
43 *
44 * @param result The result value, possibly null.
45 * @return a {@link ByteBuffer} containing the encoding between position 0 and the current
46 * position.
47 */
48 @NonNull
49 ByteBuffer encodeSuccessEnvelope(@Nullable Object result);
50
51 /**
52 * Encodes an error result into a binary envelope message.
53 *
54 * @param errorCode An error code String.
55 * @param errorMessage An error message String, possibly null.
56 * @param errorDetails Error details, possibly null. Consider supporting {@link Throwable} in your
57 * codec. This is the most common value passed to this field.
58 * @return a {@link ByteBuffer} containing the encoding between position 0 and the current
59 * position.
60 */
61 @NonNull
63 @NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails);
64
65 /**
66 * Encodes an error result into a binary envelope message with the native stacktrace.
67 *
68 * @param errorCode An error code String.
69 * @param errorMessage An error message String, possibly null.
70 * @param errorDetails Error details, possibly null. Consider supporting {@link Throwable} in your
71 * codec. This is the most common value passed to this field.
72 * @param errorStacktrace Platform stacktrace for the error. possibly null.
73 * @return a {@link ByteBuffer} containing the encoding between position 0 and the current
74 * position.
75 */
76 @NonNull
78 @NonNull String errorCode,
79 @Nullable String errorMessage,
80 @Nullable Object errorDetails,
81 @Nullable String errorStacktrace);
82
83 /**
84 * Decodes a result envelope from binary.
85 *
86 * @param envelope the binary encoding of a result envelope as a {@link ByteBuffer}.
87 * @return the enveloped result Object.
88 * @throws FlutterException if the envelope was an error envelope.
89 */
90 @NonNull
91 Object decodeEnvelope(@NonNull ByteBuffer envelope);
92}
GAsyncResult * result
ByteBuffer encodeSuccessEnvelope(@Nullable Object result)
ByteBuffer encodeErrorEnvelope( @NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails)
ByteBuffer encodeMethodCall(@NonNull MethodCall methodCall)
MethodCall decodeMethodCall(@NonNull ByteBuffer methodCall)
ByteBuffer encodeErrorEnvelopeWithStacktrace( @NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails, @Nullable String errorStacktrace)
Object decodeEnvelope(@NonNull ByteBuffer envelope)