mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
The JSON codec is awkward to use in the wrapper (since the client has to build and link one of the JSON libraries to do so). Since it would be very cumbersome to wrap in a C API, and there's essentially no reason to use it instead of the standard codec, this removes it from the wrapper entirely. Since some system channels (internal to the engine) still use it, it's moved into common/cpp instead of being eliminated entirely. Internally we always use RapidJSON though, so the jsoncpp implementation is removed. Also adds some unit test coverage, since there wasn't any. Fixes #30669
44 lines
1.4 KiB
C++
44 lines
1.4 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.
|
|
|
|
#ifndef FLUTTER_SHELL_PLATFORM_COMMON_CPP_JSON_MESSAGE_CODEC_H_
|
|
#define FLUTTER_SHELL_PLATFORM_COMMON_CPP_JSON_MESSAGE_CODEC_H_
|
|
|
|
#include <rapidjson/document.h>
|
|
|
|
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/message_codec.h"
|
|
|
|
namespace flutter {
|
|
|
|
// A message encoding/decoding mechanism for communications to/from the
|
|
// Flutter engine via JSON channels.
|
|
class JsonMessageCodec : public MessageCodec<rapidjson::Document> {
|
|
public:
|
|
// Returns the shared instance of the codec.
|
|
static const JsonMessageCodec& GetInstance();
|
|
|
|
~JsonMessageCodec() = default;
|
|
|
|
// Prevent copying.
|
|
JsonMessageCodec(JsonMessageCodec const&) = delete;
|
|
JsonMessageCodec& operator=(JsonMessageCodec const&) = delete;
|
|
|
|
protected:
|
|
// Instances should be obtained via GetInstance.
|
|
JsonMessageCodec() = default;
|
|
|
|
// |flutter::MessageCodec|
|
|
std::unique_ptr<rapidjson::Document> DecodeMessageInternal(
|
|
const uint8_t* binary_message,
|
|
const size_t message_size) const override;
|
|
|
|
// |flutter::MessageCodec|
|
|
std::unique_ptr<std::vector<uint8_t>> EncodeMessageInternal(
|
|
const rapidjson::Document& message) const override;
|
|
};
|
|
|
|
} // namespace flutter
|
|
|
|
#endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_JSON_MESSAGE_CODEC_H_
|