Chromium Code Reviews| Index: net/der/input.h |
| diff --git a/net/der/input.h b/net/der/input.h |
| index 3772d0df927f9b93b2587802ebbddf0dfcfa870d..695e153e80bb656fba556c9883a1bab60bab42a1 100644 |
| --- a/net/der/input.h |
| +++ b/net/der/input.h |
| @@ -11,6 +11,7 @@ |
| #include <string> |
| #include "base/compiler_specific.h" |
| +#include "base/strings/string_piece.h" |
| #include "net/base/net_export.h" |
| namespace net { |
| @@ -51,6 +52,14 @@ class NET_EXPORT_PRIVATE Input { |
| // Creates an Input from the given |data| and |len|. |
| Input(const uint8_t* data, size_t len); |
| + // Creates an Input from a base::StringPiece. |
| + Input(const base::StringPiece& sp); |
|
eroman
2016/01/13 22:54:00
Mark as explicit
nharper
2016/01/13 23:04:47
Done.
|
| + |
| + // Creates an Input from a std::string. The lifetimes are a bit subtle when |
| + // using this function: The constructed Input is only valid so long as |s| is |
| + // still alive and not mutated. |
| + Input(const std::string* s); |
|
eroman
2016/01/13 22:54:00
explicit
nharper
2016/01/13 23:04:48
Done.
|
| + |
| // Returns the length in bytes of an Input's data. |
| size_t Length() const { return len_; } |
| @@ -66,7 +75,17 @@ class NET_EXPORT_PRIVATE Input { |
| // Returns a copy of the data represented by this object as a std::string. |
| std::string AsString() const; |
| + // Returns a StringPiece pointing to the same data as the Input. The resulting |
| + // StringPiece cannot outlive the data that was used to construct this Input. |
|
eroman
2016/01/13 22:54:00
nit: cannot --> must not
nharper
2016/01/13 23:04:48
Done.
|
| + base::StringPiece AsStringPiece() const; |
| + |
| private: |
| + // This constructor is deleted to prevent constructing an Input from a |
| + // std::string r-value. Since the Input points to memory owned by another |
| + // object, such an Input would point to invalid memory. Without this deleted |
| + // constructor, a std::string could be passed in to the base::StringPiece |
| + // constructor because of StringPiece's implicit constructor. |
| + Input(std::string) = delete; |
|
eroman
2016/01/13 22:54:00
Does this need to be const std::string& ?
nharper
2016/01/13 23:04:47
I tested the following, and they all failed to com
eroman
2016/01/13 23:21:06
Sounds good. My only other test suggestions would
|
| const uint8_t* data_; |
| size_t len_; |
| }; |