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
54 lines
1.8 KiB
C++
54 lines
1.8 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_METHOD_CODEC_H_
|
|
#define FLUTTER_SHELL_PLATFORM_COMMON_CPP_JSON_METHOD_CODEC_H_
|
|
|
|
#include <rapidjson/document.h>
|
|
|
|
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_call.h"
|
|
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_codec.h"
|
|
|
|
namespace flutter {
|
|
|
|
// An implementation of MethodCodec that uses JSON strings as the serialization.
|
|
class JsonMethodCodec : public MethodCodec<rapidjson::Document> {
|
|
public:
|
|
// Returns the shared instance of the codec.
|
|
static const JsonMethodCodec& GetInstance();
|
|
|
|
~JsonMethodCodec() = default;
|
|
|
|
// Prevent copying.
|
|
JsonMethodCodec(JsonMethodCodec const&) = delete;
|
|
JsonMethodCodec& operator=(JsonMethodCodec const&) = delete;
|
|
|
|
protected:
|
|
// Instances should be obtained via GetInstance.
|
|
JsonMethodCodec() = default;
|
|
|
|
// |flutter::MethodCodec|
|
|
std::unique_ptr<MethodCall<rapidjson::Document>> DecodeMethodCallInternal(
|
|
const uint8_t* message,
|
|
const size_t message_size) const override;
|
|
|
|
// |flutter::MethodCodec|
|
|
std::unique_ptr<std::vector<uint8_t>> EncodeMethodCallInternal(
|
|
const MethodCall<rapidjson::Document>& method_call) const override;
|
|
|
|
// |flutter::MethodCodec|
|
|
std::unique_ptr<std::vector<uint8_t>> EncodeSuccessEnvelopeInternal(
|
|
const rapidjson::Document* result) const override;
|
|
|
|
// |flutter::MethodCodec|
|
|
std::unique_ptr<std::vector<uint8_t>> EncodeErrorEnvelopeInternal(
|
|
const std::string& error_code,
|
|
const std::string& error_message,
|
|
const rapidjson::Document* error_details) const override;
|
|
};
|
|
|
|
} // namespace flutter
|
|
|
|
#endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_JSON_METHOD_CODEC_H_
|