5package io.flutter.plugin.common;
7import androidx.annotation.NonNull;
8import androidx.annotation.Nullable;
9import java.nio.ByteBuffer;
10import org.json.JSONArray;
11import org.json.JSONException;
12import org.json.JSONObject;
34 final JSONObject
map =
new JSONObject();
35 map.put(
"method", methodCall.method);
38 }
catch (JSONException
e) {
39 throw new IllegalArgumentException(
"Invalid JSON",
e);
48 if (json instanceof JSONObject) {
49 final JSONObject
map = (JSONObject) json;
50 final Object method =
map.get(
"method");
52 if (method instanceof String) {
53 return new MethodCall((String) method, arguments);
56 throw new IllegalArgumentException(
"Invalid method call: " + json);
57 }
catch (JSONException
e) {
58 throw new IllegalArgumentException(
"Invalid JSON",
e);
71 @NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails) {
82 @NonNull String errorCode,
83 @Nullable String errorMessage,
84 @Nullable Object errorDetails,
85 @Nullable String errorStacktrace) {
99 if (json instanceof JSONArray) {
100 final JSONArray array = (JSONArray) json;
101 if (array.length() == 1) {
104 if (array.length() == 3) {
105 final Object
code = array.get(0);
107 final Object details =
unwrapNull(array.opt(2));
113 throw new IllegalArgumentException(
"Invalid envelope: " + json);
114 }
catch (JSONException
e) {
115 throw new IllegalArgumentException(
"Invalid JSON",
e);
120 return (
value == JSONObject.NULL) ? null :
value;
Object decodeMessage(@Nullable ByteBuffer message)
static final JSONMessageCodec INSTANCE
ByteBuffer encodeMessage(@Nullable Object message)
Object unwrapNull(Object value)
ByteBuffer encodeSuccessEnvelope(@Nullable Object result)
MethodCall decodeMethodCall(@NonNull ByteBuffer message)
ByteBuffer encodeErrorEnvelopeWithStacktrace( @NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails, @Nullable String errorStacktrace)
static final JSONMethodCodec INSTANCE
Object decodeEnvelope(@NonNull ByteBuffer envelope)
ByteBuffer encodeErrorEnvelope( @NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails)
ByteBuffer encodeMethodCall(@NonNull MethodCall methodCall)
static Object wrap(@Nullable Object o)
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>