Flutter Engine
The 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
11G_DEFINE_QUARK(fl_string_codec_error_quark, fl_string_codec_error)
12
14 FlMessageCodec parent_instance;
15};
16
17G_DEFINE_TYPE(FlStringCodec, fl_string_codec, fl_message_codec_get_type())
18
19// Implements FlMessageCodec::encode_message.
20static GBytes* fl_string_codec_encode_message(FlMessageCodec* codec,
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.
35static 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
44static 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
51static void fl_string_codec_init(FlStringCodec* self) {}
52
53G_MODULE_EXPORT FlStringCodec* fl_string_codec_new() {
54 return static_cast<FlStringCodec*>(
55 g_object_new(fl_string_codec_get_type(), nullptr));
56}
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_DEFINE_QUARK(fl_binary_messenger_codec_error_quark, fl_binary_messenger_codec_error) G_DECLARE_FINAL_TYPE(FlBinaryMessengerImpl
@ FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE
#define FL_MESSAGE_CODEC_ERROR
const uint8_t uint32_t uint32_t GError ** error
uint8_t value
static void fl_string_codec_init(FlStringCodec *self)
static GBytes * fl_string_codec_encode_message(FlMessageCodec *codec, FlValue *value, GError **error)
static void fl_string_codec_class_init(FlStringCodecClass *klass)
G_MODULE_EXPORT FlStringCodec * fl_string_codec_new()
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:466
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
G_MODULE_EXPORT FlValue * fl_value_new_string_sized(const gchar *value, size_t value_length)
Definition: fl_value.cc:283
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
@ FL_VALUE_TYPE_STRING
Definition: fl_value.h:69
std::u16string text
Win32Message message
FlMessageCodec parent_instance
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63