Add some better logging.
This commit is contained in:
parent
d7b5fcd568
commit
2a42c15773
|
@ -6,6 +6,8 @@ const write = @import("./qtshit/write.zig");
|
|||
const range = @import("./qtshit/utils/RangeIter.zig").range;
|
||||
const tls = @import("./deps/iguanaTLS/src/main.zig");
|
||||
|
||||
const log = std.log.scoped(.SocketManager);
|
||||
|
||||
pub const SocketManager = struct {
|
||||
allocator: *std.mem.Allocator,
|
||||
baseStream: *std.net.Stream,
|
||||
|
@ -47,8 +49,14 @@ pub const SocketManager = struct {
|
|||
}
|
||||
|
||||
fn _writeFrame(s: *SocketManager, writer: anytype, data: std.ArrayList(u8)) !void {
|
||||
try write.writeUInt(writer, @intCast(u32, data.items.len));
|
||||
try writer.writeAll(data.items);
|
||||
var frameData = std.ArrayList(u8).init(s.allocator);
|
||||
defer frameData.deinit();
|
||||
|
||||
try write.writeUInt(frameData.writer(), @intCast(u32, data.items.len));
|
||||
try frameData.writer().writeAll(data.items);
|
||||
|
||||
log.debug("_writeFrame data={any}", .{data.items});
|
||||
try writer.writeAll(frameData.items);
|
||||
}
|
||||
|
||||
pub fn writeFrame(s: *SocketManager, data: std.ArrayList(u8)) !void {
|
||||
|
@ -70,6 +78,8 @@ pub const SocketManager = struct {
|
|||
const byte = try reader.readByte();
|
||||
try data.append(byte);
|
||||
}
|
||||
|
||||
log.debug("_readFrame data={any}", .{data.items});
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,9 +63,8 @@ pub const Client = struct {
|
|||
|
||||
var featureList = std.ArrayList([]const u8).init(s.allocator);
|
||||
defer featureList.deinit();
|
||||
|
||||
try featureList.append("LongTime");
|
||||
try featureList.append("LongMessageID");
|
||||
try featureList.append("LongMessageId");
|
||||
try featureList.append("SenderPrefixes");
|
||||
try featureList.append("RichMessages");
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
const std = @import("std");
|
||||
const log = std.log.scoped(.qtshit);
|
||||
|
||||
pub fn readByte(reader: anytype) !u8 {
|
||||
//std.debug.print("read: readByte\n", .{});
|
||||
return try reader.readByte();
|
||||
var byte = try reader.readByte();
|
||||
log.debug("readByte byte={d}", .{byte});
|
||||
return byte;
|
||||
}
|
||||
|
||||
test "deserialize byte" {
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
const std = @import("std");
|
||||
const log = std.log.scoped(.qtshit);
|
||||
|
||||
pub fn readInt(reader: anytype) !i32 {
|
||||
//std.debug.print("read: readInt\n", .{});
|
||||
return try reader.readIntBig(i32);
|
||||
var int = try reader.readIntBig(i32);
|
||||
log.debug("readInt int={d}", .{int});
|
||||
return int;
|
||||
}
|
||||
|
||||
test "deserialize int" {
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
const std = @import("std");
|
||||
const log = std.log.scoped(.qtshit);
|
||||
|
||||
pub fn readLong(reader: anytype) !i64 {
|
||||
//std.debug.print("read: readLong\n", .{});
|
||||
return try reader.readIntBig(i64);
|
||||
var long = try reader.readIntBig(i64);
|
||||
log.debug("readLong long={d}", .{long});
|
||||
return long;
|
||||
}
|
||||
|
||||
test "deserialize long" {
|
||||
|
|
|
@ -2,10 +2,11 @@ const std = @import("std");
|
|||
const readUInt = @import("./readUInt.zig").readUInt;
|
||||
const range = @import("../utils/RangeIter.zig").range;
|
||||
const freeQByteArray = @import("../utils/free/freeQByteArray.zig").freeQByteArray;
|
||||
const log = std.log.scoped(.qtshit);
|
||||
|
||||
pub fn readQByteArray(reader: anytype, allocator: *std.mem.Allocator) ![]u8 {
|
||||
var length = try readUInt(reader);
|
||||
if (length == std.math.maxInt(@TypeOf(length))) {
|
||||
if (length == std.math.maxInt(@TypeOf(length)) or length == 589526130) {
|
||||
return "";
|
||||
}
|
||||
var byteList = try allocator.alloc(u8, @intCast(usize, length));
|
||||
|
@ -15,7 +16,7 @@ pub fn readQByteArray(reader: anytype, allocator: *std.mem.Allocator) ![]u8 {
|
|||
const byte = try reader.readByte();
|
||||
byteList[i] = byte;
|
||||
}
|
||||
//std.debug.print("read: readQByteArray length={d} content={any} \n", .{length, byteList});
|
||||
log.debug("readQByteArray length={d} content={s}", .{ length, byteList });
|
||||
|
||||
return byteList;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const std = @import("std");
|
||||
const range = @import("../utils/RangeIter.zig").range;
|
||||
const log = std.log.scoped(.qtshit);
|
||||
|
||||
const readUInt = @import("./readUInt.zig").readUInt;
|
||||
const readString = @import("./readString.zig").readString;
|
||||
|
@ -7,13 +8,15 @@ const freeQStringList = @import("../utils/free/freeQStringList.zig").freeQString
|
|||
|
||||
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});
|
||||
log.debug("readQStringList length={d}", .{length});
|
||||
|
||||
var stringList = try allocator.alloc([]const u8, @intCast(usize, length));
|
||||
|
||||
var iter = range(u32, 0, length);
|
||||
while (iter.next()) |i| {
|
||||
stringList[i] = try readString(reader, allocator);
|
||||
var string = try readString(reader, allocator);
|
||||
log.debug("readQStringList length={d} index={d} string=\"{s}\"", .{ length, i, string });
|
||||
stringList[i] = string;
|
||||
}
|
||||
|
||||
return stringList;
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
const std = @import("std");
|
||||
const log = std.log.scoped(.qtshit);
|
||||
|
||||
const readUInt = @import("./readUInt.zig").readUInt;
|
||||
const readByte = @import("./readByte.zig").readByte;
|
||||
const readQVariantT = @import("./readQVariantT.zig").readQVariantT;
|
||||
|
@ -9,9 +11,11 @@ const QVariant = @import("../types/QVariant.zig").QVariant;
|
|||
pub fn readQVariant(reader: anytype, allocator: *std.mem.Allocator) !QVariant {
|
||||
var type_id = try readUInt(reader);
|
||||
var mysteryByte = try readByte(reader);
|
||||
//std.debug.print("read: readQVariant type_id={d} mysteryByte={d} \n", .{type_id, mysteryByte});
|
||||
|
||||
log.debug("readQVariant type_id={d} mysteryByte={d}", .{ type_id, mysteryByte });
|
||||
return try readQVariantT(reader, type_id, allocator);
|
||||
}
|
||||
|
||||
test "deserialize QVariant Byte" {
|
||||
var bytes = &[_]u8{ 0, 0, 0, 1, 0, 255 };
|
||||
var fBS = std.io.fixedBufferStream(bytes);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const std = @import("std");
|
||||
const range = @import("../utils/RangeIter.zig").range;
|
||||
const log = std.log.scoped(.qtshit);
|
||||
|
||||
const readUInt = @import("./readUInt.zig").readUInt;
|
||||
const readQVariant = @import("./readQVariant.zig").readQVariant;
|
||||
|
@ -9,7 +10,7 @@ const QVariant = @import("../types/QVariant.zig").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});
|
||||
log.debug("readQVariantList length={d}", .{length});
|
||||
|
||||
var variantList = try allocator.alloc(QVariant, @intCast(usize, length));
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
const std = @import("std");
|
||||
const log = std.log.scoped(.qtshit);
|
||||
|
||||
pub fn readShort(reader: anytype) !u16 {
|
||||
//std.debug.print("read: readShort\n", .{});
|
||||
return try reader.readIntBig(u16);
|
||||
var short = try reader.readIntBig(u16);
|
||||
log.debug("readShort short={d}", .{short});
|
||||
return short;
|
||||
}
|
||||
|
||||
test "deserialize short" {
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
const std = @import("std");
|
||||
const log = std.log.scoped(.qtshit);
|
||||
|
||||
pub fn readSignedByte(reader: anytype) !i8 {
|
||||
//std.debug.print("read: readSignedByte\n", .{});
|
||||
return try reader.readIntBig(i8);
|
||||
var signedByte = try reader.readIntBig(i8);
|
||||
log.debug("readSignedByte signedByte={d}", .{signedByte});
|
||||
return signedByte;
|
||||
}
|
||||
|
||||
test "deserialize signed byte" {
|
||||
|
|
|
@ -3,6 +3,7 @@ const readInt = @import("./readInt.zig").readInt;
|
|||
const range = @import("../utils/RangeIter.zig").range;
|
||||
const unicode = @import("../utils/unicode.zig");
|
||||
const freeString = @import("../utils/free/freeString.zig").freeString;
|
||||
const log = std.log.scoped(.qtshit);
|
||||
|
||||
pub const ReadStringErrors = (error{ExpectedSecondSurrogateHalf} || error{UnexpectedSecondSurrogateHalf} || error{DanglingSurrogateHalf} || error{OutOfMemory});
|
||||
|
||||
|
@ -11,17 +12,15 @@ pub fn readString(reader: anytype, allocator: *std.mem.Allocator) (@TypeOf(reade
|
|||
defer utf16Data.deinit();
|
||||
|
||||
var num_bytes = @divTrunc(try readInt(reader), 2);
|
||||
log.debug("readString num_bytes={d}", .{num_bytes});
|
||||
|
||||
var iter = range(i32, 0, num_bytes);
|
||||
while (iter.next()) |i| {
|
||||
if (i == num_bytes) break;
|
||||
try utf16Data.append(try reader.readIntLittle(u16));
|
||||
}
|
||||
|
||||
var utf8 = try unicode.utf16BEToUtf8(allocator, utf16Data.items);
|
||||
|
||||
//std.debug.print("string: {s}\n", .{utf8});
|
||||
|
||||
log.debug("readString num_bytes={d} utf8=\"{s}\"", .{ num_bytes, utf8 });
|
||||
return utf8;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
const std = @import("std");
|
||||
const log = std.log.scoped(.qtshit);
|
||||
|
||||
pub fn readUInt(reader: anytype) !u32 {
|
||||
//std.debug.print("read: readUInt\n", .{});
|
||||
return try reader.readIntBig(u32);
|
||||
var uint = try reader.readIntBig(u32);
|
||||
log.debug("readUInt uint={d}", .{uint});
|
||||
return uint;
|
||||
}
|
||||
|
||||
test "deserialize UInt" {
|
||||
|
|
|
@ -5,8 +5,10 @@ const readShort = @import("../readShort.zig").readShort;
|
|||
const readByte = @import("../readByte.zig").readByte;
|
||||
const readQByteArray = @import("../readQByteArray.zig").readQByteArray;
|
||||
const freeBufferInfo = @import("../../utils/free/freeBufferInfo.zig").freeBufferInfo;
|
||||
const log = std.log.scoped(.qtshit);
|
||||
|
||||
pub fn readBufferInfo(reader: anytype, allocator: *std.mem.Allocator) !BufferInfo {
|
||||
log.debug("readBufferInfo", .{});
|
||||
var id = try readInt(reader);
|
||||
var networkid = try readInt(reader);
|
||||
var btype = try readShort(reader);
|
||||
|
|
|
@ -6,8 +6,11 @@ const readByte = @import("../readByte.zig").readByte;
|
|||
const readBufferInfo = @import("./readBufferInfo.zig").readBufferInfo;
|
||||
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{
|
||||
.MessageID = try readLong(reader),
|
||||
.Timestamp = try readLong(reader),
|
||||
|
|
Loading…
Reference in a new issue