Merge pull request #4152 from edyu/master

Fix error for uuid to require 36 bytes instead 32 (4 bytes for dashes)
This commit is contained in:
Jeroen van Rijn
2024-08-26 19:35:04 +02:00
committed by GitHub
+8 -3
View File
@@ -11,7 +11,7 @@ Write a UUID in the 8-4-4-4-12 format.
This procedure performs error checking with every byte written. This procedure performs error checking with every byte written.
If you can guarantee beforehand that your stream has enough space to hold the If you can guarantee beforehand that your stream has enough space to hold the
UUID (32 bytes), then it is better to use `unsafe_write` instead as that will UUID (36 bytes), then it is better to use `unsafe_write` instead as that will
be faster. be faster.
Inputs: Inputs:
@@ -106,7 +106,7 @@ Convert a UUID to a string in the 8-4-4-4-12 format.
Inputs: Inputs:
- id: The identifier to convert. - id: The identifier to convert.
- buffer: A byte buffer to store the result. Must be at least 32 bytes large. - buffer: A byte buffer to store the result. Must be at least 36 bytes large.
- loc: The caller location for debugging purposes (default: #caller_location) - loc: The caller location for debugging purposes (default: #caller_location)
Returns: Returns:
@@ -119,7 +119,11 @@ to_string_buffer :: proc(
) -> ( ) -> (
str: string, str: string,
) { ) {
assert(len(buffer) >= EXPECTED_LENGTH, "The buffer provided is not at least 32 bytes large.", loc) assert(
len(buffer) >= EXPECTED_LENGTH,
"The buffer provided is not at least 36 bytes large.",
loc,
)
builder := strings.builder_from_bytes(buffer) builder := strings.builder_from_bytes(buffer)
unsafe_write(strings.to_writer(&builder), id) unsafe_write(strings.to_writer(&builder), id)
return strings.to_string(builder) return strings.to_string(builder)
@@ -129,3 +133,4 @@ to_string :: proc {
to_string_allocated, to_string_allocated,
to_string_buffer, to_string_buffer,
} }