Reputation: 51
In almost all examples UUID is encoded to utf-8 for example.
"aa4aaa2c-c6ca-d5f5-b8b2-0b5c78ee2cb7".getBytes(StandardCharsets.UTF_8))
UUID is not ascii format? Why everyone encodes to utf-8?
Upvotes: 0
Views: 3584
Reputation: 1183
UUID is encoded as a 128-bit object (see RFC4122). Your example is the textual representation in hexadecimal of an UUID value.
There is no particular encoding required for UUID. I guess UTF-8 is used probably because it is the default encoding for various exchange formats such as for example JSON.
Upvotes: 2
Reputation: 299605
What do you mean by "UUID is not ascii format?" UUID is a 128-bit number, and this is one (ambiguous) way to encode it into a string. Do you mean "why do people use UTF-8 when ASCII is equivalent?" Because it's good habit to use UTF-8 for most things unless you have a reason not to. When it's equivalent to ASCII, it's the same, so it doesn't matter. When it's not equivalent to ASCII, you usually wanted UTF-8.
Upvotes: 0