map to array fizzbuzz technique
This commit is contained in:
parent
4d36de6c5d
commit
04385070f1
|
@ -4,6 +4,8 @@ const write = @import("./qtshit/write.zig");
|
||||||
const QVariantType = @import("./qtshit/types/QVariant.zig").QVariant;
|
const QVariantType = @import("./qtshit/types/QVariant.zig").QVariant;
|
||||||
const prettyPrintQVariant = @import("./qtshit/utils/prettyPrintQVariant.zig").prettyPrintQVariant;
|
const prettyPrintQVariant = @import("./qtshit/utils/prettyPrintQVariant.zig").prettyPrintQVariant;
|
||||||
const freeQVariant = @import("./qtshit/utils/freeQVariant.zig").freeQVariant;
|
const freeQVariant = @import("./qtshit/utils/freeQVariant.zig").freeQVariant;
|
||||||
|
const QVariantMapToQVariantList = @import("./qtshit/utils/QVariantMapToQVariantList.zig").QVariantMapToQVariantList;
|
||||||
|
|
||||||
|
|
||||||
fn dumpDebug(name: []const u8, list: std.ArrayList(u8)) !void {
|
fn dumpDebug(name: []const u8, list: std.ArrayList(u8)) !void {
|
||||||
std.debug.print("dumpDebug list len {d}\n", .{list.items.len});
|
std.debug.print("dumpDebug list len {d}\n", .{list.items.len});
|
||||||
|
|
|
@ -24,6 +24,12 @@ pub fn main() !void {
|
||||||
try client.quassel_init_packet();
|
try client.quassel_init_packet();
|
||||||
try client.quassel_login(username, password);
|
try client.quassel_login(username, password);
|
||||||
while (true) {
|
while (true) {
|
||||||
try client.read_quassel_packet();
|
client.read_quassel_packet() catch |err| {
|
||||||
|
if (err == error.DecodeError) {
|
||||||
|
std.debug.print("Decode Error.\n", .{});
|
||||||
|
} else {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ const readUserType = @import("./usertypes/readUserType.zig").readUserType;
|
||||||
const QVariant = @import("../types/QVariant.zig").QVariant;
|
const QVariant = @import("../types/QVariant.zig").QVariant;
|
||||||
const QVariantTypes = @import("../types/QVariantTypes.zig").QVariantTypes;
|
const QVariantTypes = @import("../types/QVariantTypes.zig").QVariantTypes;
|
||||||
|
|
||||||
pub fn readQVariantT(reader: anytype, type_id: u32, allocator: *std.mem.Allocator) (@TypeOf(reader).Error || error{EndOfStream} || error{OutOfMemory})!QVariant {
|
pub fn readQVariantT(reader: anytype, type_id: u32, allocator: *std.mem.Allocator) (@TypeOf(reader).Error || error{EndOfStream} || error{OutOfMemory} || error{DecodeError})!QVariant {
|
||||||
switch (type_id) {
|
switch (type_id) {
|
||||||
@enumToInt(QVariantTypes.Byte) => {
|
@enumToInt(QVariantTypes.Byte) => {
|
||||||
var byte = try readByte(reader);
|
var byte = try readByte(reader);
|
||||||
|
@ -65,9 +65,7 @@ pub fn readQVariantT(reader: anytype, type_id: u32, allocator: *std.mem.Allocato
|
||||||
},
|
},
|
||||||
else => {
|
else => {
|
||||||
std.debug.print("Unknown Type ID: {d}\n", .{type_id});
|
std.debug.print("Unknown Type ID: {d}\n", .{type_id});
|
||||||
return QVariant{ .String = "UnknownType" };
|
return error.DecodeError;
|
||||||
|
|
||||||
//@panic("Unknown Type See Above.");
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return QVariant{ .empty = true };
|
return QVariant{ .empty = true };
|
||||||
|
|
18
src/qtshit/utils/QVariantMapToQVariantList.zig
Normal file
18
src/qtshit/utils/QVariantMapToQVariantList.zig
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
const std = @import("std");
|
||||||
|
const QVariant = @import("../types/QVariant.zig").QVariant;
|
||||||
|
const range = @import("./RangeIter.zig").range;
|
||||||
|
|
||||||
|
pub fn QVariantMapToQVariantList(varMap: std.StringHashMap(QVariant), allocator: *std.mem.Allocator) ![]QVariant {
|
||||||
|
var variantList = try allocator.alloc(QVariant, @intCast(usize, varMap.count() * 2));
|
||||||
|
|
||||||
|
var varMapIter = varMap.iterator();
|
||||||
|
var iter = range(u32, 0, varMap.count() * 2);
|
||||||
|
|
||||||
|
while (iter.next()) |i| {
|
||||||
|
if (i % 2 == 1) continue;
|
||||||
|
var item = varMapIter.next().?;
|
||||||
|
variantList[i] = QVariant{.String = item.key};
|
||||||
|
variantList[i + 1] = item.value;
|
||||||
|
}
|
||||||
|
return variantList;
|
||||||
|
}
|
Loading…
Reference in a new issue