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 STORAGE_COMMON_BLOB_STORAGE_BLOB_ITEM_BYTES_RESPONSE_H_ |
| 6 #define STORAGE_COMMON_BLOB_STORAGE_BLOB_ITEM_BYTES_RESPONSE_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 #include <algorithm> |
| 10 #include <ostream> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/basictypes.h" |
| 14 #include "storage/common/storage_common_export.h" |
| 15 |
| 16 namespace storage { |
| 17 |
| 18 // This class is serialized over IPC to send blob item data, or to signal that |
| 19 // the memory has been populated. |
| 20 struct STORAGE_COMMON_EXPORT BlobItemBytesResponse { |
| 21 // not using std::numeric_limits<T>::max() because of non-C++11 builds. |
| 22 static const size_t kInvalidIndex = SIZE_MAX; |
| 23 |
| 24 BlobItemBytesResponse(); |
| 25 explicit BlobItemBytesResponse(size_t request_number); |
| 26 ~BlobItemBytesResponse(); |
| 27 |
| 28 char* allocate_mutable_data(size_t size) { |
| 29 inline_data.resize(size); |
| 30 return &inline_data[0]; |
| 31 } |
| 32 |
| 33 size_t request_number; |
| 34 std::vector<char> inline_data; |
| 35 }; |
| 36 |
| 37 #if defined(UNIT_TEST) |
| 38 STORAGE_COMMON_EXPORT inline bool operator==(const BlobItemBytesResponse& a, |
| 39 const BlobItemBytesResponse& b) { |
| 40 return a.request_number == b.request_number && |
| 41 a.inline_data.size() == b.inline_data.size() && |
| 42 std::equal(a.inline_data.begin(), |
| 43 a.inline_data.begin() + a.inline_data.size(), |
| 44 b.inline_data.begin()); |
| 45 } |
| 46 |
| 47 STORAGE_COMMON_EXPORT inline bool operator!=(const BlobItemBytesResponse& a, |
| 48 const BlobItemBytesResponse& b) { |
| 49 return !(a == b); |
| 50 } |
| 51 |
| 52 STORAGE_COMMON_EXPORT inline ::std::ostream& operator<<( |
| 53 ::std::ostream& os, |
| 54 const BlobItemBytesResponse& response) { |
| 55 std::string data_string(response.inline_data.begin(), |
| 56 response.inline_data.end()); |
| 57 return os << "{ request_number: " << response.request_number |
| 58 << ", inline_data size: " << response.inline_data.size() |
| 59 << ", inline_data: " << data_string << " }"; |
| 60 } |
| 61 #endif // defined(UNIT_TEST) |
| 62 |
| 63 } // namespace storage |
| 64 |
| 65 #endif // STORAGE_COMMON_BLOB_STORAGE_BLOB_ITEM_BYTES_RESPONSE_H_ |
OLD | NEW |