public final class BinaryCodec extends Object implements MessageCodec<ByteBuffer>
MessageCodec
using unencoded binary messages, represented as ByteBuffer
s.
This codec is guaranteed to be compatible with the corresponding BinaryCodec on the Dart side. These parts of the Flutter SDK are evolved synchronously.
On the Dart side, messages are represented using ByteData
.
Modifier and Type | Field and Description |
---|---|
static BinaryCodec |
INSTANCE |
static BinaryCodec |
INSTANCE_DIRECT
A BinaryCodec that returns direct ByteBuffers from `decodeMessage` for better performance.
|
Modifier and Type | Method and Description |
---|---|
ByteBuffer |
decodeMessage(ByteBuffer message)
Decodes the specified message from binary.
|
ByteBuffer |
encodeMessage(ByteBuffer message)
Encodes the specified message into binary.
|
public static final BinaryCodec INSTANCE
public static final BinaryCodec INSTANCE_DIRECT
BinaryCodec(boolean)
public ByteBuffer encodeMessage(@Nullable ByteBuffer message)
MessageCodec
encodeMessage
in interface MessageCodec<ByteBuffer>
message
- the T message, possibly null.public ByteBuffer decodeMessage(@Nullable ByteBuffer message)
MessageCodec
Warning: The ByteBuffer is "direct" and it won't be valid beyond this call. Storing
the ByteBuffer and using it later and will lead to a java.nio.BufferUnderflowException
.
If you want to retain the data you'll need to copy it.
decodeMessage
in interface MessageCodec<ByteBuffer>
message
- the ByteBuffer
message, possibly null.