issues with parsing

This commit is contained in:
Kitteh 2021-06-03 13:16:08 +01:00
parent a68c3e2c82
commit a108f9befd
14 changed files with 35 additions and 6 deletions

View file

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

View file

@ -1,3 +1,5 @@
const std = @import("std");
pub fn readByte(reader: anytype) !u8 {
std.debug.print("read: readByte\n", .{});
return try reader.readByte();
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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