Google is committed to advancing racial equity for Black communities. See how.

decodeMessageWithCallback<A> function

*<Null safety>*

A decodeMessageWithCallback <A>(Message message, int inlineSize, A f(Decoder decoder))

Decodes a FIDL message with multiple parameters. The callback parameter provides a decoder that is initialized on the provided Message, which callers can use to decode specific types. The return result of the callback (e.g. the decoded parameters, wrapped in a containing class/struct) is returned as the result of the function. This functionality (decoding multiple parameters) is implemented using a callback because returning a list would be insufficient: the list would be of type List, whereas we want to retain concrete types of each decoded parameter. The only way to accomplish this in Dart is to pass in a function that collects these multiple values into a bespoke, properly typed class.

Implementation

A decodeMessageWithCallback<A>(
    Message message, int inlineSize, A Function(Decoder decoder) f) {
  final Decoder decoder = Decoder(message)
    ..claimMemory(kMessageHeaderSize + inlineSize);
  A out = f(decoder);
  decoder.claimMemoryComplete();
  _validateDecoding(decoder);
  return out;
}