Flutter Engine
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 
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 }
static GBytes * fl_string_codec_encode_message(FlMessageCodec *codec, FlValue *value, GError **error)
static FlValue * fl_string_codec_decode_message(FlMessageCodec *codec, GBytes *message, GError **error)
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
FlMethodResponse GError ** error
G_DEFINE_QUARK(fl_binary_messenger_codec_error_quark, fl_binary_messenger_codec_error) struct _FlBinaryMessenger
#define FL_MESSAGE_CODEC_ERROR
G_MODULE_EXPORT FlStringCodec * fl_string_codec_new()
FlMessageCodec parent_instance
uint8_t value
G_MODULE_EXPORT GType fl_message_codec_get_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)
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:596
static void fl_string_codec_class_init(FlStringCodecClass *klass)
G_MODULE_EXPORT FlValue * fl_value_new_string_sized(const gchar *value, size_t value_length)
Definition: fl_value.cc:254
static void fl_string_codec_init(FlStringCodec *self)