mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Cleans up header order/grouping for consistency: associated header, C/C++ system/standard library headers, library headers, platform-specific #includes. Adds <cstring> where strlen, memcpy are being used: there are a bunch of places we use them transitively. Applies linter-required cleanups. Disables linter on one file due to included RapidJson header. See https://github.com/flutter/flutter/issues/65676 This patch does not cover flutter/shell/platform/darwin. There's a separate, slightly more intensive cleanup for those in progress.
57 lines
1.9 KiB
C++
57 lines
1.9 KiB
C++
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "flutter/shell/platform/linux/public/flutter_linux/fl_string_codec.h"
|
|
|
|
#include <gmodule.h>
|
|
|
|
#include <cstring>
|
|
|
|
G_DEFINE_QUARK(fl_string_codec_error_quark, fl_string_codec_error)
|
|
|
|
struct _FlStringCodec {
|
|
FlMessageCodec parent_instance;
|
|
};
|
|
|
|
G_DEFINE_TYPE(FlStringCodec, fl_string_codec, fl_message_codec_get_type())
|
|
|
|
// Implements FlMessageCodec::encode_message.
|
|
static GBytes* fl_string_codec_encode_message(FlMessageCodec* codec,
|
|
FlValue* value,
|
|
GError** error) {
|
|
if (fl_value_get_type(value) != FL_VALUE_TYPE_STRING) {
|
|
g_set_error(error, FL_MESSAGE_CODEC_ERROR,
|
|
FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE,
|
|
"Only string values supported");
|
|
return nullptr;
|
|
}
|
|
|
|
const gchar* text = fl_value_get_string(value);
|
|
return g_bytes_new(text, strlen(text));
|
|
}
|
|
|
|
// Implements FlMessageCodec::decode_message.
|
|
static FlValue* fl_string_codec_decode_message(FlMessageCodec* codec,
|
|
GBytes* message,
|
|
GError** error) {
|
|
gsize data_length;
|
|
const gchar* data =
|
|
static_cast<const gchar*>(g_bytes_get_data(message, &data_length));
|
|
return fl_value_new_string_sized(data, data_length);
|
|
}
|
|
|
|
static void fl_string_codec_class_init(FlStringCodecClass* klass) {
|
|
FL_MESSAGE_CODEC_CLASS(klass)->encode_message =
|
|
fl_string_codec_encode_message;
|
|
FL_MESSAGE_CODEC_CLASS(klass)->decode_message =
|
|
fl_string_codec_decode_message;
|
|
}
|
|
|
|
static void fl_string_codec_init(FlStringCodec* self) {}
|
|
|
|
G_MODULE_EXPORT FlStringCodec* fl_string_codec_new() {
|
|
return static_cast<FlStringCodec*>(
|
|
g_object_new(fl_string_codec_get_type(), nullptr));
|
|
}
|