是否有标准可接受的方式来字节交换 UUID 以通过网络(或文件存储)传输?(我想发送/存储 16 个原始字节,而不是将 UUID 转换为字符串表示形式。)
起初我想我应该将 UUID 划分为 4 个 32 位整数并在每个整数上调用 htonl,但这听起来不对。UUID 具有内部结构(来自 RFC 4122):
typedef struct {
unsigned32 time_low;
unsigned16 time_mid;
unsigned16 time_hi_and_version;
unsigned8 clock_seq_hi_and_reserved;
unsigned8 clock_seq_low;
byte node[6];
} uuid_t;
这样做是否正确:
...
uuid.time_low = htonl( uuid.time_low );
uuid.time_mid = htons( uuid.time_mid );
uuid.time_hi_and_version = htons( uuid.time_high_and_version );
/* other fields are represented as bytes and shouldn't be swapped */
....
写之前,然后对应的ntoh...在另一端读后调用?
谢谢。