diff --git a/src/client.zig b/src/client.zig index 7b054ec..eae8ba3 100644 --- a/src/client.zig +++ b/src/client.zig @@ -4,6 +4,8 @@ const write = @import("./qtshit/write.zig"); const QVariantType = @import("./qtshit/types/QVariant.zig").QVariant; const prettyPrintQVariant = @import("./qtshit/utils/prettyPrintQVariant.zig").prettyPrintQVariant; const freeQVariant = @import("./qtshit/utils/freeQVariant.zig").freeQVariant; +const QVariantMapToQVariantList = @import("./qtshit/utils/QVariantMapToQVariantList.zig").QVariantMapToQVariantList; + fn dumpDebug(name: []const u8, list: std.ArrayList(u8)) !void { std.debug.print("dumpDebug list len {d}\n", .{list.items.len}); diff --git a/src/main.zig b/src/main.zig index 981fda0..384ea34 100644 --- a/src/main.zig +++ b/src/main.zig @@ -24,6 +24,12 @@ pub fn main() !void { try client.quassel_init_packet(); try client.quassel_login(username, password); while (true) { - try client.read_quassel_packet(); + client.read_quassel_packet() catch |err| { + if (err == error.DecodeError) { + std.debug.print("Decode Error.\n", .{}); + } else { + return err; + } + }; } } diff --git a/src/qtshit/read/readQVariantT.zig b/src/qtshit/read/readQVariantT.zig index 9250761..810b18f 100644 --- a/src/qtshit/read/readQVariantT.zig +++ b/src/qtshit/read/readQVariantT.zig @@ -17,7 +17,7 @@ const readUserType = @import("./usertypes/readUserType.zig").readUserType; const QVariant = @import("../types/QVariant.zig").QVariant; const QVariantTypes = @import("../types/QVariantTypes.zig").QVariantTypes; -pub fn readQVariantT(reader: anytype, type_id: u32, allocator: *std.mem.Allocator) (@TypeOf(reader).Error || error{EndOfStream} || error{OutOfMemory})!QVariant { +pub fn readQVariantT(reader: anytype, type_id: u32, allocator: *std.mem.Allocator) (@TypeOf(reader).Error || error{EndOfStream} || error{OutOfMemory} || error{DecodeError})!QVariant { switch (type_id) { @enumToInt(QVariantTypes.Byte) => { var byte = try readByte(reader); @@ -65,9 +65,7 @@ pub fn readQVariantT(reader: anytype, type_id: u32, allocator: *std.mem.Allocato }, else => { std.debug.print("Unknown Type ID: {d}\n", .{type_id}); - return QVariant{ .String = "UnknownType" }; - - //@panic("Unknown Type See Above."); + return error.DecodeError; }, } return QVariant{ .empty = true }; diff --git a/src/qtshit/utils/QVariantMapToQVariantList.zig b/src/qtshit/utils/QVariantMapToQVariantList.zig new file mode 100644 index 0000000..6dfc5f0 --- /dev/null +++ b/src/qtshit/utils/QVariantMapToQVariantList.zig @@ -0,0 +1,18 @@ +const std = @import("std"); +const QVariant = @import("../types/QVariant.zig").QVariant; +const range = @import("./RangeIter.zig").range; + +pub fn QVariantMapToQVariantList(varMap: std.StringHashMap(QVariant), allocator: *std.mem.Allocator) ![]QVariant { + var variantList = try allocator.alloc(QVariant, @intCast(usize, varMap.count() * 2)); + + var varMapIter = varMap.iterator(); + var iter = range(u32, 0, varMap.count() * 2); + + while (iter.next()) |i| { + if (i % 2 == 1) continue; + var item = varMapIter.next().?; + variantList[i] = QVariant{.String = item.key}; + variantList[i + 1] = item.value; + } + return variantList; +}