GUID 和 UUID 之间有什么区别吗?

发布于 2024-07-07 21:57:10 字数 49 浏览 5 评论 0原文

我看到这两个缩写词被到处乱扔,我想知道 GUID 和 UUID 之间是否有任何区别?

I see these two acronyms being thrown around and I was wondering if there are any differences between a GUID and a UUID?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

埋情葬爱 2024-07-14 21:57:10

简单的答案是:没有区别,它们是同一件事。

对于大多数实际用途,请将它们视为用作唯一标识符的 16 字节(128 位)值。 在 Microsoft 语言中,它们称为 GUID,但在不使用 Microsoft 语言时,称为 UUID。

甚至 UUID 规范的作者和 Microsoft 也声称它们是同义词:

详细答案

但是正确答案是“视情况而定”。 这取决于问题说“UUID”时的含义……

第一部分取决于提问者说“UUID”时的想法。

Microsoft 的声明暗示所有 UUID 都是 GUID。 但所有 GUID 都是真正的 UUID 吗? 也就是说,所有 UUID 的集合只是所有 GUID 集合的真子集,还是完全相同的集合?

查看 RFC 4122 的详细信息,UUID 有四种不同的“变体”。 这主要是因为在创建 UUID 规范时将这些规范合并在一起之前就已经使用了此类 16 字节标识符。 从 RFC 4122 的第 4.1.1 节中,四个变体 UUID 包括:

  1. 保留,网络计算系统向后兼容性
  2. RFC 4122 中指定的变体(其中有五个子变体,称为“版本”)
  3. 保留,Microsoft Corporation 向后兼容性
  4. 为将来保留定义。

根据 RFC 4122,所有 UUID 变体都是“真实 UUID”,那么所有 GUID 都是真实 UUID。 对于字面上的问题“GUID 和 UUID 之间有什么区别”,对于 RFC 4122 UUID 来说答案肯定是否定的:没有区别(但受下面第二部分的约束)。

但并非所有 GUID 都是变体 2 UUID(例如,Microsoft COM 的 GUID 是变体 3 UUID)。 如果问题是“GUID 和变体 2 UUID 之间有什么区别”,那么答案是肯定的——它们可以不同。 提出问题的人可能不知道变体,当他们说“UUID”这个词时,他们可能只想到变体 2个UUID(例如,他们模糊地知道MAC 地址+时间和 UUID 的随机数算法形式,都是 变体 2) 的版本。 在这种情况下,答案是是不同

因此,答案部分取决于提问者在说出“UUID”一词时的想法。 他们是指变体 2 UUID(因为这是他们知道的唯一变体)还是所有 UUID?

第二部分取决于使用哪个规范作为 UUID 的定义。

如果您认为这令人困惑,请阅读 ITU-T X.667 ISO/ IEC 9834-8:2004 应该与 RFC 4122 保持一致并在技术上完全兼容。 第 11.2 条中有一个额外的句子:“符合本建议书 | 国际标准的所有 UUID 应具有变体位,其中第 7 个八位字节的第 7 位设置为 1,第 7 个八位字节的第 6 位设置为 0”。 这意味着只有 variant 2 UUID 符合该标准(这两个位值意味着 variant 2)。 如果这是真的,则并非所有 GUID 都符合 ITU-T/ISO/IEC UUID,因为符合 ITU-T/ISO/IEC UUID 只能是变体 2 值。

因此,真正的答案还取决于问题所询问的 UUID 规范。 假设我们明确讨论的是所有 UUID,而不仅仅是变体 2 UUID:GUID 和 IETF 的 UUID 之间没有区别,但 GUID 与一致<之间有区别 /em> ITU-T/ISO/IEC 的 UUID!

实用说明

以上信息并未详细介绍 UUID/GUID 值或如何获取/生成它们。 但对于价值观有两个误解需要澄清。

1. UUID/GUID的表示

首先,同一个UUID/GUID是一个16字节(128位)的值,可以用不同的方式表示。

在内存或存储中,它可以紧凑地表示为二进制数据。 例如,它可以表示为十六个字节的数组、八个16位字或四个32位整数; 已签名或未签名。 使用单词或整数时,字节序很重要。

在文本或字符串中,它通常以带有连字符的十六进制表示:

hhhhhhhh-hhhh-Yhhh-Xhhh-hhhhhhhhhhhh

其中 h、X 和 Y 是十六进制字符。

某些程序可能只接受大写字符,或只接受小写字符 — 即使大小写对于 UUID/GUID 的值并不重要。 某些程序可能要求省略连字符或仅在这些位置出现连字符 — 即使连字符对于 UUID/GUID 的值并不重要。

连字符的位置反映了基于时间的 UUID 版本:分隔各种时间、时钟和 MAC 地址字段。 显然,当涉及到其他版本的 UUID 时,这些字段没有意义。 但是,按照惯例,连字符的这些位置仍然被使用。

2. 字节解释

其次,始终使用库来生成 UUID/GUID。 生成 16 个随机字节并不能保证有效的 UUID/GUID。 即使使用版本 4 UUID,某些字节也必须具有特定值。

在上面的十六进制字符串模板中,位置 X 中的三位十六进制字符对 UUID 的变体进行编码。 对于 RFC 4122 中定义的变体,X 将为 8、9、A 或 B。

如果 UUID 是 RFC 4122 变体,则位置 Y 中的十六进制字符表示的位将对其 进行编码>版本。 例如,4 表示版本 4。

随机生成 16 个字节并不能保证这些字节在这两个字段中具有正确的值。

有关完整详细信息,请参阅 RFC 4122。 但通常你不需要知道它们的内部结构。 如果您只是使用给定的值,只需将它们视为用作唯一标识符的 16 字节(128 位)值。

The simple answer is: no difference, they are the same thing.

For most practical purposes, treat them as 16 byte (128 bits) values that are used as a unique identifier. In Microsoft-speak they are called GUIDs, but call them UUIDs when not using Microsoft-speak.

Even the authors of the UUID specification and Microsoft claim they are synonyms:

  • From the introduction to IETF RFC 4122 "A Universally Unique IDentifier (UUID) URN Namespace": "a Uniform Resource Name namespace for UUIDs (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDentifier)."

  • From the ITU-T Recommendation X.667, ISO/IEC 9834-8:2004 International Standard: "UUIDs are also known as Globally Unique Identifiers (GUIDs), but this term is not used in this Recommendation."

  • And Microsoft even claims a GUID is specified by the UUID RFC: "In Microsoft Windows programming and in Windows operating systems, a globally unique identifier (GUID), as specified in [RFC4122], is ... The term universally unique identifier (UUID) is sometimes used in Windows protocol specifications as a synonym for GUID."

Detailed answer

But the correct answer is "it depends". It depends on what the question means when it says "UUID"...

The first part depends on what the asker is thinking when they are saying "UUID".

Microsoft's claim implies that all UUIDs are GUIDs. But are all GUIDs real UUIDs? That is, is the set of all UUIDs just a proper subset of the set of all GUIDs, or is it the exact same set?

Looking at the details of the RFC 4122, there are four different "variants" of UUIDs. This is mostly because such 16 byte identifiers were in use before those specifications were brought together in the creation of a UUID specification. From section 4.1.1 of RFC 4122, the four variants of UUID are:

  1. Reserved, Network Computing System backward compatibility
  2. The variant specified in RFC 4122 (of which there are five sub-variants, which are called "versions")
  3. Reserved, Microsoft Corporation backward compatibility
  4. Reserved for future definition.

According to RFC 4122, all UUID variants are "real UUIDs", then all GUIDs are real UUIDs. To the literal question "is there any difference between GUID and UUID" the answer is definitely no for RFC 4122 UUIDs: no difference (but subject to the second part below).

But not all GUIDs are variant 2 UUIDs (e.g. Microsoft COM has GUIDs which are variant 3 UUIDs). If the question was "is there any difference between GUID and variant 2 UUIDs", then the answer would be yes -- they can be different. Someone asking the question probably doesn't know about variants and they might be only thinking of variant 2 UUIDs when they say the word "UUID" (e.g. they vaguely know of the MAC address+time and the random number algorithms forms of UUID, which are both versions of variant 2). In which case, the answer is yes different.

So the answer, in part, depends on what the person asking is thinking when they say the word "UUID". Do they mean variant 2 UUID (because that is the only variant they are aware of) or all UUIDs?

The second part depends on which specification being used as the definition of UUID.

If you think that was confusing, read the ITU-T X.667 ISO/IEC 9834-8:2004 which is supposed to be aligned and fully technically compatible with RFC 4122. It has an extra sentence in Clause 11.2 that says, "All UUIDs conforming to this Recommendation | International Standard shall have variant bits with bit 7 of octet 7 set to 1 and bit 6 of octet 7 set to 0". Which means that only variant 2 UUID conform to that Standard (those two bit values mean variant 2). If that is true, then not all GUIDs are conforming ITU-T/ISO/IEC UUIDs, because conformant ITU-T/ISO/IEC UUIDs can only be variant 2 values.

Therefore, the real answer also depends on which specification of UUID the question is asking about. Assuming we are clearly talking about all UUIDs and not just variant 2 UUIDs: there is no difference between GUID and IETF's UUIDs, but yes difference between GUID and conforming ITU-T/ISO/IEC's UUIDs!

Practical notes

The information above does not go into the details of the UUID/GUID values, or how you get/generate them. But there are two misconceptions about the values that should be cleared up.

1. Representation of UUID/GUIDs

Firstly, the same UUID/GUID is a 16 bytes (128 bits) value that can be represented in different ways.

In memory or storage, it can be represented compactly as binary data. For example, it can be represented as an array of sixteen bytes, eight 16-bit words, or four 32-bit integers; signed or unsigned. The endian is significant when using words or integers.

In text or strings, it is commonly represented in hexadecimal with hyphens:

hhhhhhhh-hhhh-Yhhh-Xhhh-hhhhhhhhhhhh

where h, X and Y are hexadecimal characters.

Some programs might only accept uppercase characters, or only lowercase characters---even though the case is not significant to the value of the UUID/GUID. Some programs might require the hyphens to be omitted or to be present only in those positions---even though the hyphens are not significant to the value of the UUID/GUID.

The positions of the hyphens reflect the time-based version of UUIDs: separating the various time, clock and MAC address fields. Obviously, those fields don't have meaning when it comes to the other version of UUIDs. But, by convention, those positions of the hyphens are still used.

2. Interpretation of the bytes

Secondly, always use a library to generate a UUID/GUID. Generating 16 random bytes does not guarantee a valid UUID/GUID. Even when using a version 4 UUID, some of the bytes must have specific values.

In the above hexadecimal string template, three bits of the hexadecimal character in position X encodes the UUID's variant. For the variant defined in RFC 4122, X will be either 8, 9, A or B.

If the UUID is an RFC 4122 variant, the bits represented by the hexadecimal character in position Y encode its version. For example, 4 indicates a version 4.

Randomly generating 16 bytes would not guarantee the bytes would have the correct values in those two fields.

For the full details, see RFC 4122. But normally you don't need to know their internal structure. If you are just using values you have been given, just treat them as 16 byte (128 bits) values that are used as a unique identifier.

腻橙味 2024-07-14 21:57:10

GUID 是 Microsoft 对 UUID 标准的实现。

根据 维基百科

术语“GUID”通常指 Microsoft 对通用唯一标识符 (UUID) 标准的实现。

来自同一篇维基百科文章的更新引用:

RFC 4122 本身指出 UUID“也称为 GUID”。 所有这些都表明“GUID”虽然最初指的是 Microsoft 使用的 UUID 的变体,但现在已成为 UUID 的替代名称......

GUID is Microsoft's implementation of the UUID standard.

Per Wikipedia:

The term GUID usually refers to Microsoft's implementation of the Universally Unique Identifier (UUID) standard.

An updated quote from that same Wikipedia article:

RFC 4122 itself states that UUIDs "are also known as GUIDs". All this suggests that "GUID", while originally referring to a variant of UUID used by Microsoft, has become simply an alternative name for UUID…

孤芳又自赏 2024-07-14 21:57:10

并不真地。 GUID 更以 Microsoft 为中心,而 UUID 的使用更广泛(例如,在 urn:uuid: URN 方案和 CORBA 中)。

Not really. GUID is more Microsoft-centric whereas UUID is used more widely (e.g., as in the urn:uuid: URN scheme, and in CORBA).

治碍 2024-07-14 21:57:10

GUID has longstanding usage in areas where it isn't necessarily a 128-bit value in the same way as a UUID. For example, the RSS specification defines GUIDs to be any string of your choosing, as long as it's unique, with an "isPermalink" attribute to specify that the value you're using is just a permalink back to the item being syndicated.

桃扇骨 2024-07-14 21:57:10

SQL Server 中的 GUID 和 PostgreSQL 中的 UUID 之间的一个区别是字母大小写; SQL Server 输出上限,而 PostgreSQL 输出下限。

十六进制值“a”到“f”作为小写字符输出,并且输入时不区分大小写。 - rfc4122#section-3

One difference between GUID in SQL Server and UUID in PostgreSQL is letter case; SQL Server outputs upper while PostgreSQL outputs lower.

The hexadecimal values "a" through "f" are output as lower case characters and are case insensitive on input. - rfc4122#section-3

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文