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_MESSAGE_CODEC_H_ 6 #define FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_JSON_MESSAGE_CODEC_H_ 7 8 #include "json_type.h" 9 #include "message_codec.h" 10 11 namespace flutter { 12 13 // A message encoding/decoding mechanism for communications to/from the 14 // Flutter engine via JSON channels. 15 class JsonMessageCodec : public MessageCodec<JsonValueType> { 16 public: 17 // Returns the shared instance of the codec. 18 static const JsonMessageCodec& GetInstance(); 19 20 ~JsonMessageCodec() = default; 21 22 // Prevent copying. 23 JsonMessageCodec(JsonMessageCodec const&) = delete; 24 JsonMessageCodec& operator=(JsonMessageCodec const&) = delete; 25 26 protected: 27 // Instances should be obtained via GetInstance. 28 JsonMessageCodec() = default; 29 30 // |flutter::MessageCodec| 31 std::unique_ptr<JsonValueType> DecodeMessageInternal( 32 const uint8_t* binary_message, 33 const size_t message_size) const override; 34 35 // |flutter::MessageCodec| 36 std::unique_ptr<std::vector<uint8_t>> EncodeMessageInternal( 37 const JsonValueType& message) const override; 38 }; 39 40 } // namespace flutter 41 42 #endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_JSON_MESSAGE_CODEC_H_ 43