From 747c6e55cbe2283fd85ef8cd930e88d2bb0b7db2 Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Wed, 27 Sep 2023 23:34:46 +0100 Subject: Add a tagged union for all backend messages. Move read_message to proto.zig and make it return the tagged union rather than expecting a message type. --- src/proto/authentication_request.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/proto/authentication_request.zig') diff --git a/src/proto/authentication_request.zig b/src/proto/authentication_request.zig index 9203482..3ea5cd1 100644 --- a/src/proto/authentication_request.zig +++ b/src/proto/authentication_request.zig @@ -30,7 +30,11 @@ pub fn read(_: std.mem.Allocator, b: []const u8) !AuthenticationRequest { log.err("invalid message length, expected 4 got {}", .{b.len}); return ProtocolError.InvalidMessageLength; } - const inner_type = enum_from_int(InnerAuthRequestType, std.mem.readIntBig(u32, b[0..4])) orelse return ClientError.UnsupportedAuthType; + const auth_type_int = std.mem.readIntBig(u32, b[0..4]); + const inner_type = enum_from_int(InnerAuthRequestType, auth_type_int) orelse { + log.err("Unsupported auth type {}", .{auth_type_int}); + return ClientError.UnsupportedAuthType; + }; var inner: InnerAuthRequest = switch (inner_type) { .AuthRequestTypeOk => .{ .ok = AuthRequestOk{} }, .AuthRequestTypeCleartextPassword => .{ .cleartext_password = AuthRequestCleartextPassword{} }, -- cgit v1.2.3-ZIG