Google celebrates Hispanic Heritage Month. See how.

decodeMessageWithCallback<A> function

A decodeMessageWithCallback <A>(IncomingMessage 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.


A decodeMessageWithCallback<A>(
    IncomingMessage message, int inlineSize, A Function(Decoder decoder) f) {
  final int size = kMessageHeaderSize + inlineSize;
  final Decoder decoder = Decoder(message)..claimBytes(size, 0);
  A out = f(decoder);
  final int padding = align(size) - size;
  decoder.checkPadding(size, padding);
  return out;