| ... | @@ -105,8 +105,10 @@ pub fn receiveMessage(s: *Server) !InMessage.Header { | ... | @@ -105,8 +105,10 @@ pub fn receiveMessage(s: *Server) !InMessage.Header { |
| 105 | assert(fifo.readableLength() == buf.len); | 105 | assert(fifo.readableLength() == buf.len); |
| 106 | if (buf.len >= @sizeOf(Header)) { | 106 | if (buf.len >= @sizeOf(Header)) { |
| 107 | const header = @ptrCast(*align(1) const Header, buf[0..@sizeOf(Header)]); | 107 | const header = @ptrCast(*align(1) const Header, buf[0..@sizeOf(Header)]); |
| 108 | const bytes_len = bswap(header.bytes_len); | 108 | // workaround for https://github.com/ziglang/zig/issues/14904 |
| 109 | const tag = bswap(header.tag); | 109 | const bytes_len = bswap_and_workaround_u32(&header.bytes_len); |
| | 110 | // workaround for https://github.com/ziglang/zig/issues/14904 |
| | 111 | const tag = bswap_and_workaround_tag(&header.tag); |
| 110 | | 112 | |
| 111 | if (buf.len - @sizeOf(Header) >= bytes_len) { | 113 | if (buf.len - @sizeOf(Header) >= bytes_len) { |
| 112 | fifo.discard(@sizeOf(Header)); | 114 | fifo.discard(@sizeOf(Header)); |
| ... | @@ -278,6 +280,19 @@ fn bswap_u32_array(slice: []u32) void { | ... | @@ -278,6 +280,19 @@ fn bswap_u32_array(slice: []u32) void { |
| 278 | for (slice) |*elem| elem.* = @byteSwap(elem.*); | 280 | for (slice) |*elem| elem.* = @byteSwap(elem.*); |
| 279 | } | 281 | } |
| 280 | | 282 | |
| | 283 | /// workaround for https://github.com/ziglang/zig/issues/14904 |
| | 284 | fn bswap_and_workaround_u32(x: *align(1) const u32) u32 { |
| | 285 | const bytes_ptr = @ptrCast(*const [4]u8, x); |
| | 286 | return std.mem.readIntLittle(u32, bytes_ptr); |
| | 287 | } |
| | 288 | |
| | 289 | /// workaround for https://github.com/ziglang/zig/issues/14904 |
| | 290 | fn bswap_and_workaround_tag(x: *align(1) const InMessage.Tag) InMessage.Tag { |
| | 291 | const bytes_ptr = @ptrCast(*const [4]u8, x); |
| | 292 | const int = std.mem.readIntLittle(u32, bytes_ptr); |
| | 293 | return @intToEnum(InMessage.Tag, int); |
| | 294 | } |
| | 295 | |
| 281 | const OutMessage = std.zig.Server.Message; | 296 | const OutMessage = std.zig.Server.Message; |
| 282 | const InMessage = std.zig.Client.Message; | 297 | const InMessage = std.zig.Client.Message; |
| 283 | | 298 | |