| 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.
52 *
53 * Virtual method to write an #FlValue in Flutter Standard encoding.
54 *
55 * If a codec needs to support custom #FlValue objects it must override this
56 * method to encode those values. For non-custom values the parent method
57 * should be called.
58 *
59 * Returns: %TRUE on success.
60 */
61 gboolean (*write_value)(FlStandardMessageCodec* codec,
62 GByteArray* buffer,
63 FlValue* value,
64 GError** error);
65
66 /**
67 * FlStandardMessageCodec::read_value_of_type:
68 * @codec: an #FlStandardMessageCodec.
69 * @buffer: buffer to read from.
70 * @offset: (inout): read position in @buffer.
71 * @type: the type of the value.
72 * @error: (allow-none): #GError location to store the error occurring, or
73 * %NULL.
74 *
75 * Virtual method to read an #FlValue in Flutter Standard encoding.
76 *
77 * If a codec needs to support custom #FlValue objects it must override this
78 * method to decode those values. For non-custom values the parent method
79 * should be called.
80 *
81 * Returns: an #FlValue or %NULL on error.
82 */
83 FlValue* (*read_value_of_type)(FlStandardMessageCodec* codec,
84 GBytes* buffer,
85 size_t* offset,
86 int type,
87 GError** error);
88 };
89
90 /*
91 * fl_standard_message_codec_new:
92 *
93 * Creates an #FlStandardMessageCodec.
94 *
95 * Returns: a new #FlStandardMessageCodec.
96 */
97 FlStandardMessageCodec* fl_standard_message_codec_new();
98
99 /**
100 * fl_standard_message_codec_write_size:
101 * @codec: an #FlStandardMessageCodec.
102 * @buffer: buffer to write into.
103 * @size: size value to write.
104 *
105 * Writes a size field in Flutter Standard encoding.
106 */
107 void fl_standard_message_codec_write_size(FlStandardMessageCodec* codec,
108 GByteArray* buffer,
109 uint32_t size);
110
111 /**
112 * fl_standard_message_codec_read_size:
113 * @codec: an #FlStandardMessageCodec.
114 * @buffer: buffer to read from.
115 * @offset: (inout): read position in @buffer.
116 * @value: location to read size.
117 * @error: (allow-none): #GError location to store the error occurring, or
118 * %NULL.
119 *
120 * Reads a size field in Flutter Standard encoding.
121 *
122 * This method is intended for use by subclasses overriding
123 * FlStandardMessageCodec::read_value_of_type.
124 *
125 * Returns: %TRUE on success.
126 */
127 gboolean fl_standard_message_codec_read_size(FlStandardMessageCodec* codec,
128 GBytes* buffer,
129 size_t* offset,
130 uint32_t* value,
131 GError** error);
132
133 /**
134 * fl_standard_message_codec_write_value:
135 * @codec: an #FlStandardMessageCodec.
136 * @buffer: buffer to write into.
137 * @value: (allow-none): value to write.
138 * @error: (allow-none): #GError location to store the error occurring, or
139 * %NULL.
140 *
141 * Writes an #FlValue in Flutter Standard encoding.
142 *
143 * This method is intended for use by subclasses overriding
144 * FlStandardMessageCodec::write_value.
145 *
146 * Returns: %TRUE on success.
147 */
148 gboolean fl_standard_message_codec_write_value(FlStandardMessageCodec* codec,
149 GByteArray* buffer,
150 FlValue* value,
151 GError** error);
152
153 /**
154 * fl_standard_message_codec_read_value:
155 * @codec: an #FlStandardMessageCodec.
156 * @buffer: buffer to read from.
157 * @offset: (inout): read position in @buffer.
158 * @value: location to read size.
159 * @error: (allow-none): #GError location to store the error occurring, or
160 * %NULL.
161 *
162 * Reads an #FlValue in Flutter Standard encoding.
163 *
164 * This method is intended for use by subclasses overriding
165 * FlStandardMessageCodec::read_value_of_type.
166 *
167 * Returns: a new #FlValue or %NULL on error.
168 */
169 FlValue* fl_standard_message_codec_read_value(FlStandardMessageCodec* codec,
170 GBytes* buffer,
171 size_t* offset,
172 GError** error);
173
174 G_END_DECLS
175
176 #endif // FLUTTER_SHELL_PLATFORM_LINUX_PUBLIC_FLUTTER_LINUX_FL_STANDARD_MESSAGE_CODEC_H_
fl_standard_message_codec_new
FlStandardMessageCodec * fl_standard_message_codec_new()
Definition: fl_standard_message_codec.cc:637
type
uint8_t type
Definition: fl_standard_message_codec_test.cc:1115
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
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:657
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_message_codec.h
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
FL
Definition: fl_binary_messenger.cc:27
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
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
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:685
buffer
static const uint8_t buffer[]
Definition: fl_pixel_buffer_texture_test.cc:44
value
uint8_t value
Definition: fl_standard_message_codec.cc:36