Package io.flutter.plugin.common
Class JSONMethodCodec
- java.lang.Object
-
- io.flutter.plugin.common.JSONMethodCodec
-
- All Implemented Interfaces:
MethodCodec
public final class JSONMethodCodec extends Object implements MethodCodec
AMethodCodecusing 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 by
JSONMessageCodec.
-
-
Field Summary
Fields Modifier and Type Field Description static JSONMethodCodecINSTANCE
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectdecodeEnvelope(ByteBuffer envelope)Decodes a result envelope from binary.MethodCalldecodeMethodCall(ByteBuffer message)Decodes a message call from binary.ByteBufferencodeErrorEnvelope(String errorCode, String errorMessage, Object errorDetails)Encodes an error result into a binary envelope message.ByteBufferencodeErrorEnvelopeWithStacktrace(String errorCode, String errorMessage, Object errorDetails, String errorStacktrace)Encodes an error result into a binary envelope message with the native stacktrace.ByteBufferencodeMethodCall(MethodCall methodCall)Encodes a message call into binary.ByteBufferencodeSuccessEnvelope(Object result)Encodes a successful result into a binary envelope message.
-
-
-
Field Detail
-
INSTANCE
public static final JSONMethodCodec INSTANCE
-
-
Method Detail
-
encodeMethodCall
@NonNull public ByteBuffer encodeMethodCall(@NonNull MethodCall methodCall)
Description copied from interface:MethodCodecEncodes a message call into binary.- Specified by:
encodeMethodCallin interfaceMethodCodec- Parameters:
methodCall- aMethodCall.- Returns:
- a
ByteBuffercontaining the encoding between position 0 and the current position.
-
decodeMethodCall
@NonNull public MethodCall decodeMethodCall(@NonNull ByteBuffer message)
Description copied from interface:MethodCodecDecodes a message call from binary.- Specified by:
decodeMethodCallin interfaceMethodCodec- Parameters:
message- the binary encoding of the method call as aByteBuffer.- Returns:
- a
MethodCallrepresentation of the bytes between the given buffer's current position and its limit.
-
encodeSuccessEnvelope
@NonNull public ByteBuffer encodeSuccessEnvelope(@Nullable Object result)
Description copied from interface:MethodCodecEncodes a successful result into a binary envelope message.- Specified by:
encodeSuccessEnvelopein interfaceMethodCodec- Parameters:
result- The result value, possibly null.- Returns:
- a
ByteBuffercontaining the encoding between position 0 and the current position.
-
encodeErrorEnvelope
@NonNull public ByteBuffer encodeErrorEnvelope(@NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails)
Description copied from interface:MethodCodecEncodes an error result into a binary envelope message.- Specified by:
encodeErrorEnvelopein interfaceMethodCodec- Parameters:
errorCode- An error code String.errorMessage- An error message String, possibly null.errorDetails- Error details, possibly null. Consider supportingThrowablein your codec. This is the most common value passed to this field.- Returns:
- a
ByteBuffercontaining the encoding between position 0 and the current position.
-
encodeErrorEnvelopeWithStacktrace
@NonNull public ByteBuffer encodeErrorEnvelopeWithStacktrace(@NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails, @Nullable String errorStacktrace)
Description copied from interface:MethodCodecEncodes an error result into a binary envelope message with the native stacktrace.- Specified by:
encodeErrorEnvelopeWithStacktracein interfaceMethodCodec- Parameters:
errorCode- An error code String.errorMessage- An error message String, possibly null.errorDetails- Error details, possibly null. Consider supportingThrowablein your codec. This is the most common value passed to this field.errorStacktrace- Platform stacktrace for the error. possibly null.- Returns:
- a
ByteBuffercontaining the encoding between position 0 and the current position.
-
decodeEnvelope
@NonNull public Object decodeEnvelope(@NonNull ByteBuffer envelope)
Description copied from interface:MethodCodecDecodes a result envelope from binary.- Specified by:
decodeEnvelopein interfaceMethodCodec- Parameters:
envelope- the binary encoding of a result envelope as aByteBuffer.- Returns:
- the enveloped result Object.
-
-