ネットワーク (またはファイル ストレージ) 経由で送信するために UUID をバイト スワップする標準的な方法はありますか? (UUID を文字列表現に変換するのではなく、生の 16 バイトを送信/保存したい。)
最初は、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... が反対側で読み取り後に呼び出されますか?
ありがとう。