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 #ifndef CRASHPAD_UTIL_MISC_UUID_H_ | 15 #ifndef CRASHPAD_UTIL_MISC_UUID_H_ |
16 #define CRASHPAD_UTIL_MISC_UUID_H_ | 16 #define CRASHPAD_UTIL_MISC_UUID_H_ |
17 | 17 |
18 #include <stdint.h> | 18 #include <stdint.h> |
19 | 19 |
20 #include <string> | 20 #include <string> |
21 | 21 |
22 namespace crashpad { | 22 namespace crashpad { |
23 | 23 |
24 //! \brief A universally unique identifier (%UUID). | 24 //! \brief A universally unique identifier (%UUID). |
25 //! | 25 //! |
26 //! An alternate term for %UUID is “globally unique identifier” (GUID), used | 26 //! An alternate term for %UUID is “globally unique identifier” (GUID), used |
27 //! primarily by Microsoft. | 27 //! primarily by Microsoft. |
28 //! | 28 //! |
29 //! A %UUID is a unique 128-bit number specified by RFC 4122. | 29 //! A %UUID is a unique 128-bit number specified by RFC 4122. |
30 //! | |
31 //! This is a standard-layout structure, and it is acceptable to use `memcpy()` | |
32 //! to set its value. | |
33 struct UUID { | 30 struct UUID { |
34 //! \brief Initializes the %UUID to zero. | 31 //! \brief Initializes the %UUID to zero. |
35 UUID(); | 32 UUID(); |
36 | 33 |
| 34 //! \copydoc InitializeFromBytes() |
| 35 explicit UUID(const uint8_t* bytes); |
| 36 |
37 //! \brief Initializes the %UUID from a sequence of bytes. | 37 //! \brief Initializes the %UUID from a sequence of bytes. |
38 //! | 38 //! |
| 39 //! \a bytes is taken as a %UUID laid out in big-endian format in memory. On |
| 40 //! little-endian machines, appropriate byte-swapping will be performed to |
| 41 //! initialize an object’s data members. |
| 42 //! |
39 //! \param[in] bytes A buffer of exactly 16 bytes that will be assigned to the | 43 //! \param[in] bytes A buffer of exactly 16 bytes that will be assigned to the |
40 //! %UUID. | 44 //! %UUID. |
41 explicit UUID(const uint8_t* bytes); | 45 void InitializeFromBytes(const uint8_t* bytes); |
42 | 46 |
43 //! \brief Formats the %UUID per RFC 4122 §3. | 47 //! \brief Formats the %UUID per RFC 4122 §3. |
44 //! | 48 //! |
45 //! \return A string of the form `"00112233-4455-6677-8899-aabbccddeeff"`. | 49 //! \return A string of the form `"00112233-4455-6677-8899-aabbccddeeff"`. |
46 std::string ToString() const; | 50 std::string ToString() const; |
47 | 51 |
48 uint8_t data[16]; | 52 // These fields are laid out according to RFC 4122 §4.1.2. |
| 53 uint32_t data_1; |
| 54 uint16_t data_2; |
| 55 uint16_t data_3; |
| 56 uint8_t data_4[2]; |
| 57 uint8_t data_5[6]; |
49 }; | 58 }; |
50 | 59 |
51 } // namespace crashpad | 60 } // namespace crashpad |
52 | 61 |
53 #endif // CRASHPAD_UTIL_MISC_UUID_H_ | 62 #endif // CRASHPAD_UTIL_MISC_UUID_H_ |
OLD | NEW |