Flutter Engine
json_method_codec.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_COMMON_CPP_JSON_METHOD_CODEC_H_
6 #define FLUTTER_SHELL_PLATFORM_COMMON_CPP_JSON_METHOD_CODEC_H_
7 
8 #include <rapidjson/document.h>
9 
10 #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_call.h"
11 #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_codec.h"
12 
13 namespace flutter {
14 
15 // An implementation of MethodCodec that uses JSON strings as the serialization.
16 class JsonMethodCodec : public MethodCodec<rapidjson::Document> {
17  public:
18  // Returns the shared instance of the codec.
19  static const JsonMethodCodec& GetInstance();
20 
21  ~JsonMethodCodec() = default;
22 
23  // Prevent copying.
24  JsonMethodCodec(JsonMethodCodec const&) = delete;
25  JsonMethodCodec& operator=(JsonMethodCodec const&) = delete;
26 
27  protected:
28  // Instances should be obtained via GetInstance.
29  JsonMethodCodec() = default;
30 
31  // |flutter::MethodCodec|
32  std::unique_ptr<MethodCall<rapidjson::Document>> DecodeMethodCallInternal(
33  const uint8_t* message,
34  const size_t message_size) const override;
35 
36  // |flutter::MethodCodec|
37  std::unique_ptr<std::vector<uint8_t>> EncodeMethodCallInternal(
38  const MethodCall<rapidjson::Document>& method_call) const override;
39 
40  // |flutter::MethodCodec|
41  std::unique_ptr<std::vector<uint8_t>> EncodeSuccessEnvelopeInternal(
42  const rapidjson::Document* result) const override;
43 
44  // |flutter::MethodCodec|
45  std::unique_ptr<std::vector<uint8_t>> EncodeErrorEnvelopeInternal(
46  const std::string& error_code,
47  const std::string& error_message,
48  const rapidjson::Document* error_details) const override;
49 
50  // |flutter::MethodCodec|
52  const uint8_t* response,
53  const size_t response_size,
54  MethodResult<rapidjson::Document>* result) const override;
55 };
56 
57 } // namespace flutter
58 
59 #endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_JSON_METHOD_CODEC_H_
G_BEGIN_DECLS FlMethodCall * method_call
std::unique_ptr< MethodCall< rapidjson::Document > > DecodeMethodCallInternal(const uint8_t *message, const size_t message_size) const override
static const JsonMethodCodec & GetInstance()
JsonMethodCodec & operator=(JsonMethodCodec const &)=delete
std::unique_ptr< std::vector< uint8_t > > EncodeSuccessEnvelopeInternal(const rapidjson::Document *result) const override
bool DecodeAndProcessResponseEnvelopeInternal(const uint8_t *response, const size_t response_size, MethodResult< rapidjson::Document > *result) const override
std::unique_ptr< std::vector< uint8_t > > EncodeMethodCallInternal(const MethodCall< rapidjson::Document > &method_call) const override
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