Skip to content

Commit

Permalink
Add alignment padding to floats in std codec (flutter#3780)
Browse files Browse the repository at this point in the history
  • Loading branch information
mravn-google authored Jun 16, 2017
1 parent ab2bc15 commit 784e975
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ - (void)writeValue:(id)value {
} 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 ||
Expand Down Expand Up @@ -430,6 +431,7 @@ - (id)readValue {
}
case FlutterStandardFieldFloat64: {
Float64 value;
[self readAlignment:8];
[self readBytes:&value length:8];
return [NSNumber numberWithDouble:value];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ void checkEncodeDecode(id value) {
}

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) {
Expand Down

0 comments on commit 784e975

Please sign in to comment.