OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "util/misc/uuid.h" | 15 #include "util/misc/uuid.h" |
16 | 16 |
17 #include <string.h> | 17 #include <string.h> |
18 | 18 |
19 #include "base/basictypes.h" | 19 #include "base/basictypes.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "util/stdlib/cxx.h" | 21 #include "base/sys_byteorder.h" |
22 | |
23 #if CXX_LIBRARY_VERSION >= 2011 | |
24 #include <type_traits> | |
25 #endif | |
26 | 22 |
27 namespace crashpad { | 23 namespace crashpad { |
28 | 24 |
29 #if CXX_LIBRARY_VERSION >= 2011 | 25 UUID::UUID() : data_1(0), data_2(0), data_3(0), data_4(), data_5() { |
30 COMPILE_ASSERT(std::is_standard_layout<UUID>::value, | |
31 UUID_must_be_standard_layout); | |
32 #endif | |
33 | |
34 UUID::UUID() : data() { | |
35 } | 26 } |
36 | 27 |
37 UUID::UUID(const uint8_t* bytes) { | 28 UUID::UUID(const uint8_t* bytes) { |
38 memcpy(data, bytes, sizeof(data)); | 29 InitializeFromBytes(bytes); |
| 30 } |
| 31 |
| 32 void UUID::InitializeFromBytes(const uint8_t* bytes) { |
| 33 memcpy(this, bytes, sizeof(*this)); |
| 34 data_1 = base::NetToHost32(data_1); |
| 35 data_2 = base::NetToHost16(data_2); |
| 36 data_3 = base::NetToHost16(data_3); |
39 } | 37 } |
40 | 38 |
41 std::string UUID::ToString() const { | 39 std::string UUID::ToString() const { |
42 return base::StringPrintf( | 40 return base::StringPrintf("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", |
43 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", | 41 data_1, |
44 data[0], | 42 data_2, |
45 data[1], | 43 data_3, |
46 data[2], | 44 data_4[0], |
47 data[3], | 45 data_4[1], |
48 data[4], | 46 data_5[0], |
49 data[5], | 47 data_5[1], |
50 data[6], | 48 data_5[2], |
51 data[7], | 49 data_5[3], |
52 data[8], | 50 data_5[4], |
53 data[9], | 51 data_5[5]); |
54 data[10], | |
55 data[11], | |
56 data[12], | |
57 data[13], | |
58 data[14], | |
59 data[15]); | |
60 } | 52 } |
61 | 53 |
62 } // namespace crashpad | 54 } // namespace crashpad |
OLD | NEW |