third_party/krabsetw/krabs/krabs/guid.hpp
inline GUID guid_parser::parse_guid(const char* str, unsigned int length)
    {
        if (length != UUID_STRING_LENGTH)
        {
            std::stringstream message;
            message << "Input data has incorrect length. Expected "
                << UUID_STRING_LENGTH
                << ", got "
                << length;
            throw std::runtime_error(message.str());
        }

        GUID guid = { 0 };

        // Check that hyphens are in expected places as a formatting issue.
        if (str[STR_POSITION_DATA2 - 1] != DELIMITER ||
            str[STR_POSITION_DATA3 - 1] != DELIMITER ||
            str[STR_POSITION_DATA4_PART1 - 1] != DELIMITER ||
            str[STR_POSITION_DATA4_PART2 - 1] != DELIMITER)
        {
            throw std::runtime_error("Missing a hyphen where one was expected.");
        }

        // Use from_hex_string for Data1, Data2, and Data3 because of endianness of the data
        // Use hex_string_to_bytes for Data4's array elements because it's byte by byte instead
        auto success = guid_parser::hex_string_to_number(str + STR_POSITION_DATA1, guid.Data1)
            && guid_parser::hex_string_to_number(str + STR_POSITION_DATA2, guid.Data2)
            && guid_parser::hex_string_to_number(str + STR_POSITION_DATA3, guid.Data3)
            && guid_parser::hex_string_to_bytes(str + STR_POSITION_DATA4_PART1, reinterpret_cast<unsigned char*>(&guid.Data4[0]), 2)
            && guid_parser::hex_string_to_bytes(str + STR_POSITION_DATA4_PART2, reinterpret_cast<unsigned char*>(&guid.Data4[2]), 6);

        if (!success)
        {
            throw std::runtime_error("GUID string contains non-hex digits where hex digits are expected.");
        }

        return guid;
    }
/** <summary>
      * Parses GUID of "D" format. For example, the nil GUID would be "00000000-0000-0000-0000-000000000000".
      * See: https://docs.microsoft.com/en-us/dotnet/api/system.guid.tostring?view=netframework-4.8
      *
      * (str) must have at least (length) valid characters for memory safety. A null terminator is not
      * required. Instead, (length) is used for the bounds check.
      *
      * Returns the parsed GUID. Throws a std::runtime_error if there is a bounds error or format error.
      * 
      * This function is for performance, to help deal with container ID extended data, which has no null 
      * terminator, which would force us to clone the data to append a null terminator in order to use 
      * existing GUID parsing functions.
      * </summary>
      */

Parses GUID of "D" format.

(str) must have at least (length) valid characters for memory safety. A null terminator is not
required. Instead, (length) is used for the bounds check.

Returns the parsed GUID. Throws a std::runtime_error if there is a bounds error or format error.

This function is for performance, to help deal with container ID extended data, which has no null
terminator, which would force us to clone the data to append a null terminator in order to use
existing GUID parsing functions.
Parses GUID of " D " format . ( str ) must have at least ( length ) valid characters for memory safety . A null terminator is not required . Instead ( length ) is used for the bounds check . Returns the parsed GUID . Throws a std :: runtime_error if there is a bounds error or format error . This function is for performance to help deal with container ID extended data which has no null terminator which would force us to clone the data to append a null terminator in order to use existing GUID parsing functions .
inline GUID guid_parser::parse_guid(const char* str, unsigned int length)
    {
        if (length != UUID_STRING_LENGTH)
        {
            std::stringstream message;
            message << "Input data has incorrect length. Expected "
                << UUID_STRING_LENGTH
                << ", got "
                << length;
            throw std::runtime_error(message.str());
        }
        GUID guid = { 0 };
        if (str[STR_POSITION_DATA2 - 1] != DELIMITER ||
            str[STR_POSITION_DATA3 - 1] != DELIMITER ||
            str[STR_POSITION_DATA4_PART1 - 1] != DELIMITER ||
            str[STR_POSITION_DATA4_PART2 - 1] != DELIMITER)
        {
            throw std::runtime_error("Missing a hyphen where one was expected.");
        }
        auto success = guid_parser::hex_string_to_number(str + STR_POSITION_DATA1, guid.Data1)
            && guid_parser::hex_string_to_number(str + STR_POSITION_DATA2, guid.Data2)
            && guid_parser::hex_string_to_number(str + STR_POSITION_DATA3, guid.Data3)
            && guid_parser::hex_string_to_bytes(str + STR_POSITION_DATA4_PART1, reinterpret_cast<unsigned char*>(&guid.Data4[0]), 2)
            && guid_parser::hex_string_to_bytes(str + STR_POSITION_DATA4_PART2, reinterpret_cast<unsigned char*>(&guid.Data4[2]), 6);
        if (!success)
        {
            throw std::runtime_error("GUID string contains non-hex digits where hex digits are expected.");
        }
        return guid;
    }
inline GUID guid_parser :: parse_guid ( const char * str , unsigned int length ) { if ( length != UUID_STRING_LENGTH ) { std :: stringstream message ; message << " " << UUID_STRING_LENGTH << " " << length ; throw std :: runtime_error ( message . str ( ) ) ; } GUID guid = { 0 } ; if ( str [ STR_POSITION_DATA2 - 1 ] != DELIMITER || str [ STR_POSITION_DATA3 - 1 ] != DELIMITER || str [ STR_POSITION_DATA4_PART1 - 1 ] != DELIMITER || str [ STR_POSITION_DATA4_PART2 - 1 ] != DELIMITER ) { throw std :: runtime_error ( " " ) ; } auto success = guid_parser :: hex_string_to_number ( str + STR_POSITION_DATA1 , guid . Data1 ) && guid_parser :: hex_string_to_number ( str + STR_POSITION_DATA2 , guid . Data2 ) && guid_parser :: hex_string_to_number ( str + STR_POSITION_DATA3 , guid . Data3 ) && guid_parser :: hex_string_to_bytes ( str + STR_POSITION_DATA4_PART1 , reinterpret_cast < unsigned char * > ( & guid . Data4 [ 0 ] ) , 2 ) && guid_parser :: hex_string_to_bytes ( str + STR_POSITION_DATA4_PART2 , reinterpret_cast < unsigned char * > ( & guid . Data4 [ 2 ] ) , 6 ) ; if ( ! success ) { throw std :: runtime_error ( " " ) ; } return guid ; }
<summary>
 Parses GUID of "D" format.
<summary > Parses GUID of " D " format .
// Check that hyphens are in expected places as a formatting issue. // Use from_hex_string for Data1, Data2, and Data3 because of endianness of the data // Use hex_string_to_bytes for Data4's array elements because it's byte by byte instead