Flutter Engine
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_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_STANDARD_METHOD_CODEC_H_
6 #define FLUTTER_SHELL_PLATFORM_COMMON_CPP_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_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_STANDARD_METHOD_CODEC_H_
StandardMethodCodec & operator=(StandardMethodCodec const &)=delete
G_BEGIN_DECLS FlMethodCall * method_call
std::unique_ptr< std::vector< uint8_t > > EncodeErrorEnvelopeInternal(const std::string &error_code, const std::string &error_message, const EncodableValue *error_details) const override
bool DecodeAndProcessResponseEnvelopeInternal(const uint8_t *response, size_t response_size, MethodResult< EncodableValue > *result) const override
static const StandardMethodCodec & GetInstance(const StandardCodecSerializer *serializer=nullptr)
std::unique_ptr< std::vector< uint8_t > > EncodeSuccessEnvelopeInternal(const EncodableValue *result) const override
StandardMethodCodec(StandardMethodCodec const &)=delete
std::unique_ptr< MethodCall< EncodableValue > > DecodeMethodCallInternal(const uint8_t *message, size_t message_size) const override
std::unique_ptr< std::vector< uint8_t > > EncodeMethodCallInternal(const MethodCall< EncodableValue > &method_call) const override