2018-11-07 12:24:35 -08:00
|
|
|
// Copyright 2013 The Flutter Authors. All rights reserved.
|
2017-03-01 13:54:32 +01:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package io.flutter.plugin.common;
|
|
|
|
|
|
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A codec for method calls and enveloped results.
|
|
|
|
|
*
|
|
|
|
|
* Method calls are encoded as binary messages with enough structure that the codec can
|
|
|
|
|
* extract a method name String and an arguments Object. These data items are used to populate a
|
|
|
|
|
* {@link MethodCall}.
|
|
|
|
|
*
|
|
|
|
|
* All operations throw {@link IllegalArgumentException}, if conversion fails.
|
|
|
|
|
*/
|
|
|
|
|
public interface MethodCodec {
|
2017-03-17 09:04:59 +01:00
|
|
|
/**
|
|
|
|
|
* Encodes a message call into binary.
|
|
|
|
|
*
|
|
|
|
|
* @param methodCall a {@link MethodCall}.
|
|
|
|
|
* @return a {@link ByteBuffer} containing the encoding between position 0 and
|
|
|
|
|
* the current position.
|
|
|
|
|
*/
|
|
|
|
|
ByteBuffer encodeMethodCall(MethodCall methodCall);
|
|
|
|
|
|
2017-03-01 13:54:32 +01:00
|
|
|
/**
|
|
|
|
|
* Decodes a message call from binary.
|
|
|
|
|
*
|
|
|
|
|
* @param methodCall the binary encoding of the method call as a {@link ByteBuffer}.
|
|
|
|
|
* @return a {@link MethodCall} representation of the bytes between the given buffer's current
|
|
|
|
|
* position and its limit.
|
|
|
|
|
*/
|
|
|
|
|
MethodCall decodeMethodCall(ByteBuffer methodCall);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Encodes a successful result into a binary envelope message.
|
|
|
|
|
*
|
|
|
|
|
* @param result The result value, possibly null.
|
2017-03-17 09:04:59 +01:00
|
|
|
* @return a {@link ByteBuffer} containing the encoding between position 0 and
|
2017-03-01 13:54:32 +01:00
|
|
|
* the current position.
|
|
|
|
|
*/
|
|
|
|
|
ByteBuffer encodeSuccessEnvelope(Object result);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Encodes an error result into a binary envelope message.
|
|
|
|
|
*
|
|
|
|
|
* @param errorCode An error code String.
|
|
|
|
|
* @param errorMessage An error message String, possibly null.
|
|
|
|
|
* @param errorDetails Error details, possibly null.
|
2017-03-17 09:04:59 +01:00
|
|
|
* @return a {@link ByteBuffer} containing the encoding between position 0 and
|
2017-03-01 13:54:32 +01:00
|
|
|
* the current position.
|
|
|
|
|
*/
|
|
|
|
|
ByteBuffer encodeErrorEnvelope(String errorCode, String errorMessage, Object errorDetails);
|
2017-03-17 09:04:59 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Decodes a result envelope from binary.
|
|
|
|
|
*
|
|
|
|
|
* @param envelope the binary encoding of a result envelope as a {@link ByteBuffer}.
|
|
|
|
|
* @return the enveloped result Object.
|
|
|
|
|
* @throws FlutterException if the envelope was an error envelope.
|
|
|
|
|
*/
|
|
|
|
|
Object decodeEnvelope(ByteBuffer envelope);
|
2017-03-01 13:54:32 +01:00
|
|
|
}
|