From c5ee112799b64ccc7da390331fafbf5bf14425c6 Mon Sep 17 00:00:00 2001 From: Z Date: Sat, 12 Jun 2021 08:50:22 +0100 Subject: [PATCH] Add writing debug logs. --- src/main.zig | 2 ++ src/qtshit/read/usertypes/readMessage.zig | 1 - src/qtshit/write/writeByte.zig | 2 ++ src/qtshit/write/writeFrame.zig | 16 ---------------- src/qtshit/write/writeInt.zig | 6 ++++-- src/qtshit/write/writeQByteArray.zig | 3 +++ src/qtshit/write/writeQStringList.zig | 3 +++ src/qtshit/write/writeQVariantHeader.zig | 2 ++ src/qtshit/write/writeQVariantList.zig | 3 +++ src/qtshit/write/writeQVariantMap.zig | 13 ++++++------- src/qtshit/write/writeShort.zig | 6 ++++-- src/qtshit/write/writeSignedByte.zig | 6 ++++-- src/qtshit/write/writeString.zig | 5 ++++- src/qtshit/write/writeUInt.zig | 6 ++++-- 14 files changed, 41 insertions(+), 33 deletions(-) delete mode 100644 src/qtshit/write/writeFrame.zig diff --git a/src/main.zig b/src/main.zig index b3efc47..0d3b500 100644 --- a/src/main.zig +++ b/src/main.zig @@ -4,6 +4,8 @@ const DebugAllocator = @import("./debug_allocator.zig"); const write = @import("./qtshit/write.zig"); const initClient = @import("./client.zig").initClient; +pub const log_level: std.log.Level = .warn; + pub fn realMain(allocator: *std.mem.Allocator) !void { var argIter = std.process.args(); diff --git a/src/qtshit/read/usertypes/readMessage.zig b/src/qtshit/read/usertypes/readMessage.zig index a7203ad..c4b6da5 100644 --- a/src/qtshit/read/usertypes/readMessage.zig +++ b/src/qtshit/read/usertypes/readMessage.zig @@ -8,7 +8,6 @@ const readQByteArray = @import("../readQByteArray.zig").readQByteArray; const freeMessage = @import("../../utils/free/freeMessage.zig").freeMessage; const log = std.log.scoped(.qtshit); - pub fn readMessage(reader: anytype, allocator: *std.mem.Allocator) !Message { log.debug("readMessage", .{}); return Message{ diff --git a/src/qtshit/write/writeByte.zig b/src/qtshit/write/writeByte.zig index d4897b4..0c69fd6 100644 --- a/src/qtshit/write/writeByte.zig +++ b/src/qtshit/write/writeByte.zig @@ -1,7 +1,9 @@ const std = @import("std"); +const log = std.log.scoped(.qtshit); pub fn writeByte(writer: anytype, byte: u8) !void { try writer.writeByte(byte); + log.debug("writeByte byte={d}", .{byte}); } test "serialize byte" { diff --git a/src/qtshit/write/writeFrame.zig b/src/qtshit/write/writeFrame.zig deleted file mode 100644 index 64eda3e..0000000 --- a/src/qtshit/write/writeFrame.zig +++ /dev/null @@ -1,16 +0,0 @@ -const std = @import("std"); -const QVariantType = @import("../types/QVariant.zig").QVariant; - -const writeUInt = @import("./writeUInt.zig").writeUInt; -const writeQVariant = @import("./writeQVariant.zig").writeQVariant; - -pub fn writeFrame(writer: anytype, allocator: *std.mem.Allocator, map: std.StringHashMap(QVariantType)) !void { - var data = std.ArrayList(u8).init(allocator); - try writeQVariant(data.writer(), allocator, .{ - .QVariantMap = map, - }); - - try writeUInt(writer, @intCast(u32, data.items.len)); - - try writer.writeAll(data.items); -} diff --git a/src/qtshit/write/writeInt.zig b/src/qtshit/write/writeInt.zig index d9c2358..03b0b3a 100644 --- a/src/qtshit/write/writeInt.zig +++ b/src/qtshit/write/writeInt.zig @@ -1,7 +1,9 @@ const std = @import("std"); +const log = std.log.scoped(.qtshit); -pub fn writeInt(writer: anytype, number: i32) !void { - try writer.writeIntBig(i32, number); +pub fn writeInt(writer: anytype, int: i32) !void { + try writer.writeIntBig(i32, int); + log.debug("writeInt byte={d}", .{int}); } test "serialize int" { diff --git a/src/qtshit/write/writeQByteArray.zig b/src/qtshit/write/writeQByteArray.zig index a0d6f86..560bae1 100644 --- a/src/qtshit/write/writeQByteArray.zig +++ b/src/qtshit/write/writeQByteArray.zig @@ -1,9 +1,12 @@ const std = @import("std"); +const log = std.log.scoped(.qtshit); + const writeUInt = @import("./writeUInt.zig").writeUInt; pub fn writeQByteArray(writer: anytype, array: []const u8) !void { try writeUInt(writer, @intCast(u32, array.len)); try writer.writeAll(array); + log.debug("writeQByteArray array={s}", .{array}); } test "serialize QByteArray" { diff --git a/src/qtshit/write/writeQStringList.zig b/src/qtshit/write/writeQStringList.zig index f11197c..e0e8995 100644 --- a/src/qtshit/write/writeQStringList.zig +++ b/src/qtshit/write/writeQStringList.zig @@ -1,9 +1,12 @@ const std = @import("std"); +const log = std.log.scoped(.qtshit); + const writeUInt = @import("./writeUInt.zig").writeUInt; const writeString = @import("./writeString.zig").writeString; pub fn writeQStringList(writer: anytype, allocator: *std.mem.Allocator, strList: [][]const u8) !void { try writeUInt(writer, @intCast(u32, strList.len)); + log.debug("writeQStringList length={d}", .{strList.len}); for (strList) |string| { try writeString(writer, allocator, string); } diff --git a/src/qtshit/write/writeQVariantHeader.zig b/src/qtshit/write/writeQVariantHeader.zig index d58229b..3179716 100644 --- a/src/qtshit/write/writeQVariantHeader.zig +++ b/src/qtshit/write/writeQVariantHeader.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const log = std.log.scoped(.qtshit); const writeUInt = @import("./writeUInt.zig").writeUInt; const writeByte = @import("./writeByte.zig").writeByte; @@ -6,6 +7,7 @@ const writeByte = @import("./writeByte.zig").writeByte; pub fn writeQVariantHeader(writer: anytype, type_id: u32) !void { try writeUInt(writer, type_id); try writeByte(writer, 0); + log.debug("writeQvariantHeader type_id={d}", .{type_id}); } test "serialize QVariantHeader" { var byteList = std.ArrayList(u8).init(std.testing.allocator); diff --git a/src/qtshit/write/writeQVariantList.zig b/src/qtshit/write/writeQVariantList.zig index 6571c9c..23fd38d 100644 --- a/src/qtshit/write/writeQVariantList.zig +++ b/src/qtshit/write/writeQVariantList.zig @@ -1,10 +1,13 @@ const std = @import("std"); +const log = std.log.scoped(.qtshit); + const QVariantType = @import("../types/QVariant.zig").QVariant; const writeUInt = @import("./writeUInt.zig").writeUInt; const writeQVariant = @import("./writeQVariant.zig").writeQVariant; pub fn writeQVariantList(writer: anytype, allocator: *std.mem.Allocator, varList: []QVariantType) !void { try writeUInt(writer, @intCast(u32, varList.len)); + log.debug("writeQVariantList length={}", .{varList.len}); for (varList) |v| { try writeQVariant(writer, allocator, v); } diff --git a/src/qtshit/write/writeQVariantMap.zig b/src/qtshit/write/writeQVariantMap.zig index ea60323..4de84d9 100644 --- a/src/qtshit/write/writeQVariantMap.zig +++ b/src/qtshit/write/writeQVariantMap.zig @@ -1,22 +1,21 @@ const std = @import("std"); +const log = std.log.scoped(.qtshit); + const QVariantType = @import("../types/QVariant.zig").QVariant; const writeString = @import("./writeString.zig").writeString; const writeUInt = @import("./writeUInt.zig").writeUInt; const writeQVariant = @import("./writeQVariant.zig").writeQVariant; pub fn writeQVariantMap(writer: anytype, allocator: *std.mem.Allocator, map: std.StringHashMap(QVariantType)) !void { - var data = std.ArrayList(u8).init(allocator); - defer data.deinit(); + try writeUInt(writer, map.count()); + log.debug("writeQVariantMap count={d}", .{map.count()}); var writeIterator = map.iterator(); while (writeIterator.next()) |entry| { - try writeString(data.writer(), allocator, entry.key_ptr.*); - try writeQVariant(data.writer(), allocator, entry.value_ptr.*); + try writeString(writer, allocator, entry.key_ptr.*); + try writeQVariant(writer, allocator, entry.value_ptr.*); } - try writeUInt(writer, map.count()); - try writer.writeAll(data.items); - return; } diff --git a/src/qtshit/write/writeShort.zig b/src/qtshit/write/writeShort.zig index 7e8dbf2..0913004 100644 --- a/src/qtshit/write/writeShort.zig +++ b/src/qtshit/write/writeShort.zig @@ -1,7 +1,9 @@ const std = @import("std"); +const log = std.log.scoped(.qtshit); -pub fn writeShort(writer: anytype, number: u16) !void { - try writer.writeIntBig(u16, number); +pub fn writeShort(writer: anytype, short: u16) !void { + try writer.writeIntBig(u16, short); + log.debug("writeShort short={d}", .{short}); } test "serialize Short" { diff --git a/src/qtshit/write/writeSignedByte.zig b/src/qtshit/write/writeSignedByte.zig index bc3a858..7cd61b3 100644 --- a/src/qtshit/write/writeSignedByte.zig +++ b/src/qtshit/write/writeSignedByte.zig @@ -1,7 +1,9 @@ const std = @import("std"); +const log = std.log.scoped(.qtshit); -pub fn writeSignedByte(writer: anytype, byte: i8) !void { - try writer.writeIntBig(i8, byte); +pub fn writeSignedByte(writer: anytype, signedByte: i8) !void { + try writer.writeIntBig(i8, signedByte); + log.debug("writeSignedByte signedByte={d}", .{signedByte}); } test "serialize Signed Byte" { diff --git a/src/qtshit/write/writeString.zig b/src/qtshit/write/writeString.zig index a1ea4a7..dc9f722 100644 --- a/src/qtshit/write/writeString.zig +++ b/src/qtshit/write/writeString.zig @@ -1,10 +1,13 @@ const std = @import("std"); -const writeInt = @import("./writeInt.zig").writeInt; +const log = std.log.scoped(.qtshit); const unicode = @import("../utils/unicode.zig"); +const writeInt = @import("./writeInt.zig").writeInt; + pub const WriteStringErrors = (error{InvalidUtf8} || error{OutOfMemory}); pub fn writeString(writer: anytype, allocator: *std.mem.Allocator, str: []const u8) WriteStringErrors!void { + log.debug("writeString string={s}", .{str}); var str_utf16BE = try unicode.utf8ToUtf16BE(allocator, str); defer allocator.free(str_utf16BE); diff --git a/src/qtshit/write/writeUInt.zig b/src/qtshit/write/writeUInt.zig index acd411c..146a95e 100644 --- a/src/qtshit/write/writeUInt.zig +++ b/src/qtshit/write/writeUInt.zig @@ -1,7 +1,9 @@ const std = @import("std"); +const log = std.log.scoped(.qtshit); -pub fn writeUInt(writer: anytype, number: u32) !void { - try writer.writeIntBig(u32, number); +pub fn writeUInt(writer: anytype, uint: u32) !void { + try writer.writeIntBig(u32, uint); + log.debug("writeUInt uint={d}", .{uint}); } test "serialize UInt" {