aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorMartin Ashby <martin@ashbysoft.com>2023-09-22 22:55:47 +0100
committerMartin Ashby <martin@ashbysoft.com>2023-09-22 22:55:47 +0100
commit6202dd351c83e9e54bffdbff844414b4dd763eba (patch)
treef9b0ce153a690e09a31c98f305295af29b682452 /src/main.zig
downloadpgz-6202dd351c83e9e54bffdbff844414b4dd763eba.tar.gz
pgz-6202dd351c83e9e54bffdbff844414b4dd763eba.tar.bz2
pgz-6202dd351c83e9e54bffdbff844414b4dd763eba.tar.xz
pgz-6202dd351c83e9e54bffdbff844414b4dd763eba.zip
Initial: port of pgx to zig (so, pgz)
Starting with message structures, so far we have startup_message and authentication_ok
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
new file mode 100644
index 0000000..4bed468
--- /dev/null
+++ b/src/main.zig
@@ -0,0 +1,39 @@
+const std = @import("std");
+const testing = std.testing;
+const StartupMessage = @import("startup_message.zig");
+const AuthenticationOk = @import("authentication_ok.zig");
+
+pub const ProtocolError = error{
+ InvalidProtocolVersion,
+ InvalidKeyValuePair,
+ InvalidMessageLength,
+ InvalidAuthType,
+};
+
+pub const ClientError = error{
+ UnsupportedAuthType,
+};
+
+pub const AuthType = enum(u32) {
+ AuthTypeOk = 0,
+};
+
+// Fallible version of enumFromInt
+pub fn enum_from_int(comptime e: type, i: anytype) ?e {
+ const enum_ti = @typeInfo(e);
+ if (enum_ti != .Enum) @compileError("e should be an enum but instead it's a " ++ @typeName(e));
+ const ei = enum_ti.Enum;
+ if (@TypeOf(i) != ei.tag_type) @compileError("i should be of type " ++ @typeName(e) ++ " but instead it's " ++ @typeName(@TypeOf(i)));
+ inline for (ei.fields) |field| {
+ if (field.value == i) {
+ return @enumFromInt(i);
+ }
+ } else {
+ return null;
+ }
+}
+
+test {
+ _ = StartupMessage;
+ _ = AuthenticationOk;
+}