public class StandardMessageCodec extends Object implements MessageCodec<Object>
This codec is guaranteed to be compatible with the corresponding StandardMessageCodec on the Dart side. These parts of the Flutter SDK are evolved synchronously.
Supported messages are acyclic values of these forms:
On the Dart side, these values are represented as follows:
BigIntegers are represented in Dart as strings with the hexadecimal representation of the integer's value.
To extend the codec, overwrite the writeValue and readValueOfType methods.
Modifier and Type | Field and Description |
---|---|
static StandardMessageCodec |
INSTANCE |
Constructor and Description |
---|
StandardMessageCodec() |
Modifier and Type | Method and Description |
---|---|
Object |
decodeMessage(ByteBuffer message)
Decodes the specified message from binary.
|
ByteBuffer |
encodeMessage(Object message)
Encodes the specified message into binary.
|
protected static void |
readAlignment(ByteBuffer buffer,
int alignment)
Reads alignment padding bytes as written by writeAlignment.
|
protected static byte[] |
readBytes(ByteBuffer buffer)
Reads a byte array as written by writeBytes.
|
protected static int |
readSize(ByteBuffer buffer)
Reads an int representing a size as written by writeSize.
|
protected Object |
readValue(ByteBuffer buffer)
Reads a value as written by writeValue.
|
protected Object |
readValueOfType(byte type,
ByteBuffer buffer)
Reads a value of the specified type.
|
protected static void |
writeAlignment(ByteArrayOutputStream stream,
int alignment)
Writes a number of padding bytes to the specified stream to ensure that
the next value is aligned to a whole multiple of the specified alignment.
|
protected static void |
writeBytes(ByteArrayOutputStream stream,
byte[] bytes)
Writes the length and then the actual bytes of the specified array to
the specified stream.
|
protected static void |
writeChar(ByteArrayOutputStream stream,
int value)
Writes the least significant two bytes of the specified int to the
specified stream.
|
protected static void |
writeDouble(ByteArrayOutputStream stream,
double value)
Writes the specified double as 8 bytes to the specified stream.
|
protected static void |
writeInt(ByteArrayOutputStream stream,
int value)
Writes the specified int as 4 bytes to the specified stream.
|
protected static void |
writeLong(ByteArrayOutputStream stream,
long value)
Writes the specified long as 8 bytes to the specified stream.
|
protected static void |
writeSize(ByteArrayOutputStream stream,
int value)
Writes an int representing a size to the specified stream.
|
protected void |
writeValue(ByteArrayOutputStream stream,
Object value)
Writes a type discriminator byte and then a byte serialization of the
specified value to the specified stream.
|
public static final StandardMessageCodec INSTANCE
public ByteBuffer encodeMessage(Object message)
MessageCodec
encodeMessage
in interface MessageCodec<Object>
message
- the T message, possibly null.public Object decodeMessage(ByteBuffer message)
MessageCodec
decodeMessage
in interface MessageCodec<Object>
message
- the ByteBuffer
message, possibly null.protected static final void writeSize(ByteArrayOutputStream stream, int value)
protected static final void writeChar(ByteArrayOutputStream stream, int value)
protected static final void writeInt(ByteArrayOutputStream stream, int value)
protected static final void writeLong(ByteArrayOutputStream stream, long value)
protected static final void writeDouble(ByteArrayOutputStream stream, double value)
protected static final void writeBytes(ByteArrayOutputStream stream, byte[] bytes)
protected static final void writeAlignment(ByteArrayOutputStream stream, int alignment)
protected void writeValue(ByteArrayOutputStream stream, Object value)
Subclasses can extend the codec by overriding this method, calling super for values that the extension does not handle.
protected static final int readSize(ByteBuffer buffer)
protected static final byte[] readBytes(ByteBuffer buffer)
protected static final void readAlignment(ByteBuffer buffer, int alignment)
protected final Object readValue(ByteBuffer buffer)
protected Object readValueOfType(byte type, ByteBuffer buffer)
Subclasses may extend the codec by overriding this method, calling super for types that the extension does not handle.