Flutter Engine
fl_method_codec.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_LINUX_FL_METHOD_CODEC_H_
6 #define FLUTTER_SHELL_PLATFORM_LINUX_FL_METHOD_CODEC_H_
7 
8 #if !defined(__FLUTTER_LINUX_INSIDE__) && !defined(FLUTTER_LINUX_COMPILATION)
9 #error "Only <flutter_linux/flutter_linux.h> can be included directly."
10 #endif
11 
12 #include <glib-object.h>
13 
14 #include "fl_method_response.h"
15 #include "fl_value.h"
16 
17 G_BEGIN_DECLS
18 
19 G_DECLARE_DERIVABLE_TYPE(FlMethodCodec,
20  fl_method_codec,
21  FL,
22  METHOD_CODEC,
23  GObject)
24 
25 /**
26  * FlMethodCodec:
27  *
28  * #FlMethodCodec is an abstract class that encodes and decodes method calls on
29  * a platform channel. Override this class to implement an encoding.
30  *
31  * #FlMethodCodec matches the MethodCodec class in the Flutter services
32  * library.
33  */
34 
35 struct _FlMethodCodecClass {
36  GObjectClass parent_class;
37 
38  /**
39  * FlMethodCodec::encode_method_call:
40  * @codec: an #FlMethodCodec.
41  * @name: method name.
42  * @args: (allow-none): method arguments, or %NULL.
43  * @error: (allow-none): #GError location to store the error occurring, or
44  * %NULL.
45  *
46  * Encodes a method call.
47  *
48  * Returns: (transfer full): a binary encoding of this method call or %NULL if
49  * not able to encode.
50  */
51  GBytes* (*encode_method_call)(FlMethodCodec* codec,
52  const gchar* name,
53  FlValue* args,
54  GError** error);
55 
56  /**
57  * FlMethodCodec::decode_method_call:
58  * @codec: an #FlMethodCodec
59  * @message: message to decode.
60  * @name: (transfer full): location to write method name or %NULL if not
61  * required
62  * @args: (transfer full): location to write method arguments, or %NULL if not
63  * required
64  * @error: (allow-none): #GError location to store the error occurring, or
65  * %NULL
66  *
67  * Decodes a method call.
68  *
69  * Returns: %TRUE if successfully decoded.
70  */
71  gboolean (*decode_method_call)(FlMethodCodec* codec,
72  GBytes* message,
73  gchar** name,
74  FlValue** args,
75  GError** error);
76 
77  /**
78  * FlMethodCodec::encode_success_envelope:
79  * @codec: an #FlMethodCodec.
80  * @result: (allow-none): method result, or %NULL.
81  * @error: (allow-none): #GError location to store the error occurring, or
82  * %NULL.
83  *
84  * Encodes a successful response to a method call.
85  *
86  * Returns: (transfer full): a binary encoding of this response or %NULL if
87  * not able to encode.
88  */
89  GBytes* (*encode_success_envelope)(FlMethodCodec* codec,
90  FlValue* result,
91  GError** error);
92 
93  /**
94  * FlMethodCodec::encode_error_envelope:
95  * @codec: an #FlMethodCodec.
96  * @code: an error code.
97  * @message: (allow-none): an error message, or %NULL.
98  * @details: (allow-none): error details, or %NULL.
99  * @error: (allow-none): #GError location to store the error occurring, or
100  * %NULL.
101  *
102  * Encodes an error response to a method call.
103  *
104  * Returns: (transfer full): a binary encoding of this response or %NULL if
105  * not able to encode.
106  */
107  GBytes* (*encode_error_envelope)(FlMethodCodec* codec,
108  const gchar* code,
109  const gchar* message,
110  FlValue* details,
111  GError** error);
112 
113  /**
114  * FlMethodCodec::decode_response:
115  * @codec: an #FlMethodCodec.
116  * @message: message to decode.
117  * @error: (allow-none): #GError location to store the error occurring, or
118  * %NULL.
119  *
120  * Decodes a response to a method call.
121  *
122  * Returns: a new #FlMethodResponse or %NULL on error.
123  */
124  FlMethodResponse* (*decode_response)(FlMethodCodec* codec,
125  GBytes* message,
126  GError** error);
127 };
128 
129 G_END_DECLS
130 
131 #endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_METHOD_CODEC_H_
G_BEGIN_DECLS FlValue * args
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
FlMethodResponse GError ** error
static void decode_method_call(const char *text, gchar **name, FlValue **args)
G_DECLARE_DERIVABLE_TYPE(FlMessageCodec, fl_message_codec, FL, MESSAGE_CODEC, GObject) struct _FlMessageCodecClass
const char * name
Definition: fuchsia.cc:50
G_BEGIN_DECLS FL