Unverified Commit aad36ab7 authored by Mikkel Nygaard Ravn's avatar Mikkel Nygaard Ravn Committed by GitHub

Remove large int support in standard message codec (#14011)

parent 0fe1e5bf
...@@ -179,9 +179,7 @@ class JSONMethodCodec implements MethodCodec { ...@@ -179,9 +179,7 @@ class JSONMethodCodec implements MethodCodec {
/// * null: null /// * null: null
/// * [bool]\: `java.lang.Boolean` /// * [bool]\: `java.lang.Boolean`
/// * [int]\: `java.lang.Integer` for values that are representable using 32-bit /// * [int]\: `java.lang.Integer` for values that are representable using 32-bit
/// two's complement; otherwise, `java.lang.Long` for values that are /// two's complement; `java.lang.Long` otherwise
/// representable using 64-bit two's complement; otherwise,
/// `java.math.BigInteger`.
/// * [double]\: `java.lang.Double` /// * [double]\: `java.lang.Double`
/// * [String]\: `java.lang.String` /// * [String]\: `java.lang.String`
/// * [Uint8List]\: `byte[]` /// * [Uint8List]\: `byte[]`
...@@ -196,9 +194,7 @@ class JSONMethodCodec implements MethodCodec { ...@@ -196,9 +194,7 @@ class JSONMethodCodec implements MethodCodec {
/// * null: nil /// * null: nil
/// * [bool]\: `NSNumber numberWithBool:` /// * [bool]\: `NSNumber numberWithBool:`
/// * [int]\: `NSNumber numberWithInt:` for values that are representable using /// * [int]\: `NSNumber numberWithInt:` for values that are representable using
/// 32-bit two's complement; otherwise, `NSNumber numberWithLong:` for values /// 32-bit two's complement; `NSNumber numberWithLong:` otherwise
/// that are representable using 64-bit two's complement; otherwise,
/// `FlutterStandardBigInteger`.
/// * [double]\: `NSNumber numberWithDouble:` /// * [double]\: `NSNumber numberWithDouble:`
/// * [String]\: `NSString` /// * [String]\: `NSString`
/// * [Uint8List], [Int32List], [Int64List], [Float64List]\: /// * [Uint8List], [Int32List], [Int64List], [Float64List]\:
...@@ -224,11 +220,8 @@ class StandardMessageCodec implements MessageCodec<dynamic> { ...@@ -224,11 +220,8 @@ class StandardMessageCodec implements MessageCodec<dynamic> {
// in the type byte (using _kNull, _kTrue, _kFalse) // in the type byte (using _kNull, _kTrue, _kFalse)
// * Integers representable in 32 bits are encoded using 4 bytes two's // * Integers representable in 32 bits are encoded using 4 bytes two's
// complement representation. // complement representation.
// * Larger integers representable in 64 bits are encoded using 8 bytes two's // * Larger integers are encoded using 8 bytes two's complement
// complement representation. // representation.
// * Still larger integers are encoded using their hexadecimal string
// representation. First the length of that is encoded in the expanding
// format, then follows the UTF-8 representation of the hex string.
// * doubles are encoded using the IEEE 754 64-bit double-precision binary // * doubles are encoded using the IEEE 754 64-bit double-precision binary
// format. // format.
// * Strings are encoded using their UTF-8 representation. First the length // * Strings are encoded using their UTF-8 representation. First the length
...@@ -306,14 +299,9 @@ class StandardMessageCodec implements MessageCodec<dynamic> { ...@@ -306,14 +299,9 @@ class StandardMessageCodec implements MessageCodec<dynamic> {
if (-0x7fffffff - 1 <= value && value <= 0x7fffffff) { if (-0x7fffffff - 1 <= value && value <= 0x7fffffff) {
buffer.putUint8(_kInt32); buffer.putUint8(_kInt32);
buffer.putInt32(value); buffer.putInt32(value);
} else if (-0x7fffffffffffffff - 1 <= value && value <= 0x7fffffffffffffff) { } else {
buffer.putUint8(_kInt64); buffer.putUint8(_kInt64);
buffer.putInt64(value); buffer.putInt64(value);
} else {
buffer.putUint8(_kLargeInt);
final List<int> hex = UTF8.encoder.convert(value.toRadixString(16));
_writeSize(buffer, hex.length);
buffer.putUint8List(hex);
} }
} else if (value is double) { } else if (value is double) {
buffer.putUint8(_kFloat64); buffer.putUint8(_kFloat64);
...@@ -388,6 +376,9 @@ class StandardMessageCodec implements MessageCodec<dynamic> { ...@@ -388,6 +376,9 @@ class StandardMessageCodec implements MessageCodec<dynamic> {
result = buffer.getInt64(); result = buffer.getInt64();
break; break;
case _kLargeInt: case _kLargeInt:
// Flutter Engine APIs to use large ints have been deprecated on
// 2018-01-09 and will be made unavailable.
// TODO(mravn): remove this case once the APIs are unavailable.
final int length = _readSize(buffer); final int length = _readSize(buffer);
final String hex = UTF8.decoder.convert(buffer.getUint8List(length)); final String hex = UTF8.decoder.convert(buffer.getUint8List(length));
result = int.parse(hex, radix: 16); result = int.parse(hex, radix: 16);
...@@ -467,7 +458,6 @@ class StandardMethodCodec implements MethodCodec { ...@@ -467,7 +458,6 @@ class StandardMethodCodec implements MethodCodec {
return buffer.done(); return buffer.done();
} }
@override @override
MethodCall decodeMethodCall(ByteData methodCall) { MethodCall decodeMethodCall(ByteData methodCall) {
final ReadBuffer buffer = new ReadBuffer(methodCall); final ReadBuffer buffer = new ReadBuffer(methodCall);
...@@ -479,7 +469,6 @@ class StandardMethodCodec implements MethodCodec { ...@@ -479,7 +469,6 @@ class StandardMethodCodec implements MethodCodec {
throw const FormatException('Invalid method call'); throw const FormatException('Invalid method call');
} }
@override @override
ByteData encodeSuccessEnvelope(dynamic result) { ByteData encodeSuccessEnvelope(dynamic result) {
final WriteBuffer buffer = new WriteBuffer(); final WriteBuffer buffer = new WriteBuffer();
...@@ -488,7 +477,6 @@ class StandardMethodCodec implements MethodCodec { ...@@ -488,7 +477,6 @@ class StandardMethodCodec implements MethodCodec {
return buffer.done(); return buffer.done();
} }
@override @override
ByteData encodeErrorEnvelope({@required String code, String message, dynamic details}) { ByteData encodeErrorEnvelope({@required String code, String message, dynamic details}) {
final WriteBuffer buffer = new WriteBuffer(); final WriteBuffer buffer = new WriteBuffer();
......
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