Flutter Engine
test_codec_extensions.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_TESTING_TEST_CODEC_EXTENSIONS_H_
6 #define FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_TESTING_TEST_CODEC_EXTENSIONS_H_
7 
8 #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/encodable_value.h"
9 #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_codec_serializer.h"
10 
11 namespace flutter {
12 
13 // A representation of a point, for custom type testing of a simple type.
14 class Point {
15  public:
16  Point(int x, int y) : x_(x), y_(y) {}
17  ~Point() = default;
18 
19  int x() const { return x_; }
20  int y() const { return y_; }
21 
22  bool operator==(const Point& other) const {
23  return x_ == other.x_ && y_ == other.y_;
24  }
25 
26  private:
27  int x_;
28  int y_;
29 };
30 
31 // A typed binary data object with extra fields, for custom type testing of a
32 // variable-length type that includes types handled by the core standard codec.
33 class SomeData {
34  public:
35  SomeData(const std::string label, const std::vector<uint8_t>& data)
36  : label_(label), data_(data) {}
37  ~SomeData() = default;
38 
39  const std::string& label() const { return label_; }
40  const std::vector<uint8_t>& data() const { return data_; }
41 
42  private:
43  std::string label_;
44  std::vector<uint8_t> data_;
45 };
46 
47 // Codec extension for Point.
49  public:
51  virtual ~PointExtensionSerializer();
52 
53  static const PointExtensionSerializer& GetInstance();
54 
55  // |TestCodecSerializer|
56  EncodableValue ReadValueOfType(uint8_t type,
57  ByteStreamReader* stream) const override;
58 
59  // |TestCodecSerializer|
60  void WriteValue(const EncodableValue& value,
61  ByteStreamWriter* stream) const override;
62 
63  private:
64  static constexpr uint8_t kPointType = 128;
65 };
66 
67 // Codec extension for SomeData.
69  public:
71  virtual ~SomeDataExtensionSerializer();
72 
73  static const SomeDataExtensionSerializer& GetInstance();
74 
75  // |TestCodecSerializer|
76  EncodableValue ReadValueOfType(uint8_t type,
77  ByteStreamReader* stream) const override;
78 
79  // |TestCodecSerializer|
80  void WriteValue(const EncodableValue& value,
81  ByteStreamWriter* stream) const override;
82 
83  private:
84  static constexpr uint8_t kSomeDataType = 129;
85 };
86 
87 } // namespace flutter
88 
89 #endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_TESTING_TEST_CODEC_EXTENSIONS_H_
bool operator==(const Point &other) const
const std::string & label() const
const std::vector< uint8_t > & data() const
SomeData(const std::string label, const std::vector< uint8_t > &data)
~Point()=default
uint8_t value