| 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
5 #include "flutter/shell/platform/linux/public/flutter_linux/fl_string_codec.h"
6
7 #include <gmodule.h>
8
9 #include <cstring>
10
11 G_DEFINE_QUARK(fl_string_codec_error_quark, fl_string_codec_error)
12
13 struct _FlStringCodec {
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) {
23 if (fl_value_get_type(value) != FL_VALUE_TYPE_STRING) {
24 g_set_error(error, FL_MESSAGE_CODEC_ERROR,
25 FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE,
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 =
46 fl_string_codec_encode_message;
47 FL_MESSAGE_CODEC_CLASS(klass)->decode_message =
48 fl_string_codec_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 }
message
const char * message
Definition: fl_accessibility_handler.cc:21
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
G_DEFINE_QUARK
G_DEFINE_QUARK(fl_binary_messenger_codec_error_quark, fl_binary_messenger_codec_error) G_DECLARE_FINAL_TYPE(FlBinaryMessengerImpl
FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE
@ FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE
Definition: fl_message_codec.h:36
FL_MESSAGE_CODEC_ERROR
#define FL_MESSAGE_CODEC_ERROR
Definition: fl_message_codec.h:30
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_string_codec_init
static void fl_string_codec_init(FlStringCodec *self)
Definition: fl_string_codec.cc:51
fl_string_codec_new
G_MODULE_EXPORT FlStringCodec * fl_string_codec_new()
Definition: fl_string_codec.cc:53
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
fl_string_codec_decode_message
static FlValue * fl_string_codec_decode_message(FlMessageCodec *codec, GBytes *message, GError **error)
Definition: fl_string_codec.cc:35
fl_string_codec.h
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
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_value_get_string
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
FL_VALUE_TYPE_STRING
@ FL_VALUE_TYPE_STRING
Definition: fl_value.h:68
_FlStringCodec
Definition: fl_string_codec.cc:13
_FlStringCodec::parent_instance
FlMessageCodec parent_instance
Definition: fl_string_codec.cc:14