mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add alignment padding to floats in std codec (flutter/engine#3780)
This commit is contained in:
parent
156f123b12
commit
da3ae8fc95
@ -275,6 +275,7 @@ using namespace shell;
|
||||
} else if (strcmp(type, @encode(double)) == 0 || strcmp(type, @encode(float)) == 0) {
|
||||
Float64 f = number.doubleValue;
|
||||
[self writeByte:FlutterStandardFieldFloat64];
|
||||
[self writeAlignment:8];
|
||||
[_data appendBytes:(UInt8*)&f length:8];
|
||||
} else if (strcmp(type, @encode(unsigned long)) == 0 ||
|
||||
strcmp(type, @encode(signed long long)) == 0 ||
|
||||
@ -430,6 +431,7 @@ using namespace shell;
|
||||
}
|
||||
case FlutterStandardFieldFloat64: {
|
||||
Float64 value;
|
||||
[self readAlignment:8];
|
||||
[self readBytes:&value length:8];
|
||||
return [NSNumber numberWithDouble:value];
|
||||
}
|
||||
|
||||
@ -103,13 +103,13 @@ TEST(FlutterStandardCodec, CanEncodeAndDecodeBigInteger) {
|
||||
}
|
||||
|
||||
TEST(FlutterStandardCodec, CanEncodeAndDecodeFloat32) {
|
||||
char bytes[9] = {0x06, 0x00, 0x00, 0x00, 0x60, 0xfb, 0x21, 0x09, 0x40};
|
||||
checkEncodeDecode(@3.1415927f, [NSData dataWithBytes:bytes length:9]);
|
||||
char bytes[16] = {0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xfb, 0x21, 0x09, 0x40};
|
||||
checkEncodeDecode(@3.1415927f, [NSData dataWithBytes:bytes length:16]);
|
||||
}
|
||||
|
||||
TEST(FlutterStandardCodec, CanEncodeAndDecodeFloat64) {
|
||||
char bytes[9] = {0x06, 0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40};
|
||||
checkEncodeDecode(@3.14159265358979311599796346854, [NSData dataWithBytes:bytes length:9]);
|
||||
char bytes[16] = {0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40};
|
||||
checkEncodeDecode(@3.14159265358979311599796346854, [NSData dataWithBytes:bytes length:16]);
|
||||
}
|
||||
|
||||
TEST(FlutterStandardCodec, CanEncodeAndDecodeString) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user