Remove base/pickle
Change-Id: Ic3897cd4c4e1c2998291e63518ca6da67ef144d0
Reviewed-on: https://gn-review.googlesource.com/1423
Reviewed-by: Brett Wilson <brettw@chromium.org>
Commit-Queue: Scott Graham <scottmg@chromium.org>
diff --git a/base/files/file_path.cc b/base/files/file_path.cc
index 6221db9..146796b 100644
--- a/base/files/file_path.cc
+++ b/base/files/file_path.cc
@@ -9,7 +9,6 @@
#include "base/logging.h"
#include "base/macros.h"
-#include "base/pickle.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
@@ -667,33 +666,6 @@
#endif // defined(OS_WIN)
-void FilePath::WriteToPickle(Pickle* pickle) const {
-#if defined(OS_WIN)
- pickle->WriteString16(path_);
-#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
- pickle->WriteString(path_);
-#else
-#error Unsupported platform
-#endif
-}
-
-bool FilePath::ReadFromPickle(PickleIterator* iter) {
-#if defined(OS_WIN)
- if (!iter->ReadString16(&path_))
- return false;
-#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
- if (!iter->ReadString(&path_))
- return false;
-#else
-#error Unsupported platform
-#endif
-
- if (path_.find(kStringTerminator) != StringType::npos)
- return false;
-
- return true;
-}
-
#if defined(OS_WIN)
// Windows specific implementation of file string comparisons.
diff --git a/base/files/file_path.h b/base/files/file_path.h
index a31253e..340375d 100644
--- a/base/files/file_path.h
+++ b/base/files/file_path.h
@@ -384,9 +384,6 @@
// Similar to FromUTF8Unsafe, but accepts UTF-16 instead.
static FilePath FromUTF16Unsafe(StringPiece16 utf16);
- void WriteToPickle(Pickle* pickle) const;
- bool ReadFromPickle(PickleIterator* iter);
-
// Normalize all path separators to backslash on Windows
// (if FILE_PATH_USES_WIN_SEPARATORS is true), or do nothing on POSIX systems.
FilePath NormalizePathSeparators() const;
diff --git a/base/pickle.cc b/base/pickle.cc
deleted file mode 100644
index 89e2d01..0000000
--- a/base/pickle.cc
+++ /dev/null
@@ -1,435 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/pickle.h"
-
-#include <stdlib.h>
-
-#include <algorithm> // for max()
-#include <limits>
-
-#include "base/bits.h"
-#include "base/macros.h"
-#include "base/numerics/safe_conversions.h"
-#include "base/numerics/safe_math.h"
-#include "build_config.h"
-
-namespace base {
-
-// static
-const int Pickle::kPayloadUnit = 64;
-
-static const size_t kCapacityReadOnly = static_cast<size_t>(-1);
-
-PickleIterator::PickleIterator(const Pickle& pickle)
- : payload_(pickle.payload()),
- read_index_(0),
- end_index_(pickle.payload_size()) {
-}
-
-template <typename Type>
-inline bool PickleIterator::ReadBuiltinType(Type* result) {
- const char* read_from = GetReadPointerAndAdvance<Type>();
- if (!read_from)
- return false;
- if (sizeof(Type) > sizeof(uint32_t))
- memcpy(result, read_from, sizeof(*result));
- else
- *result = *reinterpret_cast<const Type*>(read_from);
- return true;
-}
-
-inline void PickleIterator::Advance(size_t size) {
- size_t aligned_size = bits::Align(size, sizeof(uint32_t));
- if (end_index_ - read_index_ < aligned_size) {
- read_index_ = end_index_;
- } else {
- read_index_ += aligned_size;
- }
-}
-
-template<typename Type>
-inline const char* PickleIterator::GetReadPointerAndAdvance() {
- if (sizeof(Type) > end_index_ - read_index_) {
- read_index_ = end_index_;
- return nullptr;
- }
- const char* current_read_ptr = payload_ + read_index_;
- Advance(sizeof(Type));
- return current_read_ptr;
-}
-
-const char* PickleIterator::GetReadPointerAndAdvance(int num_bytes) {
- if (num_bytes < 0 ||
- end_index_ - read_index_ < static_cast<size_t>(num_bytes)) {
- read_index_ = end_index_;
- return nullptr;
- }
- const char* current_read_ptr = payload_ + read_index_;
- Advance(num_bytes);
- return current_read_ptr;
-}
-
-inline const char* PickleIterator::GetReadPointerAndAdvance(
- int num_elements,
- size_t size_element) {
- // Check for int32_t overflow.
- int num_bytes;
- if (!CheckMul(num_elements, size_element).AssignIfValid(&num_bytes))
- return nullptr;
- return GetReadPointerAndAdvance(num_bytes);
-}
-
-bool PickleIterator::ReadBool(bool* result) {
- return ReadBuiltinType(result);
-}
-
-bool PickleIterator::ReadInt(int* result) {
- return ReadBuiltinType(result);
-}
-
-bool PickleIterator::ReadLong(long* result) {
- // Always read long as a 64-bit value to ensure compatibility between 32-bit
- // and 64-bit processes.
- int64_t result_int64 = 0;
- if (!ReadBuiltinType(&result_int64))
- return false;
- // CHECK if the cast truncates the value so that we know to change this IPC
- // parameter to use int64_t.
- *result = base::checked_cast<long>(result_int64);
- return true;
-}
-
-bool PickleIterator::ReadUInt16(uint16_t* result) {
- return ReadBuiltinType(result);
-}
-
-bool PickleIterator::ReadUInt32(uint32_t* result) {
- return ReadBuiltinType(result);
-}
-
-bool PickleIterator::ReadInt64(int64_t* result) {
- return ReadBuiltinType(result);
-}
-
-bool PickleIterator::ReadUInt64(uint64_t* result) {
- return ReadBuiltinType(result);
-}
-
-bool PickleIterator::ReadFloat(float* result) {
- // crbug.com/315213
- // The source data may not be properly aligned, and unaligned float reads
- // cause SIGBUS on some ARM platforms, so force using memcpy to copy the data
- // into the result.
- const char* read_from = GetReadPointerAndAdvance<float>();
- if (!read_from)
- return false;
- memcpy(result, read_from, sizeof(*result));
- return true;
-}
-
-bool PickleIterator::ReadDouble(double* result) {
- // crbug.com/315213
- // The source data may not be properly aligned, and unaligned double reads
- // cause SIGBUS on some ARM platforms, so force using memcpy to copy the data
- // into the result.
- const char* read_from = GetReadPointerAndAdvance<double>();
- if (!read_from)
- return false;
- memcpy(result, read_from, sizeof(*result));
- return true;
-}
-
-bool PickleIterator::ReadString(std::string* result) {
- int len;
- if (!ReadInt(&len))
- return false;
- const char* read_from = GetReadPointerAndAdvance(len);
- if (!read_from)
- return false;
-
- result->assign(read_from, len);
- return true;
-}
-
-bool PickleIterator::ReadStringPiece(StringPiece* result) {
- int len;
- if (!ReadInt(&len))
- return false;
- const char* read_from = GetReadPointerAndAdvance(len);
- if (!read_from)
- return false;
-
- *result = StringPiece(read_from, len);
- return true;
-}
-
-bool PickleIterator::ReadString16(string16* result) {
- int len;
- if (!ReadInt(&len))
- return false;
- const char* read_from = GetReadPointerAndAdvance(len, sizeof(char16));
- if (!read_from)
- return false;
-
- result->assign(reinterpret_cast<const char16*>(read_from), len);
- return true;
-}
-
-bool PickleIterator::ReadStringPiece16(StringPiece16* result) {
- int len;
- if (!ReadInt(&len))
- return false;
- const char* read_from = GetReadPointerAndAdvance(len, sizeof(char16));
- if (!read_from)
- return false;
-
- *result = StringPiece16(reinterpret_cast<const char16*>(read_from), len);
- return true;
-}
-
-bool PickleIterator::ReadData(const char** data, int* length) {
- *length = 0;
- *data = nullptr;
-
- if (!ReadInt(length))
- return false;
-
- return ReadBytes(data, *length);
-}
-
-bool PickleIterator::ReadBytes(const char** data, int length) {
- const char* read_from = GetReadPointerAndAdvance(length);
- if (!read_from)
- return false;
- *data = read_from;
- return true;
-}
-
-Pickle::Attachment::Attachment() = default;
-
-Pickle::Attachment::~Attachment() = default;
-
-// Payload is uint32_t aligned.
-
-Pickle::Pickle()
- : header_(nullptr),
- header_size_(sizeof(Header)),
- capacity_after_header_(0),
- write_offset_(0) {
- static_assert((Pickle::kPayloadUnit & (Pickle::kPayloadUnit - 1)) == 0,
- "Pickle::kPayloadUnit must be a power of two");
- Resize(kPayloadUnit);
- header_->payload_size = 0;
-}
-
-Pickle::Pickle(int header_size)
- : header_(nullptr),
- header_size_(bits::Align(header_size, sizeof(uint32_t))),
- capacity_after_header_(0),
- write_offset_(0) {
- DCHECK_GE(static_cast<size_t>(header_size), sizeof(Header));
- DCHECK_LE(header_size, kPayloadUnit);
- Resize(kPayloadUnit);
- header_->payload_size = 0;
-}
-
-Pickle::Pickle(const char* data, int data_len)
- : header_(reinterpret_cast<Header*>(const_cast<char*>(data))),
- header_size_(0),
- capacity_after_header_(kCapacityReadOnly),
- write_offset_(0) {
- if (data_len >= static_cast<int>(sizeof(Header)))
- header_size_ = data_len - header_->payload_size;
-
- if (header_size_ > static_cast<unsigned int>(data_len))
- header_size_ = 0;
-
- if (header_size_ != bits::Align(header_size_, sizeof(uint32_t)))
- header_size_ = 0;
-
- // If there is anything wrong with the data, we're not going to use it.
- if (!header_size_)
- header_ = nullptr;
-}
-
-Pickle::Pickle(const Pickle& other)
- : header_(nullptr),
- header_size_(other.header_size_),
- capacity_after_header_(0),
- write_offset_(other.write_offset_) {
- Resize(other.header_->payload_size);
- memcpy(header_, other.header_, header_size_ + other.header_->payload_size);
-}
-
-Pickle::~Pickle() {
- if (capacity_after_header_ != kCapacityReadOnly)
- free(header_);
-}
-
-Pickle& Pickle::operator=(const Pickle& other) {
- if (this == &other) {
- return *this;
- }
- if (capacity_after_header_ == kCapacityReadOnly) {
- header_ = nullptr;
- capacity_after_header_ = 0;
- }
- if (header_size_ != other.header_size_) {
- free(header_);
- header_ = nullptr;
- header_size_ = other.header_size_;
- }
- Resize(other.header_->payload_size);
- memcpy(header_, other.header_,
- other.header_size_ + other.header_->payload_size);
- write_offset_ = other.write_offset_;
- return *this;
-}
-
-void Pickle::WriteString(const StringPiece& value) {
- WriteInt(static_cast<int>(value.size()));
- WriteBytes(value.data(), static_cast<int>(value.size()));
-}
-
-void Pickle::WriteString16(const StringPiece16& value) {
- WriteInt(static_cast<int>(value.size()));
- WriteBytes(value.data(), static_cast<int>(value.size()) * sizeof(char16));
-}
-
-void Pickle::WriteData(const char* data, int length) {
- DCHECK_GE(length, 0);
- WriteInt(length);
- WriteBytes(data, length);
-}
-
-void Pickle::WriteBytes(const void* data, int length) {
- WriteBytesCommon(data, length);
-}
-
-void Pickle::Reserve(size_t length) {
- size_t data_len = bits::Align(length, sizeof(uint32_t));
- DCHECK_GE(data_len, length);
-#ifdef ARCH_CPU_64_BITS
- DCHECK_LE(data_len, std::numeric_limits<uint32_t>::max());
-#endif
- DCHECK_LE(write_offset_, std::numeric_limits<uint32_t>::max() - data_len);
- size_t new_size = write_offset_ + data_len;
- if (new_size > capacity_after_header_)
- Resize(capacity_after_header_ * 2 + new_size);
-}
-
-bool Pickle::WriteAttachment(scoped_refptr<Attachment> attachment) {
- return false;
-}
-
-bool Pickle::ReadAttachment(base::PickleIterator* iter,
- scoped_refptr<Attachment>* attachment) const {
- return false;
-}
-
-bool Pickle::HasAttachments() const {
- return false;
-}
-
-void Pickle::Resize(size_t new_capacity) {
- CHECK_NE(capacity_after_header_, kCapacityReadOnly);
- capacity_after_header_ = bits::Align(new_capacity, kPayloadUnit);
- void* p = realloc(header_, GetTotalAllocatedSize());
- CHECK(p);
- header_ = reinterpret_cast<Header*>(p);
-}
-
-void* Pickle::ClaimBytes(size_t num_bytes) {
- void* p = ClaimUninitializedBytesInternal(num_bytes);
- CHECK(p);
- memset(p, 0, num_bytes);
- return p;
-}
-
-size_t Pickle::GetTotalAllocatedSize() const {
- if (capacity_after_header_ == kCapacityReadOnly)
- return 0;
- return header_size_ + capacity_after_header_;
-}
-
-// static
-const char* Pickle::FindNext(size_t header_size,
- const char* start,
- const char* end) {
- size_t pickle_size = 0;
- if (!PeekNext(header_size, start, end, &pickle_size))
- return nullptr;
-
- if (pickle_size > static_cast<size_t>(end - start))
- return nullptr;
-
- return start + pickle_size;
-}
-
-// static
-bool Pickle::PeekNext(size_t header_size,
- const char* start,
- const char* end,
- size_t* pickle_size) {
- DCHECK_EQ(header_size, bits::Align(header_size, sizeof(uint32_t)));
- DCHECK_GE(header_size, sizeof(Header));
- DCHECK_LE(header_size, static_cast<size_t>(kPayloadUnit));
-
- size_t length = static_cast<size_t>(end - start);
- if (length < sizeof(Header))
- return false;
-
- const Header* hdr = reinterpret_cast<const Header*>(start);
- if (length < header_size)
- return false;
-
- // If payload_size causes an overflow, we return maximum possible
- // pickle size to indicate that.
- *pickle_size = ClampAdd(header_size, hdr->payload_size);
- return true;
-}
-
-template <size_t length> void Pickle::WriteBytesStatic(const void* data) {
- WriteBytesCommon(data, length);
-}
-
-template void Pickle::WriteBytesStatic<2>(const void* data);
-template void Pickle::WriteBytesStatic<4>(const void* data);
-template void Pickle::WriteBytesStatic<8>(const void* data);
-
-inline void* Pickle::ClaimUninitializedBytesInternal(size_t length) {
- DCHECK_NE(kCapacityReadOnly, capacity_after_header_)
- << "oops: pickle is readonly";
- size_t data_len = bits::Align(length, sizeof(uint32_t));
- DCHECK_GE(data_len, length);
-#ifdef ARCH_CPU_64_BITS
- DCHECK_LE(data_len, std::numeric_limits<uint32_t>::max());
-#endif
- DCHECK_LE(write_offset_, std::numeric_limits<uint32_t>::max() - data_len);
- size_t new_size = write_offset_ + data_len;
- if (new_size > capacity_after_header_) {
- size_t new_capacity = capacity_after_header_ * 2;
- const size_t kPickleHeapAlign = 4096;
- if (new_capacity > kPickleHeapAlign)
- new_capacity = bits::Align(new_capacity, kPickleHeapAlign) - kPayloadUnit;
- Resize(std::max(new_capacity, new_size));
- }
-
- char* write = mutable_payload() + write_offset_;
- memset(write + length, 0, data_len - length); // Always initialize padding
- header_->payload_size = static_cast<uint32_t>(new_size);
- write_offset_ = new_size;
- return write;
-}
-
-inline void Pickle::WriteBytesCommon(const void* data, size_t length) {
- DCHECK_NE(kCapacityReadOnly, capacity_after_header_)
- << "oops: pickle is readonly";
- MSAN_CHECK_MEM_IS_INITIALIZED(data, length);
- void* write = ClaimUninitializedBytesInternal(length);
- memcpy(write, data, length);
-}
-
-} // namespace base
diff --git a/base/pickle.h b/base/pickle.h
deleted file mode 100644
index eff2092..0000000
--- a/base/pickle.h
+++ /dev/null
@@ -1,345 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BASE_PICKLE_H_
-#define BASE_PICKLE_H_
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include <string>
-
-#include "base/base_export.h"
-#include "base/compiler_specific.h"
-#include "base/gtest_prod_util.h"
-#include "base/logging.h"
-#include "base/memory/ref_counted.h"
-#include "base/strings/string16.h"
-#include "base/strings/string_piece.h"
-
-#if defined(OS_POSIX)
-#include "base/files/file.h"
-#endif
-
-namespace base {
-
-class Pickle;
-
-// PickleIterator reads data from a Pickle. The Pickle object must remain valid
-// while the PickleIterator object is in use.
-class BASE_EXPORT PickleIterator {
- public:
- PickleIterator() : payload_(NULL), read_index_(0), end_index_(0) {}
- explicit PickleIterator(const Pickle& pickle);
-
- // Methods for reading the payload of the Pickle. To read from the start of
- // the Pickle, create a PickleIterator from a Pickle. If successful, these
- // methods return true. Otherwise, false is returned to indicate that the
- // result could not be extracted. It is not possible to read from the iterator
- // after that.
- bool ReadBool(bool* result) WARN_UNUSED_RESULT;
- bool ReadInt(int* result) WARN_UNUSED_RESULT;
- bool ReadLong(long* result) WARN_UNUSED_RESULT;
- bool ReadUInt16(uint16_t* result) WARN_UNUSED_RESULT;
- bool ReadUInt32(uint32_t* result) WARN_UNUSED_RESULT;
- bool ReadInt64(int64_t* result) WARN_UNUSED_RESULT;
- bool ReadUInt64(uint64_t* result) WARN_UNUSED_RESULT;
- bool ReadFloat(float* result) WARN_UNUSED_RESULT;
- bool ReadDouble(double* result) WARN_UNUSED_RESULT;
- bool ReadString(std::string* result) WARN_UNUSED_RESULT;
- // The StringPiece data will only be valid for the lifetime of the message.
- bool ReadStringPiece(StringPiece* result) WARN_UNUSED_RESULT;
- bool ReadString16(string16* result) WARN_UNUSED_RESULT;
- // The StringPiece16 data will only be valid for the lifetime of the message.
- bool ReadStringPiece16(StringPiece16* result) WARN_UNUSED_RESULT;
-
- // A pointer to the data will be placed in |*data|, and the length will be
- // placed in |*length|. The pointer placed into |*data| points into the
- // message's buffer so it will be scoped to the lifetime of the message (or
- // until the message data is mutated). Do not keep the pointer around!
- bool ReadData(const char** data, int* length) WARN_UNUSED_RESULT;
-
- // A pointer to the data will be placed in |*data|. The caller specifies the
- // number of bytes to read, and ReadBytes will validate this length. The
- // pointer placed into |*data| points into the message's buffer so it will be
- // scoped to the lifetime of the message (or until the message data is
- // mutated). Do not keep the pointer around!
- bool ReadBytes(const char** data, int length) WARN_UNUSED_RESULT;
-
- // A safer version of ReadInt() that checks for the result not being negative.
- // Use it for reading the object sizes.
- bool ReadLength(int* result) WARN_UNUSED_RESULT {
- return ReadInt(result) && *result >= 0;
- }
-
- // Skips bytes in the read buffer and returns true if there are at least
- // num_bytes available. Otherwise, does nothing and returns false.
- bool SkipBytes(int num_bytes) WARN_UNUSED_RESULT {
- return !!GetReadPointerAndAdvance(num_bytes);
- }
-
- private:
- // Read Type from Pickle.
- template <typename Type>
- bool ReadBuiltinType(Type* result);
-
- // Advance read_index_ but do not allow it to exceed end_index_.
- // Keeps read_index_ aligned.
- void Advance(size_t size);
-
- // Get read pointer for Type and advance read pointer.
- template<typename Type>
- const char* GetReadPointerAndAdvance();
-
- // Get read pointer for |num_bytes| and advance read pointer. This method
- // checks num_bytes for negativity and wrapping.
- const char* GetReadPointerAndAdvance(int num_bytes);
-
- // Get read pointer for (num_elements * size_element) bytes and advance read
- // pointer. This method checks for int overflow, negativity and wrapping.
- const char* GetReadPointerAndAdvance(int num_elements,
- size_t size_element);
-
- const char* payload_; // Start of our pickle's payload.
- size_t read_index_; // Offset of the next readable byte in payload.
- size_t end_index_; // Payload size.
-
- FRIEND_TEST_ALL_PREFIXES(PickleTest, GetReadPointerAndAdvance);
-};
-
-// This class provides facilities for basic binary value packing and unpacking.
-//
-// The Pickle class supports appending primitive values (ints, strings, etc.)
-// to a pickle instance. The Pickle instance grows its internal memory buffer
-// dynamically to hold the sequence of primitive values. The internal memory
-// buffer is exposed as the "data" of the Pickle. This "data" can be passed
-// to a Pickle object to initialize it for reading.
-//
-// When reading from a Pickle object, it is important for the consumer to know
-// what value types to read and in what order to read them as the Pickle does
-// not keep track of the type of data written to it.
-//
-// The Pickle's data has a header which contains the size of the Pickle's
-// payload. It can optionally support additional space in the header. That
-// space is controlled by the header_size parameter passed to the Pickle
-// constructor.
-//
-class BASE_EXPORT Pickle {
- public:
- // Auxiliary data attached to a Pickle. Pickle must be subclassed along with
- // this interface in order to provide a concrete implementation of support
- // for attachments. The base Pickle implementation does not accept
- // attachments.
- class BASE_EXPORT Attachment : public RefCountedThreadSafe<Attachment> {
- public:
- Attachment();
-
- protected:
- friend class RefCountedThreadSafe<Attachment>;
- virtual ~Attachment();
-
- DISALLOW_COPY_AND_ASSIGN(Attachment);
- };
-
- // Initialize a Pickle object using the default header size.
- Pickle();
-
- // Initialize a Pickle object with the specified header size in bytes, which
- // must be greater-than-or-equal-to sizeof(Pickle::Header). The header size
- // will be rounded up to ensure that the header size is 32bit-aligned.
- explicit Pickle(int header_size);
-
- // Initializes a Pickle from a const block of data. The data is not copied;
- // instead the data is merely referenced by this Pickle. Only const methods
- // should be used on the Pickle when initialized this way. The header
- // padding size is deduced from the data length.
- Pickle(const char* data, int data_len);
-
- // Initializes a Pickle as a deep copy of another Pickle.
- Pickle(const Pickle& other);
-
- // Note: There are no virtual methods in this class. This destructor is
- // virtual as an element of defensive coding. Other classes have derived from
- // this class, and there is a *chance* that they will cast into this base
- // class before destruction. At least one such class does have a virtual
- // destructor, suggesting at least some need to call more derived destructors.
- virtual ~Pickle();
-
- // Performs a deep copy.
- Pickle& operator=(const Pickle& other);
-
- // Returns the number of bytes written in the Pickle, including the header.
- size_t size() const { return header_size_ + header_->payload_size; }
-
- // Returns the data for this Pickle.
- const void* data() const { return header_; }
-
- // Returns the effective memory capacity of this Pickle, that is, the total
- // number of bytes currently dynamically allocated or 0 in the case of a
- // read-only Pickle. This should be used only for diagnostic / profiling
- // purposes.
- size_t GetTotalAllocatedSize() const;
-
- // Methods for adding to the payload of the Pickle. These values are
- // appended to the end of the Pickle's payload. When reading values from a
- // Pickle, it is important to read them in the order in which they were added
- // to the Pickle.
-
- void WriteBool(bool value) { WriteInt(value ? 1 : 0); }
- void WriteInt(int value) { WritePOD(value); }
- void WriteLong(long value) {
- // Always write long as a 64-bit value to ensure compatibility between
- // 32-bit and 64-bit processes.
- WritePOD(static_cast<int64_t>(value));
- }
- void WriteUInt16(uint16_t value) { WritePOD(value); }
- void WriteUInt32(uint32_t value) { WritePOD(value); }
- void WriteInt64(int64_t value) { WritePOD(value); }
- void WriteUInt64(uint64_t value) { WritePOD(value); }
- void WriteFloat(float value) { WritePOD(value); }
- void WriteDouble(double value) { WritePOD(value); }
- void WriteString(const StringPiece& value);
- void WriteString16(const StringPiece16& value);
- // "Data" is a blob with a length. When you read it out you will be given the
- // length. See also WriteBytes.
- void WriteData(const char* data, int length);
- // "Bytes" is a blob with no length. The caller must specify the length both
- // when reading and writing. It is normally used to serialize PoD types of a
- // known size. See also WriteData.
- void WriteBytes(const void* data, int length);
-
- // WriteAttachment appends |attachment| to the pickle. It returns
- // false iff the set is full or if the Pickle implementation does not support
- // attachments.
- virtual bool WriteAttachment(scoped_refptr<Attachment> attachment);
-
- // ReadAttachment parses an attachment given the parsing state |iter| and
- // writes it to |*attachment|. It returns true on success.
- virtual bool ReadAttachment(base::PickleIterator* iter,
- scoped_refptr<Attachment>* attachment) const;
-
- // Indicates whether the pickle has any attachments.
- virtual bool HasAttachments() const;
-
- // Reserves space for upcoming writes when multiple writes will be made and
- // their sizes are computed in advance. It can be significantly faster to call
- // Reserve() before calling WriteFoo() multiple times.
- void Reserve(size_t additional_capacity);
-
- // Payload follows after allocation of Header (header size is customizable).
- struct Header {
- uint32_t payload_size; // Specifies the size of the payload.
- };
-
- // Returns the header, cast to a user-specified type T. The type T must be a
- // subclass of Header and its size must correspond to the header_size passed
- // to the Pickle constructor.
- template <class T>
- T* headerT() {
- DCHECK_EQ(header_size_, sizeof(T));
- return static_cast<T*>(header_);
- }
- template <class T>
- const T* headerT() const {
- DCHECK_EQ(header_size_, sizeof(T));
- return static_cast<const T*>(header_);
- }
-
- // The payload is the pickle data immediately following the header.
- size_t payload_size() const {
- return header_ ? header_->payload_size : 0;
- }
-
- const char* payload() const {
- return reinterpret_cast<const char*>(header_) + header_size_;
- }
-
- // Returns the address of the byte immediately following the currently valid
- // header + payload.
- const char* end_of_payload() const {
- // This object may be invalid.
- return header_ ? payload() + payload_size() : NULL;
- }
-
- protected:
- // Returns size of the header, which can have default value, set by user or
- // calculated by passed raw data.
- size_t header_size() const { return header_size_; }
-
- char* mutable_payload() {
- return reinterpret_cast<char*>(header_) + header_size_;
- }
-
- size_t capacity_after_header() const {
- return capacity_after_header_;
- }
-
- // Resize the capacity, note that the input value should not include the size
- // of the header.
- void Resize(size_t new_capacity);
-
- // Claims |num_bytes| bytes of payload. This is similar to Reserve() in that
- // it may grow the capacity, but it also advances the write offset of the
- // pickle by |num_bytes|. Claimed memory, including padding, is zeroed.
- //
- // Returns the address of the first byte claimed.
- void* ClaimBytes(size_t num_bytes);
-
- // Find the end of the pickled data that starts at range_start. Returns NULL
- // if the entire Pickle is not found in the given data range.
- static const char* FindNext(size_t header_size,
- const char* range_start,
- const char* range_end);
-
- // Parse pickle header and return total size of the pickle. Data range
- // doesn't need to contain entire pickle.
- // Returns true if pickle header was found and parsed. Callers must check
- // returned |pickle_size| for sanity (against maximum message size, etc).
- // NOTE: when function successfully parses a header, but encounters an
- // overflow during pickle size calculation, it sets |pickle_size| to the
- // maximum size_t value and returns true.
- static bool PeekNext(size_t header_size,
- const char* range_start,
- const char* range_end,
- size_t* pickle_size);
-
- // The allocation granularity of the payload.
- static const int kPayloadUnit;
-
- private:
- friend class PickleIterator;
-
- Header* header_;
- size_t header_size_; // Supports extra data between header and payload.
- // Allocation size of payload (or -1 if allocation is const). Note: this
- // doesn't count the header.
- size_t capacity_after_header_;
- // The offset at which we will write the next field. Note: this doesn't count
- // the header.
- size_t write_offset_;
-
- // Just like WriteBytes, but with a compile-time size, for performance.
- template<size_t length> void BASE_EXPORT WriteBytesStatic(const void* data);
-
- // Writes a POD by copying its bytes.
- template <typename T> bool WritePOD(const T& data) {
- WriteBytesStatic<sizeof(data)>(&data);
- return true;
- }
-
- inline void* ClaimUninitializedBytesInternal(size_t num_bytes);
- inline void WriteBytesCommon(const void* data, size_t length);
-
- FRIEND_TEST_ALL_PREFIXES(PickleTest, DeepCopyResize);
- FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize);
- FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNext);
- FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNextOverflow);
- FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext);
- FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader);
- FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow);
-};
-
-} // namespace base
-
-#endif // BASE_PICKLE_H_
diff --git a/build/gen.py b/build/gen.py
index 9cca4e9..5f73187 100755
--- a/build/gen.py
+++ b/build/gen.py
@@ -281,7 +281,6 @@
'base/observer_list_threadsafe.cc',
'base/path_service.cc',
'base/pending_task.cc',
- 'base/pickle.cc',
'base/process/kill.cc',
'base/process/memory.cc',
'base/process/process_handle.cc',