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