Flutter Engine
fl_message_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_MESSAGE_CODEC_H_
6 #define FLUTTER_SHELL_PLATFORM_LINUX_FL_MESSAGE_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_value.h"
15 
16 G_BEGIN_DECLS
17 
18 /**
19  * FlMessageCodecError:
20  * @FL_MESSAGE_CODEC_ERROR_FAILED: Codec failed due to an unspecified error.
21  * @FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA: Codec ran out of data reading a value.
22  * @FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA: Additional data encountered in
23  * message.
24  * @FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE: Codec encountered an unsupported
25  * #FlValue.
26  *
27  * Errors for #FlMessageCodec objects to set on failures.
28  */
29 #define FL_MESSAGE_CODEC_ERROR fl_message_codec_error_quark()
30 
31 typedef enum {
37 
38 GQuark fl_message_codec_error_quark(void) G_GNUC_CONST;
39 
40 G_DECLARE_DERIVABLE_TYPE(FlMessageCodec,
41  fl_message_codec,
42  FL,
43  MESSAGE_CODEC,
44  GObject)
45 
46 /**
47  * FlMessageCodec:
48  *
49  * #FlMessageCodec is a message encoding/decoding mechanism that operates on
50  * #FlValue objects. Both operations returns errors if the conversion fails.
51  * Such situations should be treated as programming errors.
52  *
53  * #FlMessageCodec matches the MethodCodec class in the Flutter services
54  * library.
55  */
56 
57 struct _FlMessageCodecClass {
58  GObjectClass parent_class;
59 
60  /**
61  * FlMessageCodec::encode_message:
62  * @codec: A #FlMessageCodec.
63  * @message: message to encode or %NULL to encode the null value.
64  * @error: (allow-none): #GError location to store the error occurring, or
65  * %NULL.
66  *
67  * Virtual method to encode a message. A subclass must implement this method.
68  * If the subclass cannot handle the type of @message then it must generate a
69  * FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE error.
70  *
71  * Returns: a binary message or %NULL on error.
72  */
73  GBytes* (*encode_message)(FlMessageCodec* codec,
74  FlValue* message,
75  GError** error);
76 
77  /**
78  * FlMessageCodec::decode_message:
79  * @codec: an #FlMessageCodec.
80  * @message: binary message to decode.
81  * @error: (allow-none): #GError location to store the error occurring, or
82  * %NULL.
83  *
84  * Virtual method to decode a message. A subclass must implement this method.
85  * If @message is too small then a #FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA error
86  * must be generated. If @message is too large then a
87  * #FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA error must be generated.
88  *
89  * Returns: an #FlValue or %NULL on error.
90  */
91  FlValue* (*decode_message)(FlMessageCodec* codec,
92  GBytes* message,
93  GError** error);
94 };
95 
96 /**
97  * fl_message_codec_encode_message:
98  * @codec: an #FlMessageCodec.
99  * @buffer: buffer to write to.
100  * @message: message to encode or %NULL to encode the null value.
101  * @error: (allow-none): #GError location to store the error occurring, or
102  * %NULL.
103  *
104  * Encodes a message into a binary representation.
105  *
106  * Returns: a binary encoded message or %NULL on error.
107  */
108 GBytes* fl_message_codec_encode_message(FlMessageCodec* codec,
109  FlValue* message,
110  GError** error);
111 
112 /**
113  * fl_message_codec_decode_message:
114  * @codec: an #FlMessageCodec.
115  * @message: binary message to decode.
116  * @error: (allow-none): #GError location to store the error occurring, or
117  * %NULL.
118  *
119  * Decodes a message from a binary encoding.
120  *
121  * Returns: an #FlValue or %NULL on error.
122  */
123 FlValue* fl_message_codec_decode_message(FlMessageCodec* codec,
124  GBytes* message,
125  GError** error);
126 
127 G_END_DECLS
128 
129 #endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_MESSAGE_CODEC_H_
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
GBytes * fl_message_codec_encode_message(FlMessageCodec *codec, FlValue *message, GError **error)
FlMethodResponse GError ** error
FlMessageCodecError
G_DECLARE_DERIVABLE_TYPE(FlMessageCodec, fl_message_codec, FL, MESSAGE_CODEC, GObject) struct _FlMessageCodecClass
GQuark fl_message_codec_error_quark(void) G_GNUC_CONST
G_BEGIN_DECLS FL
FlValue * fl_message_codec_decode_message(FlMessageCodec *codec, GBytes *message, GError **error)