Flutter iOS Embedder
standard_codec_serializer.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_CODEC_SERIALIZER_H_
6 #define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_STANDARD_CODEC_SERIALIZER_H_
7 
8 #include "byte_streams.h"
9 #include "encodable_value.h"
10 
11 namespace flutter {
12 
13 // Encapsulates the logic for encoding/decoding EncodableValues to/from the
14 // standard codec binary representation.
15 //
16 // This can be subclassed to extend the standard codec with support for new
17 // types.
19  public:
20  virtual ~StandardCodecSerializer();
21 
22  // Returns the shared serializer instance.
23  static const StandardCodecSerializer& GetInstance();
24 
25  // Prevent copying.
28 
29  // Reads and returns the next value from |stream|.
31 
32  // Writes the encoding of |value| to |stream|, including the initial type
33  // discrimination byte.
34  //
35  // Can be overridden by a subclass to extend the codec.
36  virtual void WriteValue(const EncodableValue& value,
37  ByteStreamWriter* stream) const;
38 
39  protected:
40  // Codecs require long-lived serializers, so clients should always use
41  // GetInstance().
43 
44  // Reads and returns the next value from |stream|, whose discrimination byte
45  // was |type|.
46  //
47  // The discrimination byte will already have been read from the stream when
48  // this is called.
49  //
50  // Can be overridden by a subclass to extend the codec.
51  virtual EncodableValue ReadValueOfType(uint8_t type,
52  ByteStreamReader* stream) const;
53 
54  // Reads the variable-length size from the current position in |stream|.
55  size_t ReadSize(ByteStreamReader* stream) const;
56 
57  // Writes the variable-length size encoding to |stream|.
58  void WriteSize(size_t size, ByteStreamWriter* stream) const;
59 
60  private:
61  // Reads a fixed-type list whose values are of type T from the current
62  // position in |stream|, and returns it as the corresponding EncodableValue.
63  // |T| must correspond to one of the supported list value types of
64  // EncodableValue.
65  template <typename T>
66  EncodableValue ReadVector(ByteStreamReader* stream) const;
67 
68  // Writes |vector| to |stream| as a fixed-type list. |T| must correspond to
69  // one of the supported list value types of EncodableValue.
70  template <typename T>
71  void WriteVector(const std::vector<T> vector, ByteStreamWriter* stream) const;
72 };
73 
74 } // namespace flutter
75 
76 #endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_STANDARD_CODEC_SERIALIZER_H_
flutter::StandardCodecSerializer::ReadValue
EncodableValue ReadValue(ByteStreamReader *stream) const
Definition: standard_codec.cc:92
encodable_value.h
flutter::StandardCodecSerializer::ReadValueOfType
virtual EncodableValue ReadValueOfType(uint8_t type, ByteStreamReader *stream) const
Definition: standard_codec.cc:168
flutter::StandardCodecSerializer::WriteValue
virtual void WriteValue(const EncodableValue &value, ByteStreamWriter *stream) const
Definition: standard_codec.cc:98
flutter::StandardCodecSerializer::ReadSize
size_t ReadSize(ByteStreamReader *stream) const
Definition: standard_codec.cc:229
flutter::ByteStreamReader
Definition: byte_streams.h:13
flutter::StandardCodecSerializer::GetInstance
static const StandardCodecSerializer & GetInstance()
Definition: standard_codec.cc:87
flutter
Definition: accessibility_bridge.h:28
flutter::StandardCodecSerializer::StandardCodecSerializer
StandardCodecSerializer()
flutter::StandardCodecSerializer
Definition: standard_codec_serializer.h:18
flutter::EncodableValue
Definition: encodable_value.h:165
byte_streams.h
flutter::StandardCodecSerializer::~StandardCodecSerializer
virtual ~StandardCodecSerializer()
flutter::StandardCodecSerializer::operator=
StandardCodecSerializer & operator=(StandardCodecSerializer const &)=delete
flutter::StandardCodecSerializer::WriteSize
void WriteSize(size_t size, ByteStreamWriter *stream) const
Definition: standard_codec.cc:244
flutter::ByteStreamWriter
Definition: byte_streams.h:52