| Flutter Linux Embedder |

fl_standard_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_PUBLIC_FLUTTER_LINUX_FL_STANDARD_MESSAGE_CODEC_H_
6 #define FLUTTER_SHELL_PLATFORM_LINUX_PUBLIC_FLUTTER_LINUX_FL_STANDARD_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 <gmodule.h>
13
14 #include "fl_message_codec.h"
15
16 G_BEGIN_DECLS
17
18 G_MODULE_EXPORT
19 G_DECLARE_DERIVABLE_TYPE(FlStandardMessageCodec,
20 fl_standard_message_codec,
21 FL,
22 STANDARD_MESSAGE_CODEC,
23 FlMessageCodec)
24
25 /**
26 * FlStandardMessageCodec:
27 *
28 * #FlStandardMessageCodec is an #FlMessageCodec that implements the Flutter
29 * standard message encoding. This codec encodes and decodes #FlValue of type
30 * #FL_VALUE_TYPE_NULL, #FL_VALUE_TYPE_BOOL, #FL_VALUE_TYPE_INT,
31 * #FL_VALUE_TYPE_FLOAT, #FL_VALUE_TYPE_STRING, #FL_VALUE_TYPE_UINT8_LIST,
32 * #FL_VALUE_TYPE_INT32_LIST, #FL_VALUE_TYPE_INT64_LIST,
33 * #FL_VALUE_TYPE_FLOAT_LIST, #FL_VALUE_TYPE_LIST, and #FL_VALUE_TYPE_MAP.
34 *
35 * If other values types are required to be supported create a new subclass that
36 * overrides write_value and read_value_of_type.
37 *
38 * #FlStandardMessageCodec matches the StandardCodec class in the Flutter
39 * services library.
40 */
41
42 struct _FlStandardMessageCodecClass {
43 FlMessageCodecClass parent_class;
44
45 /**
46 * FlStandardMessageCodec::write_value:
47 * @codec: an #FlStandardMessageCodec.
48 * @buffer: a buffer to write into.
49 * @value: (allow-none): value to write.
50 * @error: (allow-none): #GError location to store the error occurring, or
51 * %NULL. If `error` is not %NULL, `*error` must be initialized (typically
52 * %NULL, but an error from a previous call using GLib error handling is
53 * explicitly valid).
54 *
55 * Virtual method to write an #FlValue in Flutter Standard encoding.
56 *
57 * If a codec needs to support custom #FlValue objects it must override this
58 * method to encode those values. For non-custom values the parent method
59 * should be called.
60 *
61 * Returns: %TRUE on success.
62 */
63 gboolean (*write_value)(FlStandardMessageCodec* codec,
64 GByteArray* buffer,
65 FlValue* value,
66 GError** error);
67
68 /**
69 * FlStandardMessageCodec::read_value_of_type:
70 * @codec: an #FlStandardMessageCodec.
71 * @buffer: buffer to read from.
72 * @offset: (inout): read position in @buffer.
73 * @type: the type of the value.
74 * @error: (allow-none): #GError location to store the error occurring, or
75 * %NULL. If `error` is not %NULL, `*error` must be initialized (typically
76 * %NULL, but an error from a previous call using GLib error handling is
77 * explicitly valid).
78 *
79 * Virtual method to read an #FlValue in Flutter Standard encoding.
80 *
81 * If a codec needs to support custom #FlValue objects it must override this
82 * method to decode those values. For non-custom values the parent method
83 * should be called.
84 *
85 * Returns: an #FlValue or %NULL on error.
86 */
87 FlValue* (*read_value_of_type)(FlStandardMessageCodec* codec,
88 GBytes* buffer,
89 size_t* offset,
90 int type,
91 GError** error);
92 };
93
94 /*
95 * fl_standard_message_codec_new:
96 *
97 * Creates an #FlStandardMessageCodec.
98 *
99 * Returns: a new #FlStandardMessageCodec.
100 */
101 FlStandardMessageCodec* fl_standard_message_codec_new();
102
103 /**
104 * fl_standard_message_codec_write_size:
105 * @codec: an #FlStandardMessageCodec.
106 * @buffer: buffer to write into.
107 * @size: size value to write.
108 *
109 * Writes a size field in Flutter Standard encoding.
110 */
111 void fl_standard_message_codec_write_size(FlStandardMessageCodec* codec,
112 GByteArray* buffer,
113 uint32_t size);
114
115 /**
116 * fl_standard_message_codec_read_size:
117 * @codec: an #FlStandardMessageCodec.
118 * @buffer: buffer to read from.
119 * @offset: (inout): read position in @buffer.
120 * @value: location to read size.
121 * @error: (allow-none): #GError location to store the error occurring, or
122 * %NULL. If `error` is not %NULL, `*error` must be initialized (typically
123 * %NULL, but an error from a previous call using GLib error handling is
124 * explicitly valid).
125 *
126 * Reads a size field in Flutter Standard encoding.
127 *
128 * This method is intended for use by subclasses overriding
129 * FlStandardMessageCodec::read_value_of_type.
130 *
131 * Returns: %TRUE on success.
132 */
133 gboolean fl_standard_message_codec_read_size(FlStandardMessageCodec* codec,
134 GBytes* buffer,
135 size_t* offset,
136 uint32_t* value,
137 GError** error);
138
139 /**
140 * fl_standard_message_codec_write_value:
141 * @codec: an #FlStandardMessageCodec.
142 * @buffer: buffer to write into.
143 * @value: (allow-none): value to write.
144 * @error: (allow-none): #GError location to store the error occurring, or
145 * %NULL. If `error` is not %NULL, `*error` must be initialized (typically
146 * %NULL, but an error from a previous call using GLib error handling is
147 * explicitly valid).
148 *
149 * Writes an #FlValue in Flutter Standard encoding.
150 *
151 * This method is intended for use by subclasses overriding
152 * FlStandardMessageCodec::write_value.
153 *
154 * Returns: %TRUE on success.
155 */
156 gboolean fl_standard_message_codec_write_value(FlStandardMessageCodec* codec,
157 GByteArray* buffer,
158 FlValue* value,
159 GError** error);
160
161 /**
162 * fl_standard_message_codec_read_value:
163 * @codec: an #FlStandardMessageCodec.
164 * @buffer: buffer to read from.
165 * @offset: (inout): read position in @buffer.
166 * @value: location to read size.
167 * @error: (allow-none): #GError location to store the error occurring, or
168 * %NULL. If `error` is not %NULL, `*error` must be initialized (typically
169 * %NULL, but an error from a previous call using GLib error handling is
170 * explicitly valid).
171 *
172 * Reads an #FlValue in Flutter Standard encoding.
173 *
174 * This method is intended for use by subclasses overriding
175 * FlStandardMessageCodec::read_value_of_type.
176 *
177 * Returns: a new #FlValue or %NULL on error.
178 */
179 FlValue* fl_standard_message_codec_read_value(FlStandardMessageCodec* codec,
180 GBytes* buffer,
181 size_t* offset,
182 GError** error);
183
184 G_END_DECLS
185
186 #endif // FLUTTER_SHELL_PLATFORM_LINUX_PUBLIC_FLUTTER_LINUX_FL_STANDARD_MESSAGE_CODEC_H_
FL
FL
Definition: fl_binary_messenger.cc:27
fl_message_codec.h
buffer
static const uint8_t buffer[]
Definition: fl_pixel_buffer_texture_test.cc:44
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
fl_standard_message_codec_write_value
gboolean fl_standard_message_codec_write_value(FlStandardMessageCodec *codec, GByteArray *buffer, FlValue *value, GError **error)
Definition: fl_standard_message_codec.cc:686
G_DECLARE_DERIVABLE_TYPE
G_BEGIN_DECLS G_MODULE_EXPORT G_DECLARE_DERIVABLE_TYPE(FlStandardMessageCodec, fl_standard_message_codec, FL, STANDARD_MESSAGE_CODEC, FlMessageCodec) struct _FlStandardMessageCodecClass
Definition: fl_standard_message_codec.h:19
fl_standard_message_codec_write_size
void fl_standard_message_codec_write_size(FlStandardMessageCodec *codec, GByteArray *buffer, uint32_t size)
Definition: fl_standard_message_codec.cc:642
fl_standard_message_codec_read_value
FlValue * fl_standard_message_codec_read_value(FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, GError **error)
Definition: fl_standard_message_codec.cc:694
fl_standard_message_codec_new
FlStandardMessageCodec * fl_standard_message_codec_new()
Definition: fl_standard_message_codec.cc:637
fl_standard_message_codec_read_size
gboolean fl_standard_message_codec_read_size(FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, uint32_t *value, GError **error)
Definition: fl_standard_message_codec.cc:658
type
uint8_t type
Definition: fl_standard_message_codec_test.cc:1117
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42