• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package io.flutter.plugin.common;
6 
7 import android.support.annotation.Nullable;
8 
9 import java.nio.ByteBuffer;
10 
11 /**
12  * A message encoding/decoding mechanism.
13  *
14  * Both operations throw {@link IllegalArgumentException}, if conversion fails.
15  */
16 public interface MessageCodec<T> {
17     /**
18      * Encodes the specified message into binary.
19      *
20      * @param message the T message, possibly null.
21      * @return a ByteBuffer containing the encoding between position 0 and
22      * the current position, or null, if message is null.
23      */
24     @Nullable
encodeMessage(@ullable T message)25     ByteBuffer encodeMessage(@Nullable T message);
26 
27     /**
28      * Decodes the specified message from binary.
29      *
30      * @param message the {@link ByteBuffer} message, possibly null.
31      * @return a T value representation of the bytes between the given buffer's current
32      * position and its limit, or null, if message is null.
33      */
34     @Nullable
decodeMessage(@ullable ByteBuffer message)35     T decodeMessage(@Nullable ByteBuffer message);
36 }
37