From 85c6f583e5c23a64021aaa80043f5e407c31ab8f Mon Sep 17 00:00:00 2001 From: Kitteh Date: Tue, 1 Jun 2021 13:55:05 +0100 Subject: [PATCH] Add bytearray support. --- src/qtshit/qvariant.zig | 2 ++ src/qtshit/read.zig | 4 ++++ src/qtshit/test.zig | 3 +-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/qtshit/qvariant.zig b/src/qtshit/qvariant.zig index 7581daf..d1952aa 100644 --- a/src/qtshit/qvariant.zig +++ b/src/qtshit/qvariant.zig @@ -4,6 +4,7 @@ pub const QVariant = union { int: u32, short: u16, byte: u8, + bytearray: std.ArrayList(u8), string: []u8, stringlist: std.ArrayList([]const u8), empty: bool, @@ -16,5 +17,6 @@ pub const QVariantTypes = enum(u32) { int_2 = 3, string = 10, stringlist = 11, + bytearray = 12, short = 133, }; \ No newline at end of file diff --git a/src/qtshit/read.zig b/src/qtshit/read.zig index a1fc4fa..bf06115 100644 --- a/src/qtshit/read.zig +++ b/src/qtshit/read.zig @@ -72,6 +72,10 @@ pub fn get_variant_t(reader: anytype, type_id: u32, allocator: *std.mem.Allocato var strlist = try get_stringlist(reader, allocator); return qvar.QVariant{ .stringlist = strlist }; }, + @enumToInt(qvar.QVariantTypes.bytearray) => { + var bArray = try get_bytearray(reader, allocator); + return qvar.QVariant{ .bytearray = bArray }; + }, @enumToInt(qvar.QVariantTypes.short) => { var short = try get_short(reader); return qvar.QVariant{ .short = short }; diff --git a/src/qtshit/test.zig b/src/qtshit/test.zig index ea648ca..fd7c611 100644 --- a/src/qtshit/test.zig +++ b/src/qtshit/test.zig @@ -70,11 +70,10 @@ test "read/write bytearray" { var fBS = std.io.fixedBufferStream(byteList.items); var val = try read.get_bytearray(fBS.reader(), global_allocator); - val.deinit(); + defer val.deinit(); try expect(arr.items.len == val.items.len); for (arr.items) |item, index| { - try std.io.getStdErr().writer().print("{d} vs {d} \n", .{ item, val.items[index] }); try std.testing.expect(item == val.items[index]); } }