提交 784e9756 编写于 作者: M Mikkel Nygaard Ravn 提交者: GitHub

Add alignment padding to floats in std codec (#3780)

上级 ab2bc15f
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册