Chris Bracken d2800926d1 Decode empty message to nil in standard codec (flutter/engine#25064)
This updates Flutter.*Codec `decode:` implementations to treat empty
messages as equivalent to nil or NSNull, which avoids a crash when we
subsequently otherwise try to read the type/value from the message. This
handles the case where the sender were to send `null` over the channel.
e.g.,

    final channel = BasicMessageChannel<Object?>('somechannel', StandardMessageCodec());
    channel.send(null);

It also updates the macOS embedder to send nil to the decoder when a
zero-length message is received in order to be consistent with the iOS
embedding.

Previously, the macOS embedder always encoded platform messages as
NSData regardless of length:
ca1a7760b4/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm (L498-L500)

The iOS embedder did not have this issue since it special-cased
zero-length messages as nil:
ca1a7760b4/shell/platform/darwin/ios/framework/Source/platform_message_router.mm (L23-L26)

Bug: https://github.com/flutter/flutter/issues/78003
2021-03-18 14:09:37 -07:00
..