1
是否有標準接受的方式來通過網絡(或文件存儲)傳輸字節交換UUID? (我想發送/存儲16個原始字節,而不是將UUID轉換爲字符串表示形式。)通過網絡傳輸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 */
....
寫入之前,然後correpsonding NTOH ......在另一端閱讀後調用?
謝謝。
謝謝。我控制兩端。我將在內部選擇主機排序,因此如果將time_low初始化爲little endian上的0x01020304並通過網絡發送,則在另一端的big-endian上的值仍將爲0x01020304。 – 2009-07-23 13:37:50