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

Unified Diff: build_tools/debug_server/debug_server/common/debug_blob.cpp

Issue 6312039: RSP proxy that can record session (for playback testing).... (Closed) Base URL: http://nativeclient-sdk.googlecode.com/svn/trunk/src/
Patch Set: Created 9 years, 11 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
Index: build_tools/debug_server/debug_server/common/debug_blob.cpp
===================================================================
--- build_tools/debug_server/debug_server/common/debug_blob.cpp (revision 0)
+++ build_tools/debug_server/debug_server/common/debug_blob.cpp (revision 0)
@@ -0,0 +1,126 @@
+#include "debug_blob.h"
+#include <algorithm>
+
+namespace {
+char GetHexDigit(unsigned int value, int digit_position) {
+ const char* kDigitStrings = "0123456789ABCDEF";
+ unsigned int digit = (value >> (4 * digit_position)) & 0xF;
+ return kDigitStrings[digit];
+}
+} // namespace
+
+namespace debug {
+Blob::Blob() {
+}
+
+Blob::Blob(const Blob& other) {
+ value_ = other.value_;
+}
+
+Blob::Blob(const void* buff, size_t buff_sz) {
+ const char* char_buff = static_cast<const char*>(buff);
+ for (size_t i = 0; i < buff_sz; i++ )
+ PushBack(*char_buff++);
+}
+
+Blob::~Blob() {
+}
+
+Blob& Blob::operator = (const Blob& other) {
+ value_ = other.value_;
+ return *this;
+}
+
+bool Blob::operator == (const Blob& other) const {
+ return value_ == other.value_;
+}
+
+size_t Blob::Size() const {
+ return value_.size();
+}
+
+char Blob::operator[] (size_t position) const {
+ return value_[position];
+}
+
+char Blob::Front() const {
+ return value_.front();
+}
+
+char Blob::Back() const {
+ return value_.back();
+}
+
+char Blob::PopFront() {
+ char c = value_.front();
+ value_.pop_front();
+ return c;
+}
+
+char Blob::PopBack() {
+ char c = value_.back();
+ value_.pop_back();
+ return c;
+}
+
+void Blob::PushFront(char c) {
+ value_.push_front(c);
+}
+
+void Blob::PushBack(char c) {
+ value_.push_back(c);
+}
+
+void Blob::Clear() {
+ value_.clear();
+}
+
+std::string Blob::ToString() const {
+ std::string result;
+ for (size_t i = 0; i < Size(); i++)
+ result.append(1, value_[i]);
+ return result;
+}
+
+std::string Blob::ToHexString() const {
+ std::string result;
+ size_t num = Size();
+ for (size_t i = 0; i < num; i++) {
+ result.append(1, GetHexDigit(value_[i], 1));
+ result.append(1, GetHexDigit(value_[i], 0));
+ }
+ return result;
+}
+
+void Blob::Append(const Blob& blob) {
+ for (size_t i = 0; i < blob.Size(); i++)
+ PushBack(blob[i]);
+}
+
+bool Blob::Compare(const Blob& blob, size_t to_length) const {
+ if (-1 == to_length) {
+ if (Size() != blob.Size())
+ return false;
+ to_length = Size();
+ }
+ for (size_t i = 0; i < to_length; i++)
+ if (value_[i] != blob[i])
+ return false;
+ return true;
+}
+
+bool Blob::HasPrefix(const std::string& prefix) const {
+ size_t num = prefix.size();
+ if (Size() < num)
+ return false;
+ for (size_t i = 0; i < num; i++)
+ if (value_[i] != prefix[i])
+ return false;
+ return true;
+}
+
+void Blob::Reverse() {
+ std::reverse(value_.begin(), value_.end());
+}
+
+} // namespace debug

Powered by Google App Engine
This is Rietveld 408576698