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 "encodable_value.h" 9 #include "method_call.h" 10 #include "method_codec.h" 11 12 namespace flutter { 13 14 // An implementation of MethodCodec that uses a binary serialization. 15 class StandardMethodCodec : public MethodCodec<EncodableValue> { 16 public: 17 // Returns the shared instance of the codec. 18 static const StandardMethodCodec& GetInstance(); 19 20 ~StandardMethodCodec() = default; 21 22 // Prevent copying. 23 StandardMethodCodec(StandardMethodCodec const&) = delete; 24 StandardMethodCodec& operator=(StandardMethodCodec const&) = delete; 25 26 protected: 27 // Instances should be obtained via GetInstance. 28 StandardMethodCodec() = default; 29 30 // |flutter::MethodCodec| 31 std::unique_ptr<MethodCall<EncodableValue>> 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<EncodableValue>& method_call) const override; 38 39 // |flutter::MethodCodec| 40 std::unique_ptr<std::vector<uint8_t>> EncodeSuccessEnvelopeInternal( 41 const EncodableValue* 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 EncodableValue* error_details) const override; 48 }; 49 50 } // namespace flutter 51 52 #endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_STANDARD_METHOD_CODEC_H_ 53