Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
MessageCodec.java
Go to the documentation of this file.
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
5package io.flutter.plugin.common;
6
7import androidx.annotation.Nullable;
8import java.nio.ByteBuffer;
9
10/**
11 * A message encoding/decoding mechanism.
12 *
13 * <p>Both operations throw {@link IllegalArgumentException}, if conversion fails.
14 */
15public interface MessageCodec<T> {
16 /**
17 * Encodes the specified message into binary.
18 *
19 * @param message the T message, possibly null.
20 * @return a ByteBuffer containing the encoding between position 0 and the current position, or
21 * null, if message is null.
22 */
23 @Nullable
24 ByteBuffer encodeMessage(@Nullable T message);
25
26 /**
27 * Decodes the specified message from binary.
28 *
29 * <p><b>Warning:</b> The ByteBuffer is "direct" and it won't be valid beyond this call. Storing
30 * the ByteBuffer and using it later and will lead to a {@code java.nio.BufferUnderflowException}.
31 * If you want to retain the data you'll need to copy it.
32 *
33 * @param message the {@link ByteBuffer} message, possibly null.
34 * @return a T value representation of the bytes between the given buffer's current position and
35 * its limit, or null, if message is null.
36 */
37 @Nullable
38 T decodeMessage(@Nullable ByteBuffer message);
39}
T decodeMessage(@Nullable ByteBuffer message)
ByteBuffer encodeMessage(@Nullable T message)
Win32Message message
#define T