• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CLIENT_WRAPPER_INCLUDE_FLUTTER_JSON_METHOD_CODEC_H_
6 #define FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_JSON_METHOD_CODEC_H_
7 
8 #include "json_type.h"
9 #include "method_call.h"
10 #include "method_codec.h"
11 
12 namespace flutter {
13 
14 // An implementation of MethodCodec that uses JSON strings as the serialization.
15 class JsonMethodCodec : public MethodCodec<JsonValueType> {
16  public:
17   // Returns the shared instance of the codec.
18   static const JsonMethodCodec& GetInstance();
19 
20   ~JsonMethodCodec() = default;
21 
22   // Prevent copying.
23   JsonMethodCodec(JsonMethodCodec const&) = delete;
24   JsonMethodCodec& operator=(JsonMethodCodec const&) = delete;
25 
26  protected:
27   // Instances should be obtained via GetInstance.
28   JsonMethodCodec() = default;
29 
30   // |flutter::MethodCodec|
31   std::unique_ptr<MethodCall<JsonValueType>> DecodeMethodCallInternal(
32       const uint8_t* message,
33       const size_t message_size) const override;
34 
35   // |flutter::MethodCodec|
36   std::unique_ptr<std::vector<uint8_t>> EncodeMethodCallInternal(
37       const MethodCall<JsonValueType>& method_call) const override;
38 
39   // |flutter::MethodCodec|
40   std::unique_ptr<std::vector<uint8_t>> EncodeSuccessEnvelopeInternal(
41       const JsonValueType* result) const override;
42 
43   // |flutter::MethodCodec|
44   std::unique_ptr<std::vector<uint8_t>> EncodeErrorEnvelopeInternal(
45       const std::string& error_code,
46       const std::string& error_message,
47       const JsonValueType* error_details) const override;
48 };
49 
50 }  // namespace flutter
51 
52 #endif  // FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_JSON_METHOD_CODEC_H_
53