flutter_flutter/shell/platform/linux/fl_string_codec.cc
Damian Wrobel e831433a20
Add missing <cstring> header (#21069)
Fixes the following compilation errors:

../../flutter/shell/platform/linux/fl_value.cc:267:3: error: use of undeclared identifier 'memcpy'
  memcpy(self->values, data, sizeof(uint8_t) * data_length);
  ^
../../flutter/shell/platform/linux/fl_value.cc:284:3: error: use of undeclared identifier 'memcpy'
  memcpy(self->values, data, sizeof(int32_t) * data_length);
  ^
../../flutter/shell/platform/linux/fl_value.cc:294:3: error: use of undeclared identifier 'memcpy'
  memcpy(self->values, data, sizeof(int64_t) * data_length);
  ^
../../flutter/shell/platform/linux/fl_value.cc:304:3: error: use of undeclared identifier 'memcpy'
  memcpy(self->values, data, sizeof(double) * data_length);
  ^

../../flutter/shell/platform/linux/fl_string_codec.cc:29:28: error: use of undeclared identifier 'strlen'
  return g_bytes_new(text, strlen(text));
                           ^

../../flutter/shell/platform/linux/fl_standard_message_codec.cc:512:23: error: use of undeclared identifier 'strlen'
      size_t length = strlen(text);
                      ^

Signed-off-by: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
2020-09-10 09:24:54 -07:00

56 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));
}