diff --git a/src/main.zig b/src/main.zig index c702b60..26d90d0 100644 --- a/src/main.zig +++ b/src/main.zig @@ -6,7 +6,7 @@ const write = @import("./qtshit/write.zig"); const initClient = @import("./client.zig").initClient; pub fn main() !void { - const allocator = std.heap.page_allocator; + const allocator = &std.heap.loggingAllocator(std.heap.page_allocator, std.io.getStdErr().writer()).allocator; var argIter = std.process.args(); _ = try argIter.next(allocator).?; @@ -18,7 +18,6 @@ pub fn main() !void { std.debug.print("host={s} port={d}\n", .{host, portInt}); - var sock = try std.net.tcpConnectToHost(allocator, host, portInt); var client = initClient(allocator, &sock); try client.handshake(); diff --git a/src/qtshit/read/readByte.zig b/src/qtshit/read/readByte.zig index 2d6c998..0449a7e 100644 --- a/src/qtshit/read/readByte.zig +++ b/src/qtshit/read/readByte.zig @@ -1,3 +1,5 @@ +const std = @import("std"); pub fn readByte(reader: anytype) !u8 { + std.debug.print("read: readByte\n", .{}); return try reader.readByte(); } diff --git a/src/qtshit/read/readInt.zig b/src/qtshit/read/readInt.zig index 8ca690f..00eb601 100644 --- a/src/qtshit/read/readInt.zig +++ b/src/qtshit/read/readInt.zig @@ -1,3 +1,6 @@ +const std = @import("std"); + pub fn readInt(reader: anytype) !i32 { + std.debug.print("read: readInt\n", .{}); return try reader.readIntBig(i32); } diff --git a/src/qtshit/read/readLong.zig b/src/qtshit/read/readLong.zig index 5830677..f61b66c 100644 --- a/src/qtshit/read/readLong.zig +++ b/src/qtshit/read/readLong.zig @@ -1,3 +1,6 @@ +const std = @import("std"); + pub fn readLong(reader: anytype) !i64 { + std.debug.print("read: readLong\n", .{}); return try reader.readIntBig(i64); } diff --git a/src/qtshit/read/readQByteArray.zig b/src/qtshit/read/readQByteArray.zig index 56f8f8b..dc09ba8 100644 --- a/src/qtshit/read/readQByteArray.zig +++ b/src/qtshit/read/readQByteArray.zig @@ -1,9 +1,9 @@ const std = @import("std"); const readUInt = @import("./readUInt.zig").readUInt; -const readByte = @import("./readByte.zig").readByte; pub fn readQByteArray(reader: anytype, allocator: *std.mem.Allocator) ![]u8 { var length = try readUInt(reader); + std.debug.print("read: readQByteArray length={d} \n", .{length}); var byteList = try allocator.alloc(u8, @intCast(usize, length)); @@ -11,7 +11,7 @@ pub fn readQByteArray(reader: anytype, allocator: *std.mem.Allocator) ![]u8 { while (true) { if (index == length) return byteList; - const byte = try readByte(reader); + const byte = try reader.readByte(); byteList[index] = byte; index += 1; } diff --git a/src/qtshit/read/readQStringList.zig b/src/qtshit/read/readQStringList.zig index c6dae08..e93e008 100644 --- a/src/qtshit/read/readQStringList.zig +++ b/src/qtshit/read/readQStringList.zig @@ -6,6 +6,8 @@ const readString = @import("./readString.zig").readString; pub fn readQStringList(reader: anytype, allocator: *std.mem.Allocator) ![][]const u8 { var length = try readUInt(reader); + std.debug.print("read: readQStringList length={d} \n", .{length}); + var stringList = try allocator.alloc([]const u8, @intCast(usize, length)); var iter = range(u32, 0, length); diff --git a/src/qtshit/read/readQVariant.zig b/src/qtshit/read/readQVariant.zig index 1124a81..2997135 100644 --- a/src/qtshit/read/readQVariant.zig +++ b/src/qtshit/read/readQVariant.zig @@ -7,6 +7,8 @@ const QVariant = @import("../types/QVariant.zig").QVariant; pub fn readQVariant(reader: anytype, allocator: *std.mem.Allocator) !QVariant { var type_id = try readUInt(reader); + std.debug.print("read: readQVariant type_id={d}\n", .{type_id}); + _ = try readByte(reader); return try readQVariantT(reader, type_id, allocator); } diff --git a/src/qtshit/read/readQVariantList.zig b/src/qtshit/read/readQVariantList.zig index d29a716..a699791 100644 --- a/src/qtshit/read/readQVariantList.zig +++ b/src/qtshit/read/readQVariantList.zig @@ -7,8 +7,10 @@ const readQVariant = @import("./readQVariant.zig").readQVariant; const QVariant = @import("../types/QVariant.zig").QVariant; -pub fn readQVariantList(reader: anytype, allocator: *std.mem.Allocator) ![]QVariant { +pub fn readQVariantList(reader: anytype, allocator: *std.mem.Allocator) ![]QVariant { var length = try readUInt(reader); + std.debug.print("read: readQVariantList length={d}\n", .{length}); + var variantList = try allocator.alloc(QVariant, @intCast(usize, length)); var iter = range(u32, 0, length); diff --git a/src/qtshit/read/readQVariantMap.zig b/src/qtshit/read/readQVariantMap.zig index 4281951..6c1a998 100644 --- a/src/qtshit/read/readQVariantMap.zig +++ b/src/qtshit/read/readQVariantMap.zig @@ -11,6 +11,8 @@ const QVariant = @import("../types/QVariant.zig").QVariant; pub fn readQVariantMap(reader: anytype, allocator: *std.mem.Allocator) !std.StringHashMap(QVariant) { var map = std.StringHashMap(QVariant).init(allocator); var numItems = try readUInt(reader); + std.debug.print("read: readQVariantMap length={d} \n", .{numItems}); + var iter = range(u32, 0, numItems); while (iter.next()) |i| { diff --git a/src/qtshit/read/readShort.zig b/src/qtshit/read/readShort.zig index 03df0f6..535793f 100644 --- a/src/qtshit/read/readShort.zig +++ b/src/qtshit/read/readShort.zig @@ -1,3 +1,7 @@ +const std = @import("std"); + pub fn readShort(reader: anytype) !u16 { + std.debug.print("read: readShort\n", .{}); + return try reader.readIntBig(u16); } diff --git a/src/qtshit/read/readSignedByte.zig b/src/qtshit/read/readSignedByte.zig index 4085455..8bd188e 100644 --- a/src/qtshit/read/readSignedByte.zig +++ b/src/qtshit/read/readSignedByte.zig @@ -1,3 +1,6 @@ +const std = @import("std"); + pub fn readSignedByte(reader: anytype) !i8 { + std.debug.print("read: readSignedByte\n", .{}); return try reader.readIntBig(i8); } diff --git a/src/qtshit/read/readString.zig b/src/qtshit/read/readString.zig index a06d953..ef39d07 100644 --- a/src/qtshit/read/readString.zig +++ b/src/qtshit/read/readString.zig @@ -8,12 +8,13 @@ pub fn readString(reader: anytype, allocator: *std.mem.Allocator) ![]u8 { var length = try readInt(reader); var chars = @divTrunc(length, 2); + std.debug.print("read: readString length={d} \n", .{length}); var index: usize = 0; while (true) { if (index == chars) break; - const byte = try readShort(reader); + const byte = try reader.readIntBig(u16); try data.append(@truncate(u8, byte)); index += 1; } @@ -23,5 +24,7 @@ pub fn readString(reader: anytype, allocator: *std.mem.Allocator) ![]u8 { ut8Str[i] = char; } + std.debug.print("string: {s}\n", .{ut8Str}); + return ut8Str; } diff --git a/src/qtshit/read/readUInt.zig b/src/qtshit/read/readUInt.zig index 033d3cc..108afbb 100644 --- a/src/qtshit/read/readUInt.zig +++ b/src/qtshit/read/readUInt.zig @@ -1,3 +1,6 @@ +const std = @import("std"); + pub fn readUInt(reader: anytype) !u32 { + std.debug.print("read: readUInt\n", .{}); return try reader.readIntBig(u32); } diff --git a/src/qtshit/read/usertypes/readUserType.zig b/src/qtshit/read/usertypes/readUserType.zig index b11b219..6b4473f 100644 --- a/src/qtshit/read/usertypes/readUserType.zig +++ b/src/qtshit/read/usertypes/readUserType.zig @@ -10,6 +10,7 @@ const readQVariantMap = @import("../readQVariantMap.zig").readQVariantMap; pub fn readUserType(reader: anytype, allocator: *std.mem.Allocator) !UserType { var userTypeName = try readQByteArray(reader, allocator); userTypeName = userTypeName[0 .. userTypeName.len - 1]; + std.debug.print("read: readUserType name={s} \n", .{userTypeName}); if (std.mem.eql(u8, userTypeName, "BufferId")) { return UserType{