Skip to content

Commit

Permalink
Document channel message value conversions (flutter#3633)
Browse files Browse the repository at this point in the history
  • Loading branch information
mravn-google authored Apr 28, 2017
1 parent 7c699ce commit da8ebf4
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
import java.nio.ByteBuffer;

/**
* A {@link MessageCodec} using unencoded binary messages, represented as {@link ByteBuffer}s.
* A {@link MessageCodec} using unencoded binary messages, represented as
* {@link ByteBuffer}s.
*
* <p>This codec is guaranteed to be compatible with the corresponding
* <a href="https://docs.flutter.io/flutter/services/BinaryCodec-class.html">BinaryCodec</a>
* on the Dart side. These parts of the Flutter SDK are evolved synchronously.</p>
*
* <p>On the Dart side, messages are represented using {@code ByteData}.</p>
*/
public final class BinaryCodec implements MessageCodec<ByteBuffer> {
// This codec must match the Dart codec of the same name in package flutter/services.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@
/**
* A {@link MessageCodec} using UTF-8 encoded JSON messages.
*
* Supports the same Java values as {@link JSONObject#wrap(Object)}.
* <p>This codec is guaranteed to be compatible with the corresponding
* <a href="https://docs.flutter.io/flutter/services/JSONMessageCodec-class.html">JSONMessageCodec</a>
* on the Dart side. These parts of the Flutter SDK are evolved synchronously.</p>
*
* <p>Supports the same Java values as {@link JSONObject#wrap(Object)}.</p>
*
* <p>On the Dart side, JSON messages are handled by the JSON facilities of the
* <a href="https://api.dartlang.org/stable/dart-convert/JSON-constant.html">dart:convert</a>
* package.</p>
*/
public final class JSONMessageCodec implements MessageCodec<Object> {
// This codec must match the Dart codec of the same name in package flutter/services.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@

/**
* A {@link MethodCodec} using UTF-8 encoded JSON method calls and result envelopes.
* Values supported as methods arguments and result payloads are those supported by
* {@link JSONMessageCodec}.
*
* <p>This codec is guaranteed to be compatible with the corresponding
* <a href="https://docs.flutter.io/flutter/services/JSONMethodCodec-class.html">JSONMethodCodec</a>
* on the Dart side. These parts of the Flutter SDK are evolved synchronously.</p>
*
* <p>Values supported as methods arguments and result payloads are those supported by
* {@link JSONMessageCodec}.</p>
*/
public final class JSONMethodCodec implements MethodCodec {
// This codec must match the Dart codec of the same name in package flutter/services.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
/**
* MessageCodec using the Flutter standard binary encoding.
*
* The standard encoding is guaranteed to be compatible with the corresponding standard codec
* for PlatformMessageChannels on the Flutter side. These parts of the Flutter SDK are evolved
* synchronously.
* <p>This codec is guaranteed to be compatible with the corresponding
* <a href="https://docs.flutter.io/flutter/services/StandardMessageCodec-class.html">StandardMessageCodec</a>
* on the Dart side. These parts of the Flutter SDK are evolved synchronously.</p>
*
* Supported messages are acyclic values of these forms:
* <p>Supported messages are acyclic values of these forms:</p>
*
* <ul>
* <li>null</li>
Expand All @@ -34,9 +34,24 @@
* <li>Lists of supported values</li>
* <li>Maps with supported keys and values</li>
* </ul>
*
* <p>On the Dart side, these values are represented as follows:</p>
*
* <ul>
* <li>null: null</li>
* <li>Boolean: bool</li>
* <li>Byte, Short, Integer, Long, BigInteger: int</li>
* <li>Float, Double: double</li>
* <li>String: String</li>
* <li>byte[]: Uint8List</li>
* <li>int[]: Int32List</li>
* <li>long[]: Int64List</li>
* <li>double[]: Float64List</li>
* <li>List: List</li>
* <li>Map: Map</li>
* </ul>
*/
public final class StandardMessageCodec implements MessageCodec<Object> {
// This codec must match the Dart codec of the same name in package flutter/services.
public static final StandardMessageCodec INSTANCE = new StandardMessageCodec();

private StandardMessageCodec() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
/**
* A {@link MethodCodec} using the Flutter standard binary encoding.
*
* The standard codec is guaranteed to be compatible with the corresponding standard codec for
* PlatformMethodChannels on the Flutter side. These parts of the Flutter SDK are evolved
* synchronously.
* <p>This codec is guaranteed to be compatible with the corresponding
* <a href="https://docs.flutter.io/flutter/services/StandardMethodCodec-class.html">StandardMethodCodec</a>
* on the Dart side. These parts of the Flutter SDK are evolved synchronously.</p>
*
* Values supported as method arguments and result payloads are those supported by
* {@link StandardMessageCodec}.
* <p>Values supported as method arguments and result payloads are those supported by
* {@link StandardMessageCodec}.</p>
*/
public final class StandardMethodCodec implements MethodCodec {
// This codec must match the Dart codec of the same name in package flutter/services.
public static final StandardMethodCodec INSTANCE = new StandardMethodCodec();

private StandardMethodCodec() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

/**
* A {@link MessageCodec} using UTF-8 encoded String messages.
*
* <p>This codec is guaranteed to be compatible with the corresponding
* <a href="https://docs.flutter.io/flutter/services/StringCodec-class.html">StringCodec</a>
* on the Dart side. These parts of the Flutter SDK are evolved synchronously.</p>
*/
public final class StringCodec implements MessageCodec<String> {
// This codec must match the Dart codec of the same name in package flutter/services.
private static final Charset UTF8 = Charset.forName("UTF8");
public static final StringCodec INSTANCE = new StringCodec();

Expand Down
53 changes: 44 additions & 9 deletions shell/platform/darwin/ios/framework/Headers/FlutterCodecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,23 @@ FLUTTER_EXPORT
/**
A `FlutterMessageCodec` using unencoded binary messages, represented as
`NSData` instances.
This codec is guaranteed to be compatible with the corresponding
[BinaryCodec](https://docs.flutter.io/flutter/services/BinaryCodec-class.html)
on the Dart side. These parts of the Flutter SDK are evolved synchronously.
On the Dart side, messages are represented using `ByteData`.
*/
FLUTTER_EXPORT
@interface FlutterBinaryCodec : NSObject<FlutterMessageCodec>
@end

/**
A `FlutterMessageCodec` using UTF-8 encoded `NSString` messages.
This codec is guaranteed to be compatible with the corresponding
[StringCodec](https://docs.flutter.io/flutter/services/StringCodec-class.html)
on the Dart side. These parts of the Flutter SDK are evolved synchronously.
*/
FLUTTER_EXPORT
@interface FlutterStringCodec : NSObject<FlutterMessageCodec>
Expand All @@ -55,7 +65,16 @@ FLUTTER_EXPORT
/**
A `FlutterMessageCodec` using UTF-8 encoded JSON messages.
Supports the same values as `NSJSONSerialization`.
This codec is guaranteed to be compatible with the corresponding
[JSONMessageCodec](https://docs.flutter.io/flutter/services/JSONMessageCodec-class.html)
on the Dart side. These parts of the Flutter SDK are evolved synchronously.
Supports values accepted by `NSJSONSerialization` plus top-level
`nil`, `NSNumber`, and `NSString`.
On the Dart side, JSON messages are handled by the JSON facilities of the
[`dart:convert`](https://api.dartlang.org/stable/dart-convert/JSON-constant.html)
package.
*/
FLUTTER_EXPORT
@interface FlutterJSONMessageCodec : NSObject<FlutterMessageCodec>
Expand All @@ -64,19 +83,29 @@ FLUTTER_EXPORT
/**
A `FlutterMessageCodec` using the Flutter standard binary encoding.
The standard encoding is guaranteed to be compatible with the corresponding
standard codec for PlatformMessageChannels on the Flutter side. These parts
of the Flutter SDK are evolved synchronously.
This codec is guaranteed to be compatible with the corresponding
[StandardMessageCodec](https://docs.flutter.io/flutter/services/StandardMessageCodec-class.html)
on the Dart side. These parts of the Flutter SDK are evolved synchronously.
Supported messages are acyclic values of these forms:
- `nil` or `NSNull`
- `NSNumber` (including their representation of Boolean values)
- `FlutterStandardBigInteger`
- `FlutterStandardTypedData`
- `NSString`
- `FlutterStandardTypedData`
- `NSArray` of supported values
- `NSDictionary` with supported keys and values
On the Dart side, these values are represented as follows:
- `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`
*/
FLUTTER_EXPORT
@interface FlutterStandardMessageCodec : NSObject<FlutterMessageCodec>
Expand Down Expand Up @@ -308,7 +337,13 @@ FLUTTER_EXPORT

/**
A `FlutterMethodCodec` using UTF-8 encoded JSON method calls and result
envelopes. Values supported as methods arguments and result payloads are
envelopes.
This codec is guaranteed to be compatible with the corresponding
[JSONMethodCodec](https://docs.flutter.io/flutter/services/JSONMethodCodec-class.html)
on the Dart side. These parts of the Flutter SDK are evolved synchronously.
Values supported as methods arguments and result payloads are
those supported as top-level or leaf values by `FlutterJSONMessageCodec`.
*/
FLUTTER_EXPORT
Expand All @@ -318,9 +353,9 @@ FLUTTER_EXPORT
/**
A `FlutterMethodCodec` using the Flutter standard binary encoding.
The standard codec is guaranteed to be compatible with the corresponding
standard codec for PlatformMethodChannels on the Flutter side. These parts of
the Flutter SDK are evolved synchronously.
This codec is guaranteed to be compatible with the corresponding
[StandardMethodCodec](https://docs.flutter.io/flutter/services/StandardMethodCodec-class.html)
on the Dart side. These parts of the Flutter SDK are evolved synchronously.
Values supported as method arguments and result payloads are those supported by
`FlutterStandardMessageCodec`.
Expand Down

0 comments on commit da8ebf4

Please sign in to comment.