Add writing debug logs.

This commit is contained in:
Z 2021-06-12 08:50:22 +01:00
parent 2a42c15773
commit c5ee112799
14 changed files with 41 additions and 33 deletions

View file

@ -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();

View file

@ -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{

View file

@ -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" {

View file

@ -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);
}

View file

@ -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" {

View file

@ -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" {

View file

@ -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);
}

View file

@ -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);

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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" {

View file

@ -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" {

View file

@ -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);

View file

@ -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" {