Flutter Linux Embedder
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_JSON_METHOD_CODEC_H_
6 #define FLUTTER_SHELL_PLATFORM_COMMON_JSON_METHOD_CODEC_H_
7 
8 #include <rapidjson/document.h>
9 
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,
55 };
56 
57 } // namespace flutter
58 
59 #endif // FLUTTER_SHELL_PLATFORM_COMMON_JSON_METHOD_CODEC_H_
flutter::JsonMethodCodec::DecodeMethodCallInternal
std::unique_ptr< MethodCall< rapidjson::Document > > DecodeMethodCallInternal(const uint8_t *message, const size_t message_size) const override
Definition: json_method_codec.cc:42
flutter::JsonMethodCodec
Definition: json_method_codec.h:16
method_codec.h
flutter::JsonMethodCodec::EncodeSuccessEnvelopeInternal
std::unique_ptr< std::vector< uint8_t > > EncodeSuccessEnvelopeInternal(const rapidjson::Document *result) const override
Definition: json_method_codec.cc:86
flutter::JsonMethodCodec::operator=
JsonMethodCodec & operator=(JsonMethodCodec const &)=delete
flutter::JsonMethodCodec::GetInstance
static const JsonMethodCodec & GetInstance()
Definition: json_method_codec.cc:36
flutter::MethodCall
Definition: method_call.h:18
flutter::JsonMethodCodec::DecodeAndProcessResponseEnvelopeInternal
bool DecodeAndProcessResponseEnvelopeInternal(const uint8_t *response, const size_t response_size, MethodResult< rapidjson::Document > *result) const override
Definition: json_method_codec.cc:118
method_call
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall * method_call
Definition: fl_method_channel.h:120
flutter::JsonMethodCodec::EncodeMethodCallInternal
std::unique_ptr< std::vector< uint8_t > > EncodeMethodCallInternal(const MethodCall< rapidjson::Document > &method_call) const override
Definition: json_method_codec.cc:67
flutter
Definition: accessibility_bridge.cc:14
flutter::JsonMethodCodec::~JsonMethodCodec
~JsonMethodCodec()=default
result
GAsyncResult * result
Definition: fl_text_input_handler.cc:106
flutter::MethodResult
Definition: method_result.h:17
flutter::MethodCodec
Definition: method_codec.h:20
flutter::JsonMethodCodec::EncodeErrorEnvelopeInternal
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
Definition: json_method_codec.cc:100
flutter::JsonMethodCodec::JsonMethodCodec
JsonMethodCodec()=default
method_call.h