Skip to content

Commit 28d1cb4

Browse files
nkarstensdlech
authored andcommitted
pbio/util: Add UUID little endian copy function.
Add function to copy UUIDs in little endian format. USB is a little endian protocol, so this will be used to encode UUIDs properly on this medium. Signed-off-by: Nate Karstens <[email protected]>
1 parent f4f9d99 commit 28d1cb4

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/pbio/include/pbio/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ void pbio_set_uint32_be(uint8_t *buf, uint32_t value) {
118118
buf[3] = value;
119119
}
120120

121+
void pbio_uuid128_le_copy(uint8_t *dst, const uint8_t *src);
121122
bool pbio_uuid128_reverse_compare(const uint8_t *uuid1, const uint8_t *uuid2);
122123
void pbio_uuid128_reverse_copy(uint8_t *dst, const uint8_t *src);
123124

lib/pbio/src/util.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,35 @@
33

44
#include <stdbool.h>
55
#include <stdint.h>
6+
#include <string.h>
7+
8+
/**
9+
* Copies a 128-bit UUID from @p src to a buffer @p dst,
10+
* which is a buffer used by a little endian medium.
11+
*
12+
* According to RFC 4122, the UUID is grouped into the following:
13+
* 1) One 32-bit
14+
* 2) Two 16-bit
15+
* 3) Eight 8-bit
16+
*
17+
* @param [in] dst The destination that will receive the
18+
* resulting little-endian-formatted UUID.
19+
* @param [in] src The UUID in host byte order.
20+
*/
21+
void pbio_uuid128_le_copy(uint8_t *dst, const uint8_t *src) {
22+
dst[0] = src[3];
23+
dst[1] = src[2];
24+
dst[2] = src[1];
25+
dst[3] = src[0];
26+
27+
dst[4] = src[5];
28+
dst[5] = src[4];
29+
30+
dst[6] = src[7];
31+
dst[7] = src[6];
32+
33+
memcpy(&dst[8], &src[8], 8);
34+
}
635

736
/**
837
* Compares two 128-bit UUIDs with opposite byte ordering for equality.

0 commit comments

Comments
 (0)