27 fl_standard_method_codec,
28 fl_method_codec_get_type())
30 static
void fl_standard_method_codec_set_property(GObject*
object,
34 FlStandardMethodCodec*
self = FL_STANDARD_METHOD_CODEC(
object);
38 g_set_object(&self->message_codec,
39 FL_STANDARD_MESSAGE_CODEC(g_value_get_object(
value)));
42 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object,
prop_id,
pspec);
51 FlStandardMethodCodec*
self = FL_STANDARD_METHOD_CODEC(
object);
55 g_value_set_object(
value, self->message_codec);
58 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object,
prop_id,
pspec);
64 FlStandardMethodCodec*
self = FL_STANDARD_METHOD_CODEC(
object);
66 g_clear_object(&self->message_codec);
68 G_OBJECT_CLASS(fl_standard_method_codec_parent_class)->dispose(
object);
76 FlStandardMethodCodec*
self = FL_STANDARD_METHOD_CODEC(codec);
78 g_autoptr(GByteArray)
buffer = g_byte_array_new();
89 return g_byte_array_free_to_bytes(
90 static_cast<GByteArray*
>(g_steal_pointer(&
buffer)));
100 FlStandardMethodCodec*
self = FL_STANDARD_METHOD_CODEC(codec);
104 self->message_codec, message, &offset,
error);
105 if (name_value ==
nullptr) {
110 "Method call name wrong type");
115 self->message_codec, message, &offset,
error);
116 if (args_value ==
nullptr) {
120 if (offset != g_bytes_get_size(message)) {
122 "Unexpected extra data");
134 FlMethodCodec* codec,
137 FlStandardMethodCodec*
self = FL_STANDARD_METHOD_CODEC(codec);
139 g_autoptr(GByteArray)
buffer = g_byte_array_new();
147 return g_byte_array_free_to_bytes(
148 static_cast<GByteArray*
>(g_steal_pointer(&
buffer)));
153 FlMethodCodec* codec,
155 const gchar* message,
158 FlStandardMethodCodec*
self = FL_STANDARD_METHOD_CODEC(codec);
160 g_autoptr(GByteArray)
buffer = g_byte_array_new();
165 code_value,
error)) {
168 g_autoptr(
FlValue) message_value =
171 message_value,
error)) {
179 return g_byte_array_free_to_bytes(
180 static_cast<GByteArray*
>(g_steal_pointer(&
buffer)));
185 FlMethodCodec* codec,
188 FlStandardMethodCodec*
self = FL_STANDARD_METHOD_CODEC(codec);
190 if (g_bytes_get_size(message) == 0) {
198 static_cast<const guint8*
>(g_bytes_get_data(message,
nullptr));
199 guint8
type = data[0];
202 g_autoptr(FlMethodResponse) response =
nullptr;
205 self->message_codec, message, &offset,
error);
206 if (code ==
nullptr) {
211 "Error code wrong type");
216 self->message_codec, message, &offset,
error);
217 if (error_message ==
nullptr) {
223 "Error message wrong type");
228 self->message_codec, message, &offset,
error);
229 if (details ==
nullptr) {
241 self->message_codec, message, &offset,
error);
250 "Unknown envelope type %02x",
type);
254 if (offset != g_bytes_get_size(message)) {
256 "Unexpected extra data");
260 return FL_METHOD_RESPONSE(g_object_ref(response));
264 FlStandardMethodCodecClass* klass) {
265 G_OBJECT_CLASS(klass)->set_property = fl_standard_method_codec_set_property;
269 FL_METHOD_CODEC_CLASS(klass)->encode_method_call =
271 FL_METHOD_CODEC_CLASS(klass)->decode_method_call =
273 FL_METHOD_CODEC_CLASS(klass)->encode_success_envelope =
275 FL_METHOD_CODEC_CLASS(klass)->encode_error_envelope =
277 FL_METHOD_CODEC_CLASS(klass)->decode_response =
280 g_object_class_install_property(
283 "message-codec",
"message-codec",
"Message codec to use",
284 fl_message_codec_get_type(),
285 static_cast<GParamFlags
>(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
286 G_PARAM_STATIC_STRINGS)));
292 g_autoptr(FlStandardMessageCodec) message_codec =
297 G_MODULE_EXPORT FlStandardMethodCodec*
299 FlStandardMessageCodec* message_codec) {
300 return FL_STANDARD_METHOD_CODEC(
301 g_object_new(fl_standard_method_codec_get_type(),
"message-codec",
302 message_codec,
nullptr));