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),
string: []const u8,
stringlist: std.ArrayList([]const u8),
qmap: std.StringHashMap(QVariant),
empty: bool,
};
@ -27,7 +28,7 @@ pub fn qvariant_type_id(variant: QVariant) !u32 {
.byte => {
return @enumToInt(QVariantTypes.byte);
},
.int_1, .int_2 => {
.int => {
return @enumToInt(QVariantTypes.int_1);
},
.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 {
add_qvariant_with_id(writer, qvar.qvariant_type_id(variant));
try add_qvariant_with_id(writer, try qvar.qvariant_type_id(variant));
switch (variant) {
.byte => |*out| {
return add_byte(writer, out);
.byte => |out| {
try add_byte(writer, out);
},
.int_1, .int_2 => |*out| {
return add_int(writer, out);
.int => |out| {
try add_int(writer, out);
},
.qmap => |*out| {
return add_qvariantmap(writer, out);
.qmap => |out| {
try add_qvariantmap(writer, out);
},
.string => |*out| {
return add_string(writer, out);
.string => |out| {
try add_string(writer, out);
},
.stringlist => |*out| {
return add_stringlist(writer, out);
.stringlist => |out| {
try add_stringlist(writer, out);
},
.bytearray => |*out| {
return add_bytearray(writer, out);
.bytearray => |out| {
try add_bytearray(writer, out);
},
.short => |*out| {
return add_short(writer, out);
.short => |out| {
try add_short(writer, out);
},
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());
while (iterator.next()) |entry| {
size += try qvar.qvariant_size(.{ .string = entry.key });
size += try qvar.qvariant_size(entry.value);
size += 4;
try add_string(writer, entry.key);
try add_qvariant(writer, entry.value);
}
std.debug.print("Size {d} !\n", .{size});