| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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 MOJO_PUBLIC_CPP_BINDINGS_LIB_PICKLE_BUFFER_H_ | |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_PICKLE_BUFFER_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include <memory> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "base/pickle.h" | |
| 14 #include "mojo/public/cpp/bindings/lib/buffer.h" | |
| 15 | |
| 16 namespace mojo { | |
| 17 namespace internal { | |
| 18 | |
| 19 // An implementation of Buffer which uses base::Pickle for its backing. Note | |
| 20 // that this does not use Pickle's header structure at all, instead storing | |
| 21 // the complete Message (including header) in the Pickle's payload. | |
| 22 class PickleBuffer : public Buffer { | |
| 23 public: | |
| 24 PickleBuffer(size_t num_bytes, bool zero_initialized); | |
| 25 ~PickleBuffer() override; | |
| 26 | |
| 27 const void* data() const; | |
| 28 | |
| 29 void* data() { | |
| 30 return const_cast<void*>(static_cast<const PickleBuffer*>(this)->data()); | |
| 31 } | |
| 32 | |
| 33 size_t data_num_bytes() const; | |
| 34 | |
| 35 base::Pickle* pickle() const; | |
| 36 | |
| 37 private: | |
| 38 class Storage; | |
| 39 | |
| 40 // Buffer implementation. Note that this cannot grow the Pickle's capacity and | |
| 41 // it is an error to Allocate() more bytes in total than have been | |
| 42 // pre-allocated using ReserveCapacity() or ReserveUninitializedCapacity(). | |
| 43 // | |
| 44 // This guarantees that the returned data is aligned on an 8-byte boundary. | |
| 45 void* Allocate(size_t num_bytes) override; | |
| 46 PickleBuffer* AsPickleBuffer() override; | |
| 47 | |
| 48 std::unique_ptr<Storage> storage_; | |
| 49 | |
| 50 DISALLOW_COPY_AND_ASSIGN(PickleBuffer); | |
| 51 }; | |
| 52 | |
| 53 } // namespace internal | |
| 54 } // namespace mojo | |
| 55 | |
| 56 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_PICKLE_BUFFER_H_ | |
| OLD | NEW |