ObjFW  Check-in [7d94c3ed89]

Overview
Comment:OFUUID: -[initWithUUIDBytes:] & -[getUUIDBytes:]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7d94c3ed898c0d16b758134431b02121aecf942a9e6f8a443b6aa9ac656f73a5
User & Date: js on 2021-10-18 00:02:52
Other Links: manifest | tags
Context
2021-10-22
21:40
OFUUID: Add -[initWithUUIDString:] check-in: 02005b54f1 user: js tags: trunk
2021-10-18
00:02
OFUUID: -[initWithUUIDBytes:] & -[getUUIDBytes:] check-in: 7d94c3ed89 user: js tags: trunk
2021-10-17
19:46
Name GitHub Actions that don't run tests "build" check-in: 585c79c2d2 user: js tags: trunk
Changes

Modified src/OFUUID.h from [a7ccfa8276] to [646e59f09e].

44
45
46
47
48
49
50








51
52
53
54
55
56
57







58
59
60
 * @brief Initializes an already allocated OFUUID as a new random UUID as per
 *	  RFC 4122 version 4.
 *
 * @return An initialized OFUUID
 */
- (instancetype)init;









/**
 * @brief Compares the UUID to another UUID.
 *
 * @param UUID The UUID to compare to
 * @return The result of the comparison
 */
- (OFComparisonResult)compare: (OFUUID *)UUID;







@end

OF_ASSUME_NONNULL_END







>
>
>
>
>
>
>
>







>
>
>
>
>
>
>



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 * @brief Initializes an already allocated OFUUID as a new random UUID as per
 *	  RFC 4122 version 4.
 *
 * @return An initialized OFUUID
 */
- (instancetype)init;

/**
 * @brief Initializes an already allocated OFUUID with the specified bytes.
 *
 * @param bytes The bytes to initialize the OFUUID with
 * @return An initialized OFUUID
 */
- (instancetype)initWithUUIDBytes: (const unsigned char [_Nonnull 16])bytes;

/**
 * @brief Compares the UUID to another UUID.
 *
 * @param UUID The UUID to compare to
 * @return The result of the comparison
 */
- (OFComparisonResult)compare: (OFUUID *)UUID;

/**
 * @brief Gets the bytes of the UUID.
 *
 * @param bytes An array of 16 bytes into which to write the UUID
 */
- (void)getUUIDBytes: (unsigned char [_Nonnull 16])bytes;
@end

OF_ASSUME_NONNULL_END

Modified src/OFUUID.m from [da8220fbff] to [d01fab39d1].

40
41
42
43
44
45
46









47
48
49
50
51
52
53
	_bytes[6] &= ~((1 << 7) | (1 << 5) | (1 << 4));
	_bytes[6] |= (1 << 6);
	_bytes[8] &= ~(1 << 6);
	_bytes[8] |= (1 << 7);

	return self;
}










- (bool)isEqual: (id)object
{
	OFUUID *UUID;

	if (![object isKindOfClass: [OFUUID class]])
		return false;







>
>
>
>
>
>
>
>
>







40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
	_bytes[6] &= ~((1 << 7) | (1 << 5) | (1 << 4));
	_bytes[6] |= (1 << 6);
	_bytes[8] &= ~(1 << 6);
	_bytes[8] |= (1 << 7);

	return self;
}

- (instancetype)initWithUUIDBytes: (const unsigned char [16])bytes
{
	self = [super init];

	memcpy(_bytes, bytes, sizeof(_bytes));

	return self;
}

- (bool)isEqual: (id)object
{
	OFUUID *UUID;

	if (![object isKindOfClass: [OFUUID class]])
		return false;
87
88
89
90
91
92
93





94
95
96
97
98
99
100
		return OFOrderedSame;

	if (comparison > 0)
		return OFOrderedDescending;
	else
		return OFOrderedAscending;
}






- (OFString *)UUIDString
{
	return [OFString stringWithFormat:
	    @"%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-"
	    @"%02X%02X%02X%02X%02X%02X",
	    _bytes[0], _bytes[1], _bytes[2], _bytes[3],







>
>
>
>
>







96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
		return OFOrderedSame;

	if (comparison > 0)
		return OFOrderedDescending;
	else
		return OFOrderedAscending;
}

- (void)getUUIDBytes: (unsigned char [16])bytes
{
	memcpy(bytes, _bytes, sizeof(_bytes));
}

- (OFString *)UUIDString
{
	return [OFString stringWithFormat:
	    @"%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-"
	    @"%02X%02X%02X%02X%02X%02X",
	    _bytes[0], _bytes[1], _bytes[2], _bytes[3],