Commit 69653128 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Align doubles to 8 bytes in the StandardMessageCodec (#10758)

See https://github.com/flutter/flutter/issues/10701
parent 3db402ec
f741647d4977410ff8e2c02160eaa02bcb1f0a2b 784e9756720f7f6daa15c95ba3df6215bb54783f
...@@ -55,6 +55,7 @@ class WriteBuffer { ...@@ -55,6 +55,7 @@ class WriteBuffer {
/// Write an Float64 into the buffer. /// Write an Float64 into the buffer.
void putFloat64(double value) { void putFloat64(double value) {
_alignTo(8);
_eightBytes.setFloat64(0, value, Endianness.HOST_ENDIAN); _eightBytes.setFloat64(0, value, Endianness.HOST_ENDIAN);
_buffer.addAll(_eightBytesAsList); _buffer.addAll(_eightBytesAsList);
} }
...@@ -150,6 +151,7 @@ class ReadBuffer { ...@@ -150,6 +151,7 @@ class ReadBuffer {
/// Reads a Float64 from the buffer. /// Reads a Float64 from the buffer.
double getFloat64() { double getFloat64() {
_alignTo(8);
final double value = data.getFloat64(_position, Endianness.HOST_ENDIAN); final double value = data.getFloat64(_position, Endianness.HOST_ENDIAN);
_position += 8; _position += 8;
return value; return value;
......
...@@ -177,6 +177,14 @@ void main() { ...@@ -177,6 +177,14 @@ void main() {
]; ];
_checkEncodeDecode<dynamic>(standard, message); _checkEncodeDecode<dynamic>(standard, message);
}); });
test('should align doubles to 8 bytes', () {
_checkEncoding<dynamic>(
standard,
1.0,
<int>[6, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0xf0, 0x3f],
);
});
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment