Skip to content

Commit

Permalink
Deprecate support for big integers in standard message codec (flutter…
Browse files Browse the repository at this point in the history
  • Loading branch information
mravn-google authored Jan 9, 2018
1 parent 5a72197 commit 84fc920
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.util.Map;
import java.util.Map.Entry;

import android.util.Log;

/**
* MessageCodec using the Flutter standard binary encoding.
*
Expand All @@ -27,7 +29,7 @@
* <ul>
* <li>null</li>
* <li>Booleans</li>
* <li>Bytes, Shorts, Integers, Longs, BigIntegers</li>
* <li>Bytes, Shorts, Integers, Longs</li>
* <li>Floats, Doubles</li>
* <li>Strings</li>
* <li>byte[], int[], long[], double[]</li>
Expand All @@ -40,7 +42,7 @@
* <ul>
* <li>null: null</li>
* <li>Boolean: bool</li>
* <li>Byte, Short, Integer, Long, BigInteger: int</li>
* <li>Byte, Short, Integer, Long: int</li>
* <li>Float, Double: double</li>
* <li>String: String</li>
* <li>byte[]: Uint8List</li>
Expand All @@ -50,6 +52,12 @@
* <li>List: List</li>
* <li>Map: Map</li>
* </ul>
*
* <p>Direct support for BigIntegers has been deprecated on 2018-01-09 to be made
* unavailable four weeks after this change is available on the Flutter alpha
* branch. BigIntegers were needed because the Dart 1.0 int type had no size
* limit. With Dart 2.0, the int type is a fixed-size, 64-bit signed integer.
* If you need to communicate larger integers, use String encoding instead.</p>
*/
public final class StandardMessageCodec implements MessageCodec<Object> {
public static final StandardMessageCodec INSTANCE = new StandardMessageCodec();
Expand Down Expand Up @@ -89,6 +97,7 @@ public Object decodeMessage(ByteBuffer message) {
private static final byte FALSE = 2;
private static final byte INT = 3;
private static final byte LONG = 4;
@Deprecated
private static final byte BIGINT = 5;
private static final byte DOUBLE = 6;
private static final byte STRING = 7;
Expand Down Expand Up @@ -195,6 +204,7 @@ static void writeValue(ByteArrayOutputStream stream, Object value) {
writeAlignment(stream, 8);
writeDouble(stream, ((Number) value).doubleValue());
} else if (value instanceof BigInteger) {
Log.w("Flutter", "Support for BigIntegers has been deprecated. Use String encoding instead.");
stream.write(BIGINT);
writeBytes(stream,
((BigInteger) value).toString(16).getBytes(UTF8));
Expand Down Expand Up @@ -301,6 +311,7 @@ static Object readValue(ByteBuffer buffer) {
result = buffer.getLong();
break;
case BIGINT: {
Log.w("Flutter", "Support for BigIntegers has been deprecated. Use String encoding instead.");
final byte[] hex = readBytes(buffer);
result = new BigInteger(new String(hex, UTF8), 16);
break;
Expand Down
8 changes: 8 additions & 0 deletions shell/platform/darwin/ios/framework/Headers/Flutter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
/**
BREAKING CHANGES:
January 09, 2018: Deprecated FlutterStandardBigInteger and its use in
FlutterStandardMessageCodec and FlutterStandardMethodCodec. Scheduled to
be marked as unavailable once the deprecation has been available on the
flutter/flutter alpha branch for four weeks. FlutterStandardBigInteger was
needed because the Dart 1.0 int type had no size limit. With Dart 2.0, the
int type is a fixed-size, 64-bit signed integer. If you need to communicate
larger integers, use NSString encoding instead.
December 11, 2017: Deprecated "initWithFLXArchive" and
"initWithFLXArchiveWithScriptSnapshot" and scheculed the same to be marked as
unavailable on January 15, 2018. Instead, "initWithFlutterAssets" and
Expand Down
16 changes: 14 additions & 2 deletions shell/platform/darwin/ios/framework/Headers/FlutterCodecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ FLUTTER_EXPORT
- `nil` or `NSNull`
- `NSNumber` (including their representation of Boolean values)
- `FlutterStandardBigInteger`
- `NSString`
- `FlutterStandardTypedData`
- `NSArray` of supported values
Expand All @@ -101,11 +100,17 @@ FLUTTER_EXPORT
- `nil` or `NSNull`: null
- `NSNumber`: `bool`, `int`, or `double`, depending on the contained value.
- `FlutterStandardBigInteger`: `int`
- `NSString`: `String`
- `FlutterStandardTypedData`: `Uint8List`, `Int32List`, `Int64List`, or `Float64List`
- `NSArray`: `List`
- `NSDictionary`: `Map`
Support for `FlutterStandardBigInteger` has been deprecated on 2018-01-09 to be
made unavailable four weeks after this change is available on the Flutter alpha
branch. `FlutterStandardBigInteger` were needed because the Dart 1.0 `int` type
had no size limit. With Dart 2.0, the `int` type is a fixed-size, 64-bit signed
integer. If you need to communicate larger integers, use `NSString` encoding
instead.
*/
FLUTTER_EXPORT
@interface FlutterStandardMessageCodec : NSObject<FlutterMessageCodec>
Expand Down Expand Up @@ -253,6 +258,13 @@ FLUTTER_EXPORT
and `FlutterStandardMethodCodec`.
*/
FLUTTER_EXPORT
FLUTTER_DEPRECATED(
"Deprecated on 2018-01-09 to be made unavailable four weeks after the "
"deprecation is available on the flutter/flutter alpha branch. "
"FlutterStandardBigInteger was needed because the Dart 1.0 int type had no "
"size limit. With Dart 2.0, the int type is a fixed-size, 64-bit signed "
"integer. If you need to communicate larger integers, use NSString encoding "
"instead.")
@interface FlutterStandardBigInteger : NSObject
/**
Creates a `FlutterStandardBigInteger` from a hexadecimal representation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ - (NSUInteger)hash {
}
@end

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

@implementation FlutterStandardBigInteger
+ (instancetype)bigIntegerWithHex:(NSString*)hex {
return [[[FlutterStandardBigInteger alloc] initWithHex:hex] autorelease];
Expand Down Expand Up @@ -469,3 +472,4 @@ - (id)readValue {
}
}
@end
#pragma clang diagnostic pop
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ void checkEncodeDecode(id value) {
checkEncodeDecode(@(value), [NSData dataWithBytes:bytes length:9]);
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
TEST(FlutterStandardCodec, CanEncodeAndDecodeUInt64AsHexString) {
FlutterStandardMessageCodec* codec = [FlutterStandardMessageCodec sharedInstance];
UInt64 u64 = 0xfffffffffffffffa;
NSData* encoded = [codec encode:@(u64)];
FlutterStandardBigInteger* decoded = [codec decode:encoded];
ASSERT_TRUE([decoded.hex isEqual:@"fffffffffffffffa"]);
}
#pragma clang diagnostic pop

TEST(FlutterStandardCodec, CanEncodeAndDecodeSInt8) {
uint8_t bytes[5] = {0x03, 0xfe, 0xff, 0xff, 0xff};
Expand All @@ -96,11 +99,14 @@ void checkEncodeDecode(id value) {
checkEncodeDecode(@(0x1234567890abcdef), [NSData dataWithBytes:bytes length:9]);
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
TEST(FlutterStandardCodec, CanEncodeAndDecodeBigInteger) {
FlutterStandardBigInteger* value =
[FlutterStandardBigInteger bigIntegerWithHex:@"-abcdef0123456789abcdef01234567890"];
checkEncodeDecode(value);
}
#pragma clang diagnostic pop

TEST(FlutterStandardCodec, CanEncodeAndDecodeFloat32) {
uint8_t bytes[16] = {0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down

0 comments on commit 84fc920

Please sign in to comment.