| |
| |
| |
| # decodeMessageWithCallback<A> function |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| A decodeMessageWithCallback |
| <A>([IncomingMessage](../package-fidl_fidl/IncomingMessage-class.md) message, int inlineSize, A f([Decoder](../package-fidl_fidl/Decoder-class.md) decoder)) |
| |
| |
| |
| <p>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<fidltype>, |
| 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.</fidltype></p> |
| |
| |
| |
| ## Implementation |
| |
| ```dart |
| 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); |
| _validateDecoding(decoder); |
| return out; |
| } |
| ``` |
| |
| |
| |
| |
| |
| |
| |