Add bytearray support.
This commit is contained in:
parent
6328879b96
commit
85c6f583e5
|
@ -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,
|
||||
};
|
|
@ -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 };
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue