Flutter macOS Embedder
standard_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_CLIENT_WRAPPER_INCLUDE_FLUTTER_STANDARD_METHOD_CODEC_H_
6 #define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_STANDARD_METHOD_CODEC_H_
7 
8 #include <memory>
9 
10 #include "encodable_value.h"
11 #include "method_call.h"
12 #include "method_codec.h"
14 
15 namespace flutter {
16 
17 // An implementation of MethodCodec that uses a binary serialization.
18 class StandardMethodCodec : public MethodCodec<EncodableValue> {
19  public:
20  // Returns an instance of the codec, optionally using a custom serializer to
21  // add support for more types.
22  //
23  // If provided, |serializer| must be long-lived. If no serializer is provided,
24  // the default will be used.
25  //
26  // The instance returned for a given |extension| will be shared, and
27  // any instance returned from this will be long-lived, and can be safely
28  // passed to, e.g., channel constructors.
29  static const StandardMethodCodec& GetInstance(
30  const StandardCodecSerializer* serializer = nullptr);
31 
33 
34  // Prevent copying.
37 
38  protected:
39  // |flutter::MethodCodec|
40  std::unique_ptr<MethodCall<EncodableValue>> DecodeMethodCallInternal(
41  const uint8_t* message,
42  size_t message_size) const override;
43 
44  // |flutter::MethodCodec|
45  std::unique_ptr<std::vector<uint8_t>> EncodeMethodCallInternal(
46  const MethodCall<EncodableValue>& method_call) const override;
47 
48  // |flutter::MethodCodec|
49  std::unique_ptr<std::vector<uint8_t>> EncodeSuccessEnvelopeInternal(
50  const EncodableValue* result) const override;
51 
52  // |flutter::MethodCodec|
53  std::unique_ptr<std::vector<uint8_t>> EncodeErrorEnvelopeInternal(
54  const std::string& error_code,
55  const std::string& error_message,
56  const EncodableValue* error_details) const override;
57 
58  // |flutter::MethodCodec|
60  const uint8_t* response,
61  size_t response_size,
62  MethodResult<EncodableValue>* result) const override;
63 
64  private:
65  // Instances should be obtained via GetInstance.
66  explicit StandardMethodCodec(const StandardCodecSerializer* serializer);
67 
68  const StandardCodecSerializer* serializer_;
69 };
70 
71 } // namespace flutter
72 
73 #endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_STANDARD_METHOD_CODEC_H_
encodable_value.h
method_codec.h
flutter::StandardMethodCodec
Definition: standard_method_codec.h:18
standard_codec_serializer.h
flutter::StandardMethodCodec::StandardMethodCodec
StandardMethodCodec(StandardMethodCodec const &)=delete
flutter::MethodCall
Definition: method_call.h:18
flutter::StandardMethodCodec::~StandardMethodCodec
~StandardMethodCodec()
flutter::StandardMethodCodec::EncodeMethodCallInternal
std::unique_ptr< std::vector< uint8_t > > EncodeMethodCallInternal(const MethodCall< EncodableValue > &method_call) const override
Definition: standard_codec.cc:383
flutter::StandardMethodCodec::DecodeMethodCallInternal
std::unique_ptr< MethodCall< EncodableValue > > DecodeMethodCallInternal(const uint8_t *message, size_t message_size) const override
Definition: standard_codec.cc:366
flutter
Definition: AccessibilityBridgeMac.h:16
flutter::StandardCodecSerializer
Definition: standard_codec_serializer.h:18
flutter::EncodableValue
Definition: encodable_value.h:165
flutter::StandardMethodCodec::DecodeAndProcessResponseEnvelopeInternal
bool DecodeAndProcessResponseEnvelopeInternal(const uint8_t *response, size_t response_size, MethodResult< EncodableValue > *result) const override
Definition: standard_codec.cc:432
flutter::MethodResult< EncodableValue >
flutter::MethodCodec
Definition: method_codec.h:20
flutter::StandardMethodCodec::EncodeErrorEnvelopeInternal
std::unique_ptr< std::vector< uint8_t > > EncodeErrorEnvelopeInternal(const std::string &error_code, const std::string &error_message, const EncodableValue *error_details) const override
Definition: standard_codec.cc:411
flutter::StandardMethodCodec::operator=
StandardMethodCodec & operator=(StandardMethodCodec const &)=delete
flutter::StandardMethodCodec::EncodeSuccessEnvelopeInternal
std::unique_ptr< std::vector< uint8_t > > EncodeSuccessEnvelopeInternal(const EncodableValue *result) const override
Definition: standard_codec.cc:397
method_call.h
flutter::StandardMethodCodec::GetInstance
static const StandardMethodCodec & GetInstance(const StandardCodecSerializer *serializer=nullptr)
Definition: standard_codec.cc:340