时有到字节交换的UUID为通过网络传输(或文件存储)的标准接受的方法? (我要发送/存储16的原始字节,而不是UUID转换为字符串表示。)

我想在第一I应的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 */
....

写作之前,然后correpsonding NTOH ...调用另一端看完之后?

感谢。

有帮助吗?

解决方案

是的,这是做正确的事。

每个数(time_lowtime_midtime_hi_and_version)受到字节排序。该node字段不是。 clock_seq_hi_and_reservedclock_seq_low也受到字节排序,但它们是每一个字节,所以它并不重要。

当然,它是由你来确保你选择两端的正确顺序,或者了解的排序上,另一端是什么,如果你不控制它。当然,微软使用自己的UUID小端。你可以在这里看到一个UUID 微软的定义

scroll top