Skip to content

Commit

Permalink
Implement StringSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-kim committed Jun 25, 2021
1 parent 8523980 commit bfc4d30
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions shell/platform/tizen/channels/lifecycle_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

#include "lifecycle_channel.h"

#include <variant>

#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_message_codec.h"
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
#include "flutter/shell/platform/tizen/tizen_log.h"

namespace flutter {
Expand All @@ -19,13 +20,38 @@ constexpr char kResumed[] = "AppLifecycleState.resumed";
constexpr char kPaused[] = "AppLifecycleState.paused";
constexpr char kDetached[] = "AppLifecycleState.detached";

// Codec extension for UTF-8 strings.
class StringSerializer : public StandardCodecSerializer {
public:
StringSerializer() = default;
virtual ~StringSerializer() = default;

// Returns the shared serializer instance.
static const StringSerializer& GetInstance() {
static StringSerializer sInstance;
return sInstance;
}

virtual void WriteValue(const EncodableValue& value,
ByteStreamWriter* stream) const override {
if (auto string_value = std::get_if<std::string>(&value)) {
size_t size = string_value->size();
if (size > 0) {
stream->WriteBytes(
reinterpret_cast<const uint8_t*>(string_value->data()), size);
}
}
}
};

} // namespace

LifecycleChannel::LifecycleChannel(BinaryMessenger* messenger)
: channel_(std::make_unique<BasicMessageChannel<EncodableValue>>(
messenger,
kChannelName,
&StandardMessageCodec::GetInstance())) {}
&StandardMessageCodec::GetInstance(
&StringSerializer::GetInstance()))) {}

LifecycleChannel::~LifecycleChannel() {}

Expand Down

0 comments on commit bfc4d30

Please sign in to comment.