Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1297)

Unified Diff: base/pickle.cc

Issue 927183002: Adding StringPiece read/write support to pickle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix indentation to make it consistent. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/pickle.h ('k') | base/pickle_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/pickle.cc
diff --git a/base/pickle.cc b/base/pickle.cc
index d461f413dfd2e68a6e97c9f15d5d97dc68faacb3..e66c5baca11bb382cea40489f7335f44b27254fd 100644
--- a/base/pickle.cc
+++ b/base/pickle.cc
@@ -152,6 +152,18 @@ bool PickleIterator::ReadString(std::string* result) {
return true;
}
+bool PickleIterator::ReadStringPiece(base::StringPiece* result) {
+ int len;
+ if (!ReadInt(&len))
+ return false;
+ const char* read_from = GetReadPointerAndAdvance(len);
+ if (!read_from)
+ return false;
+
+ *result = base::StringPiece(read_from, len);
+ return true;
+}
+
bool PickleIterator::ReadWString(std::wstring* result) {
int len;
if (!ReadInt(&len))
@@ -176,6 +188,19 @@ bool PickleIterator::ReadString16(string16* result) {
return true;
}
+bool PickleIterator::ReadStringPiece16(base::StringPiece16* result) {
+ int len;
+ if (!ReadInt(&len))
+ return false;
+ const char* read_from = GetReadPointerAndAdvance(len, sizeof(char16));
+ if (!read_from)
+ return false;
+
+ *result = base::StringPiece16(reinterpret_cast<const char16*>(read_from),
+ len);
+ return true;
+}
+
bool PickleIterator::ReadData(const char** data, int* length) {
*length = 0;
*data = 0;
@@ -271,7 +296,7 @@ Pickle& Pickle::operator=(const Pickle& other) {
return *this;
}
-bool Pickle::WriteString(const std::string& value) {
+bool Pickle::WriteString(const base::StringPiece& value) {
if (!WriteInt(static_cast<int>(value.size())))
return false;
@@ -286,7 +311,7 @@ bool Pickle::WriteWString(const std::wstring& value) {
static_cast<int>(value.size() * sizeof(wchar_t)));
}
-bool Pickle::WriteString16(const string16& value) {
+bool Pickle::WriteString16(const base::StringPiece16& value) {
if (!WriteInt(static_cast<int>(value.size())))
return false;
« no previous file with comments | « base/pickle.h ('k') | base/pickle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698