Flutter Linux Embedder
fl_string_codec.cc
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 
6 
7 #include <gmodule.h>
8 
9 #include <cstring>
10 
11 G_DEFINE_QUARK(fl_string_codec_error_quark, fl_string_codec_error)
12 
14  FlMessageCodec parent_instance;
15 };
16 
17 G_DEFINE_TYPE(FlStringCodec, fl_string_codec, fl_message_codec_get_type())
18 
19 // Implements FlMessageCodec::encode_message.
20 static GBytes* fl_string_codec_encode_message(FlMessageCodec* codec,
21  FlValue* value,
22  GError** error) {
24  g_set_error(error, FL_MESSAGE_CODEC_ERROR,
26  "Only string values supported");
27  return nullptr;
28  }
29 
30  const gchar* text = fl_value_get_string(value);
31  return g_bytes_new(text, strlen(text));
32 }
33 
34 // Implements FlMessageCodec::decode_message.
35 static FlValue* fl_string_codec_decode_message(FlMessageCodec* codec,
36  GBytes* message,
37  GError** error) {
38  gsize data_length;
39  const gchar* data =
40  static_cast<const gchar*>(g_bytes_get_data(message, &data_length));
41  return fl_value_new_string_sized(data, data_length);
42 }
43 
44 static void fl_string_codec_class_init(FlStringCodecClass* klass) {
45  FL_MESSAGE_CODEC_CLASS(klass)->encode_message =
47  FL_MESSAGE_CODEC_CLASS(klass)->decode_message =
49 }
50 
51 static void fl_string_codec_init(FlStringCodec* self) {}
52 
53 G_MODULE_EXPORT FlStringCodec* fl_string_codec_new() {
54  return static_cast<FlStringCodec*>(
55  g_object_new(fl_string_codec_get_type(), nullptr));
56 }
_FlStringCodec::parent_instance
FlMessageCodec parent_instance
Definition: fl_string_codec.cc:14
fl_value_new_string_sized
G_MODULE_EXPORT FlValue * fl_value_new_string_sized(const gchar *value, size_t value_length)
Definition: fl_value.cc:283
fl_string_codec.h
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
fl_value_get_string
const G_MODULE_EXPORT gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
fl_string_codec_class_init
static void fl_string_codec_class_init(FlStringCodecClass *klass)
Definition: fl_string_codec.cc:44
fl_string_codec_encode_message
static GBytes * fl_string_codec_encode_message(FlMessageCodec *codec, FlValue *value, GError **error)
Definition: fl_string_codec.cc:20
G_DEFINE_QUARK
G_DEFINE_QUARK(fl_binary_messenger_codec_error_quark, fl_binary_messenger_codec_error) G_DECLARE_FINAL_TYPE(FlBinaryMessengerImpl
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
FL_VALUE_TYPE_STRING
@ FL_VALUE_TYPE_STRING
Definition: fl_value.h:69
fl_string_codec_init
static void fl_string_codec_init(FlStringCodec *self)
Definition: fl_string_codec.cc:51
G_DEFINE_TYPE
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
Definition: fl_basic_message_channel.cc:37
_FlStringCodec
Definition: fl_string_codec.cc:13
fl_string_codec_decode_message
static FlValue * fl_string_codec_decode_message(FlMessageCodec *codec, GBytes *message, GError **error)
Definition: fl_string_codec.cc:35
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_string_codec_new
G_MODULE_EXPORT FlStringCodec * fl_string_codec_new()
Definition: fl_string_codec.cc:53
FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE
@ FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE
Definition: fl_message_codec.h:37
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
FL_MESSAGE_CODEC_ERROR
#define FL_MESSAGE_CODEC_ERROR
Definition: fl_message_codec.h:30