test
This commit is contained in:
parent
cbd70cc74e
commit
52a601bc17
|
@ -50,7 +50,7 @@ pub const Client = struct {
|
||||||
try map.put("ClientVersion", .{ .string = "0.1 (quasselclient)" });
|
try map.put("ClientVersion", .{ .string = "0.1 (quasselclient)" });
|
||||||
try map.put("ClientDate", .{ .string = "0" });
|
try map.put("ClientDate", .{ .string = "0" });
|
||||||
|
|
||||||
try write.add_qvariantmap(list.writer(), map);
|
try write.add_qvariantmap(list.writer(), s.allocator, map);
|
||||||
try dumpDebug("ClientInit.bin", list);
|
try dumpDebug("ClientInit.bin", list);
|
||||||
|
|
||||||
try s.stream.writer().writeAll(list.items);
|
try s.stream.writer().writeAll(list.items);
|
||||||
|
@ -62,7 +62,7 @@ pub const Client = struct {
|
||||||
try map.put("User", .{ .string = username });
|
try map.put("User", .{ .string = username });
|
||||||
try map.put("Password", .{ .string = password });
|
try map.put("Password", .{ .string = password });
|
||||||
|
|
||||||
try write.add_qvariantmap(s.stream.writer(), map);
|
try write.add_qvariantmap(s.stream.writer(), s.allocator, map);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -51,25 +51,3 @@ pub fn qvariant_type_id(variant: QVariant) !u32 {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn qvariant_size(variant: QVariant) !u32 {
|
|
||||||
var size: u32 = 0;
|
|
||||||
|
|
||||||
switch (variant) {
|
|
||||||
.int => {
|
|
||||||
size += 4;
|
|
||||||
},
|
|
||||||
.byte => {
|
|
||||||
size += 1;
|
|
||||||
},
|
|
||||||
.string => |*str| {
|
|
||||||
size += @intCast(u32, str.len);
|
|
||||||
// Null Terminator
|
|
||||||
size += 1;
|
|
||||||
},
|
|
||||||
else => {
|
|
||||||
size += 0;
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
|
@ -49,7 +49,6 @@ pub fn get_stringlist(reader: anytype, allocator: *std.mem.Allocator) !std.Array
|
||||||
pub fn get_qvariant(reader: anytype) !u32 {
|
pub fn get_qvariant(reader: anytype) !u32 {
|
||||||
var type_id = try get_int(reader);
|
var type_id = try get_int(reader);
|
||||||
// TODO: make nop variants work???
|
// TODO: make nop variants work???
|
||||||
_ = try get_byte(reader);
|
|
||||||
return type_id;
|
return type_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,10 +33,9 @@ pub fn add_stringlist(writer: anytype, strList: std.ArrayList([]const u8)) !void
|
||||||
// Call this and Then write your type
|
// Call this and Then write your type
|
||||||
pub fn add_qvariant_with_id(writer: anytype, type_id: u32) !void {
|
pub fn add_qvariant_with_id(writer: anytype, type_id: u32) !void {
|
||||||
try add_int(writer, type_id);
|
try add_int(writer, type_id);
|
||||||
try add_byte(writer, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_qvariant(writer: anytype, variant: qvar.QVariant) !void {
|
pub fn add_qvariant(writer: anytype, allocator: *std.mem.Allocator, variant: qvar.QVariant) !void {
|
||||||
try add_qvariant_with_id(writer, try qvar.qvariant_type_id(variant));
|
try add_qvariant_with_id(writer, try qvar.qvariant_type_id(variant));
|
||||||
switch (variant) {
|
switch (variant) {
|
||||||
.byte => |out| {
|
.byte => |out| {
|
||||||
|
@ -46,7 +45,7 @@ pub fn add_qvariant(writer: anytype, variant: qvar.QVariant) !void {
|
||||||
try add_int(writer, out);
|
try add_int(writer, out);
|
||||||
},
|
},
|
||||||
.qmap => |out| {
|
.qmap => |out| {
|
||||||
try add_qvariantmap(writer, out);
|
try add_qvariantmap(writer, allocator, out);
|
||||||
},
|
},
|
||||||
.string => |out| {
|
.string => |out| {
|
||||||
try add_string(writer, out);
|
try add_string(writer, out);
|
||||||
|
@ -66,31 +65,23 @@ pub fn add_qvariant(writer: anytype, variant: qvar.QVariant) !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_qvariantmap(writer: anytype, map: std.StringHashMap(qvar.QVariant)) @TypeOf(writer).Error!void {
|
pub fn add_qvariantmap(writer: anytype, allocator: *std.mem.Allocator, map: std.StringHashMap(qvar.QVariant)) (@TypeOf(writer).Error || std.os.WriteError || error{OutOfMemory})!void {
|
||||||
var size: u32 = 0;
|
var data = std.ArrayList(u8).init(allocator);
|
||||||
|
|
||||||
var sizeIterator = map.iterator();
|
|
||||||
|
|
||||||
while (sizeIterator.next()) |entry| {
|
|
||||||
size += try qvar.qvariant_size(.{ .string = entry.key });
|
|
||||||
size += try qvar.qvariant_size(entry.value);
|
|
||||||
size += 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
try add_int(writer, size + 4 + 1 + 4);
|
|
||||||
try add_int(writer, 8);
|
|
||||||
try add_byte(writer, 1);
|
|
||||||
try add_int(writer, map.count());
|
|
||||||
|
|
||||||
var writeIterator = map.iterator();
|
var writeIterator = map.iterator();
|
||||||
|
|
||||||
|
|
||||||
while (writeIterator.next()) |entry| {
|
while (writeIterator.next()) |entry| {
|
||||||
try add_string(writer, entry.key);
|
try add_string(data.writer(), entry.key);
|
||||||
try add_qvariant(writer, entry.value);
|
try add_qvariant(data.writer(), allocator, entry.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
std.debug.print("Size {d} !\n", .{size});
|
// lengths o the mesage
|
||||||
|
try add_int(writer, @intCast(u32, data.items.len) + 4 + 1 + 4);
|
||||||
|
// qvariantmap type
|
||||||
|
try add_int(writer, 8); // 4
|
||||||
|
// validity?
|
||||||
|
try add_byte(writer, 0); // 1
|
||||||
|
// elements
|
||||||
|
try add_int(writer, map.count()); // 4
|
||||||
|
|
||||||
|
try writer.writeAll(data.items);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue