This commit is contained in:
Kitteh 2021-06-02 12:37:35 +01:00
parent c3589cd74f
commit a55a44e9c1
2 changed files with 20 additions and 20 deletions

View file

@ -7,6 +7,7 @@ pub const QVariant = union(enum) {
bytearray: std.ArrayList(u8), bytearray: std.ArrayList(u8),
string: []const u8, string: []const u8,
stringlist: std.ArrayList([]const u8), stringlist: std.ArrayList([]const u8),
qmap: std.StringHashMap(QVariant),
empty: bool, empty: bool,
}; };
@ -27,7 +28,7 @@ pub fn qvariant_type_id(variant: QVariant) !u32 {
.byte => { .byte => {
return @enumToInt(QVariantTypes.byte); return @enumToInt(QVariantTypes.byte);
}, },
.int_1, .int_2 => { .int => {
return @enumToInt(QVariantTypes.int_1); return @enumToInt(QVariantTypes.int_1);
}, },
.qmap => { .qmap => {

View file

@ -37,31 +37,31 @@ pub fn add_qvariant_with_id(writer: anytype, type_id: u32) !void {
} }
pub fn add_qvariant(writer: anytype, variant: qvar.QVariant) !void { pub fn add_qvariant(writer: anytype, variant: qvar.QVariant) !void {
add_qvariant_with_id(writer, 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| {
return add_byte(writer, out); try add_byte(writer, out);
}, },
.int_1, .int_2 => |*out| { .int => |out| {
return add_int(writer, out); try add_int(writer, out);
}, },
.qmap => |*out| { .qmap => |out| {
return add_qvariantmap(writer, out); try add_qvariantmap(writer, out);
}, },
.string => |*out| { .string => |out| {
return add_string(writer, out); try add_string(writer, out);
}, },
.stringlist => |*out| { .stringlist => |out| {
return add_stringlist(writer, out); try add_stringlist(writer, out);
}, },
.bytearray => |*out| { .bytearray => |out| {
return add_bytearray(writer, out); try add_bytearray(writer, out);
}, },
.short => |*out| { .short => |out| {
return add_short(writer, out); try add_short(writer, out);
}, },
else => { else => {
return 0; return;
}, },
} }
} }
@ -83,9 +83,8 @@ pub fn add_qvariantmap(writer: anytype, map: std.StringHashMap(qvar.QVariant)) !
try add_int(writer, map.count()); try add_int(writer, map.count());
while (iterator.next()) |entry| { while (iterator.next()) |entry| {
size += try qvar.qvariant_size(.{ .string = entry.key }); try add_string(writer, entry.key);
size += try qvar.qvariant_size(entry.value); try add_qvariant(writer, entry.value);
size += 4;
} }
std.debug.print("Size {d} !\n", .{size}); std.debug.print("Size {d} !\n", .{size});