本文介绍了UUID格式:8-4-4-4-12 - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么UUID的格式是8-4-4-4-12(数字)?我已经找到了原因,但找不到要求它的决定。
$ b

格式为十六进制字符串的UUID示例:
58D5E212 -165B-4CA0-909B-C86B9CEE0111

解决方案

它由时间,版本,clock_seq_hi,clock_seq_lo,节点,如下面的rfc所示。



IETF RFC4122:

  4.1.2。布局和字节顺序

为了最大限度地减少字节内比特分配的混乱,UUID
记录定义只能用
八位字节的整数字段来定义。这些字段中首先显示的是
最重要的字段。

字段数据类型字节备注


time_low无符号32 0-3
位整数时间戳
$ b的低字段$ b time_mid无符号16 4-5
位整数时间戳的中间字段

time_hi_and_version无符号16 6-7
位的整数时间戳复用
版本号

clock_seq_hi_and_rese无符号8 8



$ b $复合的
位整数时钟序列
的高位字段

clock_seq_low无符号8 9
的低字段位整数时钟序列

节点无符号48 10-15空间唯一的
位整数节点标识符

在没有显式的应用程序或表示协议
规范相反,UUID被编码为128位对象
,如下所示:

这些字段被编码为16个八位位组,其大小和顺序为
上面定义的字段,并且每个字段先用Most
重要字节编码(称为网络字节顺序)。请注意,
字段名称,尤其是复用字段,遵循历史
练习。

0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +
| time_low |
+ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +
| time_mid | time_hi_and_version |
+ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +
| clk_seq_hi_res | clk_seq_low |节点(0-1)|
+ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +
|节点(2-5)|
+ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +


Why are UUID's presented in the format "8-4-4-4-12" (digits)? I've had a look around for the reason but can't find the decision that calls for it.

Example of UUID formatted as hex string:58D5E212-165B-4CA0-909B-C86B9CEE0111

It's separated by time, version, clock_seq_hi, clock_seq_lo, node, as indicated in the followoing rfc.

From the IETF RFC4122:

4.1.2.  Layout and Byte Order

   To minimize confusion about bit assignments within octets, the UUID
   record definition is defined only in terms of fields that are
   integral numbers of octets.  The fields are presented with the most
   significant one first.

   Field                  Data Type     Octet  Note
                                        #

   time_low               unsigned 32   0-3    The low field of the
                          bit integer          timestamp

   time_mid               unsigned 16   4-5    The middle field of the
                          bit integer          timestamp

   time_hi_and_version    unsigned 16   6-7    The high field of the
                          bit integer          timestamp multiplexed
                                               with the version number

   clock_seq_hi_and_rese  unsigned 8    8      The high field of the
   rved                   bit integer          clock sequence
                                               multiplexed with the
                                               variant

   clock_seq_low          unsigned 8    9      The low field of the
                          bit integer          clock sequence

   node                   unsigned 48   10-15  The spatially unique
                          bit integer          node identifier

   In the absence of explicit application or presentation protocol
   specification to the contrary, a UUID is encoded as a 128-bit object,
   as follows:

   The fields are encoded as 16 octets, with the sizes and order of the
   fields defined above, and with each field encoded with the Most
   Significant Byte first (known as network byte order).  Note that the
   field names, particularly for multiplexed fields, follow historical
   practice.

   0                   1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                          time_low                             |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |       time_mid                |         time_hi_and_version   |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |clk_seq_hi_res |  clk_seq_low  |         node (0-1)            |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                         node (2-5)                            |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

这篇关于UUID格式:8-4-4-4-12 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 16:34