• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium 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 V8_CRDTP_SERIALIZABLE_H_
6 #define V8_CRDTP_SERIALIZABLE_H_
7 
8 #include <cstdint>
9 #include <memory>
10 #include <vector>
11 #include "export.h"
12 
13 namespace v8_crdtp {
14 // =============================================================================
15 // Serializable - An object to be emitted as a sequence of bytes.
16 // =============================================================================
17 class Serializable {
18  public:
19   // Convenience: Invokes |AppendSerialized| on an empty vector.
20   std::vector<uint8_t> Serialize() const;
21 
22   virtual void AppendSerialized(std::vector<uint8_t>* out) const = 0;
23 
24   virtual ~Serializable() = default;
25 
26   // Wraps a vector of |bytes| into a Serializable for situations in which we
27   // eagerly serialize a structure.
28   static std::unique_ptr<Serializable> From(std::vector<uint8_t> bytes);
29 };
30 }  // namespace v8_crdtp
31 
32 #endif  // V8_CRDTP_SERIALIZABLE_H_
33