Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
r4gus committed Jul 7, 2023
1 parent d40990c commit 945510c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const uuid = @import("uuid-zig");
const id = uuid.v7.new();
const urn = try uuid.urn.serialize(id);
const urn = uuid.urn.serialize(id);
```

You can also parse URNs (UUID strings):
Expand Down
2 changes: 1 addition & 1 deletion examples/uuid_v4.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const uuid = @import("uuid-zig");
pub fn main() !void {
const id = uuid.v4.new();

const urn = try uuid.urn.serialize(id);
const urn = uuid.urn.serialize(id);

const stdout = std.io.getStdOut().writer();
try stdout.print("v4: {s}\n", .{&urn});
Expand Down
4 changes: 2 additions & 2 deletions examples/uuid_v7.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ pub fn main() !void {
const id1 = uuid.v7.new();
const id2 = uuid.v7.new();

const urn1 = try uuid.urn.serialize(id1);
const urn2 = try uuid.urn.serialize(id2);
const urn1 = uuid.urn.serialize(id1);
const urn2 = uuid.urn.serialize(id2);

const stdout = std.io.getStdOut().writer();
try stdout.print("v7: {s}\n", .{urn1});
Expand Down
10 changes: 5 additions & 5 deletions src/urn.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ pub const Urn = [36]u8;
///
/// The caller is responsible for deallocating the string returned
/// by this function.
pub fn serialize(uuid: Uuid) !Urn {
pub fn serialize(uuid: Uuid) Urn {
var urn: Urn = undefined;
_ = try std.fmt.bufPrint(&urn, "{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x:0>12}", .{
_ = std.fmt.bufPrint(&urn, "{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x:0>12}", .{
core.getTimeLow(uuid),
core.getTimeMid(uuid),
core.getTimeHiAndVersion(uuid),
core.getClockSeqHiAndReserved(uuid),
core.getClockSeqLow(uuid),
core.getNode(uuid),
});
}) catch unreachable;
return urn;
}

Expand Down Expand Up @@ -66,7 +66,7 @@ pub fn deserialize(s: []const u8) !Uuid {

test "uuid to urn" {
const uuid1: Uuid = 0xffeeddccbbaa99887766554433221100;
const urn1 = try serialize(uuid1);
const urn1 = serialize(uuid1);
try std.testing.expectEqualSlices(u8, "00112233-4455-6677-8899-aabbccddeeff", urn1[0..]);
}

Expand All @@ -79,7 +79,7 @@ test "urn tu uudi" {
test "urn full circle" {
const urn1 = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
const uuid = try deserialize(urn1);
const urn_new = try serialize(uuid);
const urn_new = serialize(uuid);

try std.testing.expectEqualStrings(urn1, &urn_new);
}

0 comments on commit 945510c

Please sign in to comment.