Add writing debug logs.
This commit is contained in:
parent
2a42c15773
commit
c5ee112799
|
@ -4,6 +4,8 @@ const DebugAllocator = @import("./debug_allocator.zig");
|
||||||
const write = @import("./qtshit/write.zig");
|
const write = @import("./qtshit/write.zig");
|
||||||
const initClient = @import("./client.zig").initClient;
|
const initClient = @import("./client.zig").initClient;
|
||||||
|
|
||||||
|
pub const log_level: std.log.Level = .warn;
|
||||||
|
|
||||||
pub fn realMain(allocator: *std.mem.Allocator) !void {
|
pub fn realMain(allocator: *std.mem.Allocator) !void {
|
||||||
var argIter = std.process.args();
|
var argIter = std.process.args();
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ const readQByteArray = @import("../readQByteArray.zig").readQByteArray;
|
||||||
const freeMessage = @import("../../utils/free/freeMessage.zig").freeMessage;
|
const freeMessage = @import("../../utils/free/freeMessage.zig").freeMessage;
|
||||||
const log = std.log.scoped(.qtshit);
|
const log = std.log.scoped(.qtshit);
|
||||||
|
|
||||||
|
|
||||||
pub fn readMessage(reader: anytype, allocator: *std.mem.Allocator) !Message {
|
pub fn readMessage(reader: anytype, allocator: *std.mem.Allocator) !Message {
|
||||||
log.debug("readMessage", .{});
|
log.debug("readMessage", .{});
|
||||||
return Message{
|
return Message{
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const log = std.log.scoped(.qtshit);
|
||||||
|
|
||||||
pub fn writeByte(writer: anytype, byte: u8) !void {
|
pub fn writeByte(writer: anytype, byte: u8) !void {
|
||||||
try writer.writeByte(byte);
|
try writer.writeByte(byte);
|
||||||
|
log.debug("writeByte byte={d}", .{byte});
|
||||||
}
|
}
|
||||||
|
|
||||||
test "serialize byte" {
|
test "serialize byte" {
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -1,7 +1,9 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const log = std.log.scoped(.qtshit);
|
||||||
|
|
||||||
pub fn writeInt(writer: anytype, number: i32) !void {
|
pub fn writeInt(writer: anytype, int: i32) !void {
|
||||||
try writer.writeIntBig(i32, number);
|
try writer.writeIntBig(i32, int);
|
||||||
|
log.debug("writeInt byte={d}", .{int});
|
||||||
}
|
}
|
||||||
|
|
||||||
test "serialize int" {
|
test "serialize int" {
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const log = std.log.scoped(.qtshit);
|
||||||
|
|
||||||
const writeUInt = @import("./writeUInt.zig").writeUInt;
|
const writeUInt = @import("./writeUInt.zig").writeUInt;
|
||||||
|
|
||||||
pub fn writeQByteArray(writer: anytype, array: []const u8) !void {
|
pub fn writeQByteArray(writer: anytype, array: []const u8) !void {
|
||||||
try writeUInt(writer, @intCast(u32, array.len));
|
try writeUInt(writer, @intCast(u32, array.len));
|
||||||
try writer.writeAll(array);
|
try writer.writeAll(array);
|
||||||
|
log.debug("writeQByteArray array={s}", .{array});
|
||||||
}
|
}
|
||||||
|
|
||||||
test "serialize QByteArray" {
|
test "serialize QByteArray" {
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const log = std.log.scoped(.qtshit);
|
||||||
|
|
||||||
const writeUInt = @import("./writeUInt.zig").writeUInt;
|
const writeUInt = @import("./writeUInt.zig").writeUInt;
|
||||||
const writeString = @import("./writeString.zig").writeString;
|
const writeString = @import("./writeString.zig").writeString;
|
||||||
|
|
||||||
pub fn writeQStringList(writer: anytype, allocator: *std.mem.Allocator, strList: [][]const u8) !void {
|
pub fn writeQStringList(writer: anytype, allocator: *std.mem.Allocator, strList: [][]const u8) !void {
|
||||||
try writeUInt(writer, @intCast(u32, strList.len));
|
try writeUInt(writer, @intCast(u32, strList.len));
|
||||||
|
log.debug("writeQStringList length={d}", .{strList.len});
|
||||||
for (strList) |string| {
|
for (strList) |string| {
|
||||||
try writeString(writer, allocator, string);
|
try writeString(writer, allocator, string);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const log = std.log.scoped(.qtshit);
|
||||||
|
|
||||||
const writeUInt = @import("./writeUInt.zig").writeUInt;
|
const writeUInt = @import("./writeUInt.zig").writeUInt;
|
||||||
const writeByte = @import("./writeByte.zig").writeByte;
|
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 {
|
pub fn writeQVariantHeader(writer: anytype, type_id: u32) !void {
|
||||||
try writeUInt(writer, type_id);
|
try writeUInt(writer, type_id);
|
||||||
try writeByte(writer, 0);
|
try writeByte(writer, 0);
|
||||||
|
log.debug("writeQvariantHeader type_id={d}", .{type_id});
|
||||||
}
|
}
|
||||||
test "serialize QVariantHeader" {
|
test "serialize QVariantHeader" {
|
||||||
var byteList = std.ArrayList(u8).init(std.testing.allocator);
|
var byteList = std.ArrayList(u8).init(std.testing.allocator);
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const log = std.log.scoped(.qtshit);
|
||||||
|
|
||||||
const QVariantType = @import("../types/QVariant.zig").QVariant;
|
const QVariantType = @import("../types/QVariant.zig").QVariant;
|
||||||
const writeUInt = @import("./writeUInt.zig").writeUInt;
|
const writeUInt = @import("./writeUInt.zig").writeUInt;
|
||||||
const writeQVariant = @import("./writeQVariant.zig").writeQVariant;
|
const writeQVariant = @import("./writeQVariant.zig").writeQVariant;
|
||||||
|
|
||||||
pub fn writeQVariantList(writer: anytype, allocator: *std.mem.Allocator, varList: []QVariantType) !void {
|
pub fn writeQVariantList(writer: anytype, allocator: *std.mem.Allocator, varList: []QVariantType) !void {
|
||||||
try writeUInt(writer, @intCast(u32, varList.len));
|
try writeUInt(writer, @intCast(u32, varList.len));
|
||||||
|
log.debug("writeQVariantList length={}", .{varList.len});
|
||||||
for (varList) |v| {
|
for (varList) |v| {
|
||||||
try writeQVariant(writer, allocator, v);
|
try writeQVariant(writer, allocator, v);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,21 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const log = std.log.scoped(.qtshit);
|
||||||
|
|
||||||
const QVariantType = @import("../types/QVariant.zig").QVariant;
|
const QVariantType = @import("../types/QVariant.zig").QVariant;
|
||||||
const writeString = @import("./writeString.zig").writeString;
|
const writeString = @import("./writeString.zig").writeString;
|
||||||
const writeUInt = @import("./writeUInt.zig").writeUInt;
|
const writeUInt = @import("./writeUInt.zig").writeUInt;
|
||||||
const writeQVariant = @import("./writeQVariant.zig").writeQVariant;
|
const writeQVariant = @import("./writeQVariant.zig").writeQVariant;
|
||||||
|
|
||||||
pub fn writeQVariantMap(writer: anytype, allocator: *std.mem.Allocator, map: std.StringHashMap(QVariantType)) !void {
|
pub fn writeQVariantMap(writer: anytype, allocator: *std.mem.Allocator, map: std.StringHashMap(QVariantType)) !void {
|
||||||
var data = std.ArrayList(u8).init(allocator);
|
try writeUInt(writer, map.count());
|
||||||
defer data.deinit();
|
log.debug("writeQVariantMap count={d}", .{map.count()});
|
||||||
|
|
||||||
var writeIterator = map.iterator();
|
var writeIterator = map.iterator();
|
||||||
while (writeIterator.next()) |entry| {
|
while (writeIterator.next()) |entry| {
|
||||||
try writeString(data.writer(), allocator, entry.key_ptr.*);
|
try writeString(writer, allocator, entry.key_ptr.*);
|
||||||
try writeQVariant(data.writer(), allocator, entry.value_ptr.*);
|
try writeQVariant(writer, allocator, entry.value_ptr.*);
|
||||||
}
|
}
|
||||||
|
|
||||||
try writeUInt(writer, map.count());
|
|
||||||
try writer.writeAll(data.items);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const log = std.log.scoped(.qtshit);
|
||||||
|
|
||||||
pub fn writeShort(writer: anytype, number: u16) !void {
|
pub fn writeShort(writer: anytype, short: u16) !void {
|
||||||
try writer.writeIntBig(u16, number);
|
try writer.writeIntBig(u16, short);
|
||||||
|
log.debug("writeShort short={d}", .{short});
|
||||||
}
|
}
|
||||||
|
|
||||||
test "serialize Short" {
|
test "serialize Short" {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const log = std.log.scoped(.qtshit);
|
||||||
|
|
||||||
pub fn writeSignedByte(writer: anytype, byte: i8) !void {
|
pub fn writeSignedByte(writer: anytype, signedByte: i8) !void {
|
||||||
try writer.writeIntBig(i8, byte);
|
try writer.writeIntBig(i8, signedByte);
|
||||||
|
log.debug("writeSignedByte signedByte={d}", .{signedByte});
|
||||||
}
|
}
|
||||||
|
|
||||||
test "serialize Signed Byte" {
|
test "serialize Signed Byte" {
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const writeInt = @import("./writeInt.zig").writeInt;
|
const log = std.log.scoped(.qtshit);
|
||||||
const unicode = @import("../utils/unicode.zig");
|
const unicode = @import("../utils/unicode.zig");
|
||||||
|
|
||||||
|
const writeInt = @import("./writeInt.zig").writeInt;
|
||||||
|
|
||||||
pub const WriteStringErrors = (error{InvalidUtf8} || error{OutOfMemory});
|
pub const WriteStringErrors = (error{InvalidUtf8} || error{OutOfMemory});
|
||||||
|
|
||||||
pub fn writeString(writer: anytype, allocator: *std.mem.Allocator, str: []const u8) WriteStringErrors!void {
|
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);
|
var str_utf16BE = try unicode.utf8ToUtf16BE(allocator, str);
|
||||||
defer allocator.free(str_utf16BE);
|
defer allocator.free(str_utf16BE);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const log = std.log.scoped(.qtshit);
|
||||||
|
|
||||||
pub fn writeUInt(writer: anytype, number: u32) !void {
|
pub fn writeUInt(writer: anytype, uint: u32) !void {
|
||||||
try writer.writeIntBig(u32, number);
|
try writer.writeIntBig(u32, uint);
|
||||||
|
log.debug("writeUInt uint={d}", .{uint});
|
||||||
}
|
}
|
||||||
|
|
||||||
test "serialize UInt" {
|
test "serialize UInt" {
|
||||||
|
|
Loading…
Reference in a new issue