Index: third_party/mojo/src/mojo/edk/system/unique_identifier.cc |
diff --git a/third_party/mojo/src/mojo/edk/system/unique_identifier.cc b/third_party/mojo/src/mojo/edk/system/unique_identifier.cc |
index 11e482b64b52728ea0aaf3641bef92f3d08f2398..6e036c81f0c3762466510027e9b7952465292429 100644 |
--- a/third_party/mojo/src/mojo/edk/system/unique_identifier.cc |
+++ b/third_party/mojo/src/mojo/edk/system/unique_identifier.cc |
@@ -4,7 +4,9 @@ |
#include "mojo/edk/system/unique_identifier.h" |
-#include <ostream> |
+#include <stdint.h> |
+ |
+#include <vector> |
#include "base/strings/string_number_conversions.h" |
#include "mojo/edk/embedder/platform_support.h" |
@@ -12,12 +14,6 @@ |
namespace mojo { |
namespace system { |
-std::ostream& operator<<(std::ostream& out, |
- const UniqueIdentifier& unique_identifier) { |
- return out << base::HexEncode(unique_identifier.data_, |
- sizeof(unique_identifier.data_)); |
-} |
- |
// static |
UniqueIdentifier UniqueIdentifier::Generate( |
embedder::PlatformSupport* platform_support) { |
@@ -26,5 +22,24 @@ UniqueIdentifier UniqueIdentifier::Generate( |
return rv; |
} |
+// static |
+UniqueIdentifier UniqueIdentifier::FromString(const std::string& s, |
+ bool* success) { |
+ UniqueIdentifier rv; |
+ std::vector<uint8_t> bytes; |
+ if (base::HexStringToBytes(s, &bytes) && bytes.size() == sizeof(rv.data_)) { |
+ memcpy(rv.data_, &bytes[0], sizeof(rv.data_)); |
+ *success = true; |
+ } else { |
+ *success = false; |
+ } |
+ return rv; |
+} |
+ |
+std::string UniqueIdentifier::ToString() const { |
+ // TODO(vtl): Maybe we should base-64 encode instead? |
+ return base::HexEncode(data_, sizeof(data_)); |
+} |
+ |
} // namespace system |
} // namespace mojo |