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

Public Member Functions

ByteBuffer encodeMessage (@Nullable Object message)
 
Object decodeMessage (@Nullable ByteBuffer message)
 
- Public Member Functions inherited from io.flutter.plugin.common.MessageCodec< Object >
ByteBuffer encodeMessage ( @Nullable T message)
 
T decodeMessage ( @Nullable ByteBuffer message)
 

Static Public Attributes

static final JSONMessageCodec INSTANCE = new JSONMessageCodec()
 

Detailed Description

A MessageCodec using UTF-8 encoded JSON messages.

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

Supports the same Java values as JSONObject#wrap(Object).

On the Dart side, JSON messages are handled by the JSON facilities of the dart:convert package.

Definition at line 25 of file JSONMessageCodec.java.

Member Function Documentation

◆ decodeMessage()

Object io.flutter.plugin.common.JSONMessageCodec.decodeMessage ( @Nullable ByteBuffer  message)
inline

Definition at line 47 of file JSONMessageCodec.java.

47 {
48 if (message == null) {
49 return null;
50 }
51 try {
52 final String json = StringCodec.INSTANCE.decodeMessage(message);
53 final JSONTokener tokener = new JSONTokener(json);
54 final Object value = tokener.nextValue();
55 if (tokener.more()) {
56 throw new IllegalArgumentException("Invalid JSON");
57 }
58 return value;
59 } catch (JSONException e) {
60 throw new IllegalArgumentException("Invalid JSON", e);
61 }
62 }
uint8_t value
Win32Message message

◆ encodeMessage()

ByteBuffer io.flutter.plugin.common.JSONMessageCodec.encodeMessage ( @Nullable Object  message)
inline

Definition at line 33 of file JSONMessageCodec.java.

33 {
34 if (message == null) {
35 return null;
36 }
37 final Object wrapped = JSONUtil.wrap(message);
38 if (wrapped instanceof String) {
39 return StringCodec.INSTANCE.encodeMessage(JSONObject.quote((String) wrapped));
40 } else {
41 return StringCodec.INSTANCE.encodeMessage(wrapped.toString());
42 }
43 }
static sk_sp< GrTextureProxy > wrapped(skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)

Member Data Documentation

◆ INSTANCE

final JSONMessageCodec io.flutter.plugin.common.JSONMessageCodec.INSTANCE = new JSONMessageCodec()
static

Definition at line 27 of file JSONMessageCodec.java.


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