public final class StandardMethodCodec extends Object implements MethodCodec
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
.
Modifier and Type | Field and Description |
---|---|
static StandardMethodCodec |
INSTANCE |
Constructor and Description |
---|
StandardMethodCodec(StandardMessageCodec messageCodec)
Creates a new method codec based on the specified message codec.
|
Modifier and Type | Method and Description |
---|---|
Object |
decodeEnvelope(ByteBuffer envelope)
Decodes a result envelope from binary.
|
MethodCall |
decodeMethodCall(ByteBuffer methodCall)
Decodes a message call from binary.
|
ByteBuffer |
encodeErrorEnvelope(String errorCode,
String errorMessage,
Object errorDetails)
Encodes an error result into a binary envelope message.
|
ByteBuffer |
encodeErrorEnvelopeWithStacktrace(String errorCode,
String errorMessage,
Object errorDetails,
String errorStacktrace)
Encodes an error result into a binary envelope message with the native stacktrace.
|
ByteBuffer |
encodeMethodCall(MethodCall methodCall)
Encodes a message call into binary.
|
ByteBuffer |
encodeSuccessEnvelope(Object result)
Encodes a successful result into a binary envelope message.
|
public static final StandardMethodCodec INSTANCE
public StandardMethodCodec(StandardMessageCodec messageCodec)
public ByteBuffer encodeMethodCall(MethodCall methodCall)
MethodCodec
encodeMethodCall
in interface MethodCodec
methodCall
- a MethodCall
.ByteBuffer
containing the encoding between position 0 and the current
position.public MethodCall decodeMethodCall(ByteBuffer methodCall)
MethodCodec
decodeMethodCall
in interface MethodCodec
methodCall
- the binary encoding of the method call as a ByteBuffer
.MethodCall
representation of the bytes between the given buffer's current
position and its limit.public ByteBuffer encodeSuccessEnvelope(Object result)
MethodCodec
encodeSuccessEnvelope
in interface MethodCodec
result
- The result value, possibly null.ByteBuffer
containing the encoding between position 0 and the current
position.public ByteBuffer encodeErrorEnvelope(String errorCode, String errorMessage, Object errorDetails)
MethodCodec
encodeErrorEnvelope
in interface MethodCodec
errorCode
- An error code String.errorMessage
- An error message String, possibly null.errorDetails
- Error details, possibly null. Consider supporting Throwable
in your
codec. This is the most common value passed to this field.ByteBuffer
containing the encoding between position 0 and the current
position.public ByteBuffer encodeErrorEnvelopeWithStacktrace(String errorCode, String errorMessage, Object errorDetails, String errorStacktrace)
MethodCodec
encodeErrorEnvelopeWithStacktrace
in interface MethodCodec
errorCode
- An error code String.errorMessage
- An error message String, possibly null.errorDetails
- Error details, possibly null. Consider supporting Throwable
in your
codec. This is the most common value passed to this field.errorStacktrace
- Platform stacktrace for the error. possibly null.ByteBuffer
containing the encoding between position 0 and the current
position.public Object decodeEnvelope(ByteBuffer envelope)
MethodCodec
decodeEnvelope
in interface MethodCodec
envelope
- the binary encoding of a result envelope as a ByteBuffer
.