| ... | @@ -53,13 +53,19 @@ pub const Guid = extern struct { | ... | @@ -53,13 +53,19 @@ pub const Guid = extern struct { |
| 53 | ) !void { | 53 | ) !void { |
| 54 | _ = options; | 54 | _ = options; |
| 55 | if (f.len == 0) { | 55 | if (f.len == 0) { |
| 56 | return std.fmt.format(writer, "{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x:0>12}", .{ | 56 | const fmt = std.fmt.fmtSliceHexLower; |
| 57 | self.time_low, | 57 | |
| 58 | self.time_mid, | 58 | const time_low = @byteSwap(u32, self.time_low); |
| 59 | self.time_high_and_version, | 59 | const time_mid = @byteSwap(u16, self.time_mid); |
| 60 | self.clock_seq_high_and_reserved, | 60 | const time_high_and_version = @byteSwap(u16, self.time_high_and_version); |
| 61 | self.clock_seq_low, | 61 | |
| 62 | self.node, | 62 | return std.fmt.format(writer, "{:0>8}-{:0>4}-{:0>4}-{:0>2}{:0>2}-{:0>12}", .{ |
| | 63 | fmt(std.mem.asBytes(&time_low)), |
| | 64 | fmt(std.mem.asBytes(&time_mid)), |
| | 65 | fmt(std.mem.asBytes(&time_high_and_version)), |
| | 66 | fmt(std.mem.asBytes(&self.clock_seq_high_and_reserved)), |
| | 67 | fmt(std.mem.asBytes(&self.clock_seq_low)), |
| | 68 | fmt(std.mem.asBytes(&self.node)), |
| 63 | }); | 69 | }); |
| 64 | } else { | 70 | } else { |
| 65 | @compileError("Unknown format character: '" ++ f ++ "'"); | 71 | @compileError("Unknown format character: '" ++ f ++ "'"); |
| ... | @@ -133,3 +139,14 @@ pub const TimeCapabilities = extern struct { | ... | @@ -133,3 +139,14 @@ pub const TimeCapabilities = extern struct { |
| 133 | | 139 | |
| 134 | /// File Handle as specified in the EFI Shell Spec | 140 | /// File Handle as specified in the EFI Shell Spec |
| 135 | pub const FileHandle = *opaque {}; | 141 | pub const FileHandle = *opaque {}; |
| | 142 | |
| | 143 | test "GUID formatting" { |
| | 144 | var bytes = [_]u8{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 }; |
| | 145 | |
| | 146 | var guid = @bitCast(Guid, bytes); |
| | 147 | |
| | 148 | var str = try std.fmt.allocPrint(std.testing.allocator, "{}", .{guid}); |
| | 149 | defer std.testing.allocator.free(str); |
| | 150 | |
| | 151 | try std.testing.expect(std.mem.eql(u8, str, "32cb3c89-8080-427c-ba13-5049873bc287")); |
| | 152 | } |