OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Native Client 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 #ifndef EXPERIMENTAL_LINUX_OOP_DEBUGGER_DEBUG_BLOB_H_ | |
5 #define EXPERIMENTAL_LINUX_OOP_DEBUGGER_DEBUG_BLOB_H_ | |
6 | |
7 #include <deque> | |
8 #include <string> | |
9 | |
10 // Class for working with raw binary data. | |
11 | |
12 typedef unsigned char byte; | |
13 | |
14 namespace debug { | |
15 class Blob { | |
16 public: | |
17 Blob(); | |
18 Blob(const Blob& other); | |
19 Blob(const void* buff, size_t buff_sz); | |
20 Blob(const char* buff); // NOLINT: I want type conversion. | |
21 virtual ~Blob(); | |
22 Blob& operator = (const Blob& other); | |
23 bool operator == (const Blob& other) const; | |
24 | |
25 size_t Size() const; | |
26 byte operator[] (size_t position) const; | |
27 byte Front() const; // Returns first byte. | |
28 byte Back() const; // Returns last byte. | |
29 byte PopFront(); // Delete first byte. | |
30 byte PopBack(); // Delete last byte. | |
31 void PushFront(byte c); // Insert byte at beginning. | |
32 void PushBack(byte c); // Add byte at the end. | |
33 void Append(const Blob& other); | |
34 void Clear(); | |
35 | |
36 std::string ToString() const; | |
37 std::string ToHexString(bool remove_leading_zeroes = true) const; | |
38 bool LoadFromHexString(const std::string& hex_str); | |
39 bool LoadFromHexString(const Blob& hex_str); | |
40 int ToInt() const; | |
41 void* ToCBuffer() const; | |
42 | |
43 void Reverse(); | |
44 bool Compare(const Blob& blob, size_t to_length = -1) const; | |
45 bool HasPrefix(const std::string& prefix) const; | |
46 | |
47 void Split(const char* delimiters, std::deque<Blob>* tokens) const; | |
48 | |
49 static bool HexCharToInt(byte c, unsigned int* result); | |
50 | |
51 protected: | |
52 std::deque<byte> value_; | |
53 }; | |
54 | |
55 class BlobUniTest { | |
56 public: | |
57 BlobUniTest(); | |
58 int Run(std::string* error); // returns 0 if success, error code if failed. | |
59 }; | |
60 } // namespace debug | |
61 #endif // EXPERIMENTAL_LINUX_OOP_DEBUGGER_DEBUG_BLOB_H_ | |
62 | |
OLD | NEW |