From 67c9353455d1570be16e2091be1f95b7516ab152 Mon Sep 17 00:00:00 2001 From: Kitteh Date: Fri, 4 Jun 2021 17:48:50 +0100 Subject: [PATCH] fmt code. --- src/client.zig | 3 +-- src/main.zig | 2 +- src/qtshit/read.zig | 2 +- src/qtshit/read/readByte.zig | 2 +- src/qtshit/read/readLong.zig | 2 +- src/qtshit/read/readQByteArray.zig | 2 +- src/qtshit/read/readQDateTime.zig | 4 ++-- src/qtshit/read/readQVariant.zig | 2 +- src/qtshit/read/readQVariantT.zig | 2 +- src/qtshit/read/readShort.zig | 4 ++-- src/qtshit/read/readSignedByte.zig | 2 +- src/qtshit/read/readString.zig | 14 ++++++++++++-- src/qtshit/read/tests.zig | 2 +- src/qtshit/read/usertypes/readBufferInfo.zig | 2 +- src/qtshit/read/usertypes/readUserType.zig | 3 +-- src/qtshit/read/usertypes/tests.zig | 2 +- src/qtshit/types/QVariant.zig | 2 +- src/qtshit/types/UserType.zig | 2 +- src/qtshit/utils/QVariantMapToQVariantList.zig | 4 ++-- src/qtshit/utils/free/freeQVariant.zig | 1 - src/qtshit/utils/free/freeQVariantMap.zig | 2 +- src/qtshit/utils/unicode.zig | 2 +- src/qtshit/write.zig | 2 +- src/qtshit/write/writeByte.zig | 2 +- src/qtshit/write/writeInt.zig | 2 +- src/qtshit/write/writeQByteArray.zig | 2 +- src/qtshit/write/writeQStringList.zig | 2 +- src/qtshit/write/writeQVariant.zig | 2 +- src/qtshit/write/writeQVariantList.zig | 2 +- src/qtshit/write/writeQVariantMap.zig | 3 +-- src/qtshit/write/writeShort.zig | 2 +- src/qtshit/write/writeSignedByte.zig | 2 +- src/qtshit/write/writeString.zig | 2 +- src/qtshit/write/writeUInt.zig | 2 +- src/tests.zig | 2 +- 35 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/client.zig b/src/client.zig index da66b40..19e9fd7 100644 --- a/src/client.zig +++ b/src/client.zig @@ -6,7 +6,6 @@ const prettyPrintQVariant = @import("./qtshit/utils/prettyPrintQVariant.zig").pr const freeQVariant = @import("./qtshit/utils/free/freeQVariant.zig").freeQVariant; const QVariantMapToQVariantList = @import("./qtshit/utils/QVariantMapToQVariantList.zig").QVariantMapToQVariantList; - fn dumpDebug(name: []const u8, list: std.ArrayList(u8)) !void { std.debug.print("dumpDebug list len {d}\n", .{list.items.len}); @@ -28,7 +27,7 @@ pub const Client = struct { //try write.writeUInt(s.stream.writer(), magic); //try write.writeUInt(s.stream.writer(), 0x80000002); - try s.stream.writer().writeAll(&[_]u8{0x42, 0xb3, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00}); + try s.stream.writer().writeAll(&[_]u8{ 0x42, 0xb3, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00 }); var flags = try read.readByte(s.stream.reader()); var extra = try read.readShort(s.stream.reader()); diff --git a/src/main.zig b/src/main.zig index 384ea34..382de03 100644 --- a/src/main.zig +++ b/src/main.zig @@ -16,7 +16,7 @@ pub fn main() !void { var username = try argIter.next(allocator).?; var password = try argIter.next(allocator).?; - std.debug.print("host={s} port={d}\n", .{host, portInt}); + std.debug.print("host={s} port={d}\n", .{ host, portInt }); var sock = try std.net.tcpConnectToHost(allocator, host, portInt); var client = initClient(allocator, &sock); diff --git a/src/qtshit/read.zig b/src/qtshit/read.zig index 5ea027c..4316ae6 100644 --- a/src/qtshit/read.zig +++ b/src/qtshit/read.zig @@ -9,4 +9,4 @@ pub const readQVariantList = @import("./read/readQVariantList.zig").readQVariant pub const readQVariantT = @import("./read/readQVariantT.zig").readQVariantT; pub const readQVariant = @import("./read/readQVariant.zig").readQVariant; pub const readQVariantMap = @import("./read/readQVariantMap.zig").readQVariantMap; -pub const readQStringList = @import("./read/readQStringList.zig").readQStringList; \ No newline at end of file +pub const readQStringList = @import("./read/readQStringList.zig").readQStringList; diff --git a/src/qtshit/read/readByte.zig b/src/qtshit/read/readByte.zig index b62af66..4946ec4 100644 --- a/src/qtshit/read/readByte.zig +++ b/src/qtshit/read/readByte.zig @@ -11,4 +11,4 @@ test "deserialize byte" { var byte = try readByte(fBS.reader()); try std.testing.expect(byte == 0x01); -} \ No newline at end of file +} diff --git a/src/qtshit/read/readLong.zig b/src/qtshit/read/readLong.zig index f768dae..13b1d4e 100644 --- a/src/qtshit/read/readLong.zig +++ b/src/qtshit/read/readLong.zig @@ -11,4 +11,4 @@ test "deserialize long" { var long = try readLong(fBS.reader()); try std.testing.expect(long == -131200002131); -} \ No newline at end of file +} diff --git a/src/qtshit/read/readQByteArray.zig b/src/qtshit/read/readQByteArray.zig index d0d27ce..254fab3 100644 --- a/src/qtshit/read/readQByteArray.zig +++ b/src/qtshit/read/readQByteArray.zig @@ -36,4 +36,4 @@ test "deserialize QByteArray max length" { var qbytearray = try readQByteArray(fBS.reader(), std.testing.allocator); defer freeQByteArray(qbytearray, std.testing.allocator); try std.testing.expect(std.mem.eql(u8, qbytearray, "")); -} \ No newline at end of file +} diff --git a/src/qtshit/read/readQDateTime.zig b/src/qtshit/read/readQDateTime.zig index 47af277..03933fd 100644 --- a/src/qtshit/read/readQDateTime.zig +++ b/src/qtshit/read/readQDateTime.zig @@ -13,11 +13,11 @@ pub fn readQDateTime(reader: anytype) !QDateTime { } test "deserialize QDateTime" { - var bytes = &[_]u8{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x02 }; + var bytes = &[_]u8{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x02 }; var fBS = std.io.fixedBufferStream(bytes); var qdatetime = try readQDateTime(fBS.reader()); try std.testing.expect(qdatetime.JulianDay == 0x01); try std.testing.expect(qdatetime.MillisOfDay == 0x01); try std.testing.expect(qdatetime.Zone == 0x02); -} \ No newline at end of file +} diff --git a/src/qtshit/read/readQVariant.zig b/src/qtshit/read/readQVariant.zig index 7868827..1a9491f 100644 --- a/src/qtshit/read/readQVariant.zig +++ b/src/qtshit/read/readQVariant.zig @@ -37,4 +37,4 @@ test "deserialize QVariant String" { var qvariant = try readQVariant(fBS.reader(), std.testing.allocator); defer freeQVariant(qvariant, std.testing.allocator); try std.testing.expectEqualStrings(qvariant.String, "ACAB"); -} \ No newline at end of file +} diff --git a/src/qtshit/read/readQVariantT.zig b/src/qtshit/read/readQVariantT.zig index cdfa932..bb9be97 100644 --- a/src/qtshit/read/readQVariantT.zig +++ b/src/qtshit/read/readQVariantT.zig @@ -18,7 +18,7 @@ const readUserType = @import("./usertypes/readUserType.zig").readUserType; const QVariant = @import("../types/QVariant.zig").QVariant; 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} || error{DecodeError} || ReadStringErrors ) !QVariant { +pub fn readQVariantT(reader: anytype, type_id: u32, allocator: *std.mem.Allocator) (@TypeOf(reader).Error || error{EndOfStream} || error{OutOfMemory} || error{DecodeError} || ReadStringErrors)!QVariant { switch (type_id) { @enumToInt(QVariantTypes.Byte) => { var byte = try readByte(reader); diff --git a/src/qtshit/read/readShort.zig b/src/qtshit/read/readShort.zig index beff4a3..7f80c7f 100644 --- a/src/qtshit/read/readShort.zig +++ b/src/qtshit/read/readShort.zig @@ -6,10 +6,10 @@ pub fn readShort(reader: anytype) !u16 { } test "deserialize short" { - var bytes = &[_]u8{0x13, 0x12}; + var bytes = &[_]u8{ 0x13, 0x12 }; var fBS = std.io.fixedBufferStream(bytes); var short = try readShort(fBS.reader()); try std.testing.expect(short == 0x1312); -} \ No newline at end of file +} diff --git a/src/qtshit/read/readSignedByte.zig b/src/qtshit/read/readSignedByte.zig index 628b67b..b610ba5 100644 --- a/src/qtshit/read/readSignedByte.zig +++ b/src/qtshit/read/readSignedByte.zig @@ -11,4 +11,4 @@ test "deserialize signed byte" { var signedByte = try readSignedByte(fBS.reader()); try std.testing.expect(signedByte == -69); -} \ No newline at end of file +} diff --git a/src/qtshit/read/readString.zig b/src/qtshit/read/readString.zig index f312f64..e3cd331 100644 --- a/src/qtshit/read/readString.zig +++ b/src/qtshit/read/readString.zig @@ -26,7 +26,18 @@ pub fn readString(reader: anytype, allocator: *std.mem.Allocator) (@TypeOf(reade } test "deserialize String" { - var bytes = &[_]u8{ 0, 0, 0, 6, 0, 111, 0, 119, 0, 111, }; + var bytes = &[_]u8{ + 0, + 0, + 0, + 6, + 0, + 111, + 0, + 119, + 0, + 111, + }; var fBS = std.io.fixedBufferStream(bytes); var str = try readString(fBS.reader(), std.testing.allocator); @@ -34,4 +45,3 @@ test "deserialize String" { try std.testing.expectEqualStrings("owo", str); } - diff --git a/src/qtshit/read/tests.zig b/src/qtshit/read/tests.zig index c76ea7f..bdd9e77 100644 --- a/src/qtshit/read/tests.zig +++ b/src/qtshit/read/tests.zig @@ -13,4 +13,4 @@ const readSignedByte = @import("./readSignedByte.zig"); comptime { @import("std").testing.refAllDecls(@This()); -} \ No newline at end of file +} diff --git a/src/qtshit/read/usertypes/readBufferInfo.zig b/src/qtshit/read/usertypes/readBufferInfo.zig index ab2c3b7..5a7d892 100644 --- a/src/qtshit/read/usertypes/readBufferInfo.zig +++ b/src/qtshit/read/usertypes/readBufferInfo.zig @@ -38,4 +38,4 @@ test "deserialize BufferInfo" { try std.testing.expect(bufferInfo.NetworkID == 1); try std.testing.expect(bufferInfo.Type == 2); try std.testing.expectEqualStrings("#test", bufferInfo.Name); -} \ No newline at end of file +} diff --git a/src/qtshit/read/usertypes/readUserType.zig b/src/qtshit/read/usertypes/readUserType.zig index 413e353..97569c5 100644 --- a/src/qtshit/read/usertypes/readUserType.zig +++ b/src/qtshit/read/usertypes/readUserType.zig @@ -10,7 +10,6 @@ const readQVariantMap = @import("../readQVariantMap.zig").readQVariantMap; const readBufferInfo = @import("./readBufferInfo.zig").readBufferInfo; const readMessage = @import("./readMessage.zig").readMessage; - pub fn readUserType(reader: anytype, allocator: *std.mem.Allocator) !UserType { var userTypeName = try readQByteArray(reader, allocator); userTypeName = userTypeName[0 .. userTypeName.len - 1]; @@ -64,7 +63,7 @@ pub fn readUserType(reader: anytype, allocator: *std.mem.Allocator) !UserType { return UserType{ .Message = try readMessage(reader, allocator), }; - }else { + } else { std.debug.print("Unknown UserType With Name: {s}\n", .{userTypeName}); @panic("Unknown Usertype."); } diff --git a/src/qtshit/read/usertypes/tests.zig b/src/qtshit/read/usertypes/tests.zig index 585a628..d5f2ef3 100644 --- a/src/qtshit/read/usertypes/tests.zig +++ b/src/qtshit/read/usertypes/tests.zig @@ -3,4 +3,4 @@ const readMessage = @import("./readMessage.zig"); comptime { @import("std").testing.refAllDecls(@This()); -} \ No newline at end of file +} diff --git a/src/qtshit/types/QVariant.zig b/src/qtshit/types/QVariant.zig index 0aec4cf..15b70b4 100644 --- a/src/qtshit/types/QVariant.zig +++ b/src/qtshit/types/QVariant.zig @@ -19,4 +19,4 @@ pub const QDateTime = struct { JulianDay: i32, MillisOfDay: i32, Zone: u8, -}; \ No newline at end of file +}; diff --git a/src/qtshit/types/UserType.zig b/src/qtshit/types/UserType.zig index 2754f65..1b72b35 100644 --- a/src/qtshit/types/UserType.zig +++ b/src/qtshit/types/UserType.zig @@ -34,4 +34,4 @@ pub const Message = struct { RealName: []u8, AvatarUrl: []u8, Content: []u8, -}; \ No newline at end of file +}; diff --git a/src/qtshit/utils/QVariantMapToQVariantList.zig b/src/qtshit/utils/QVariantMapToQVariantList.zig index 6dfc5f0..823532f 100644 --- a/src/qtshit/utils/QVariantMapToQVariantList.zig +++ b/src/qtshit/utils/QVariantMapToQVariantList.zig @@ -7,11 +7,11 @@ pub fn QVariantMapToQVariantList(varMap: std.StringHashMap(QVariant), allocator: 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] = QVariant{ .String = item.key }; variantList[i + 1] = item.value; } return variantList; diff --git a/src/qtshit/utils/free/freeQVariant.zig b/src/qtshit/utils/free/freeQVariant.zig index 51f6a35..62ebac0 100644 --- a/src/qtshit/utils/free/freeQVariant.zig +++ b/src/qtshit/utils/free/freeQVariant.zig @@ -7,7 +7,6 @@ const freeQByteArray = @import("./freeQByteArray.zig").freeQByteArray; const freeString = @import("./freeString.zig").freeString; const freeUserType = @import("./freeUserType.zig").freeUserType; - pub fn freeQVariant(variant: QVariant, allocator: *std.mem.Allocator) void { switch (variant) { .Byte, .Int, .UInt, .Short, .QDateTime => { diff --git a/src/qtshit/utils/free/freeQVariantMap.zig b/src/qtshit/utils/free/freeQVariantMap.zig index e27e122..1d873a8 100644 --- a/src/qtshit/utils/free/freeQVariantMap.zig +++ b/src/qtshit/utils/free/freeQVariantMap.zig @@ -12,4 +12,4 @@ pub fn freeQVariantMap(qvariantmap: std.StringHashMap(QVariant), allocator: *std // Compiler bug maybe? doesnt want me to drop const so have to store it in a variable var qi = qvariantmap; qi.deinit(); -} \ No newline at end of file +} diff --git a/src/qtshit/utils/unicode.zig b/src/qtshit/utils/unicode.zig index bcaa5a2..4811343 100644 --- a/src/qtshit/utils/unicode.zig +++ b/src/qtshit/utils/unicode.zig @@ -40,4 +40,4 @@ test "utf8 and utf16BE conversion" { defer testing.allocator.free(utf8Decoded); try testing.expectEqualStrings(utf8, utf8Decoded); -} \ No newline at end of file +} diff --git a/src/qtshit/write.zig b/src/qtshit/write.zig index 837c1de..08b7c6a 100644 --- a/src/qtshit/write.zig +++ b/src/qtshit/write.zig @@ -10,4 +10,4 @@ pub const writeQVariantList = @import("./write/writeQVariantList.zig").writeQVar pub const writeQVariantHeader = @import("./write/writeQVariantHeader.zig").writeQVariantHeader; pub const writeQVariant = @import("./write/writeQVariant.zig").writeQVariant; pub const writeQVariantMap = @import("./write/writeQVariantMap.zig").writeQVariantMap; -pub const writeFrame = @import("./write/writeFrame.zig").writeFrame; \ No newline at end of file +pub const writeFrame = @import("./write/writeFrame.zig").writeFrame; diff --git a/src/qtshit/write/writeByte.zig b/src/qtshit/write/writeByte.zig index 8db7c99..740008e 100644 --- a/src/qtshit/write/writeByte.zig +++ b/src/qtshit/write/writeByte.zig @@ -1,3 +1,3 @@ pub fn writeByte(writer: anytype, byte: u8) !void { try writer.writeByte(byte); -} \ No newline at end of file +} diff --git a/src/qtshit/write/writeInt.zig b/src/qtshit/write/writeInt.zig index eb150b1..0dad30b 100644 --- a/src/qtshit/write/writeInt.zig +++ b/src/qtshit/write/writeInt.zig @@ -1,3 +1,3 @@ pub fn writeInt(writer: anytype, number: i32) !void { try writer.writeIntBig(i32, number); -} \ No newline at end of file +} diff --git a/src/qtshit/write/writeQByteArray.zig b/src/qtshit/write/writeQByteArray.zig index 337b10b..a75764f 100644 --- a/src/qtshit/write/writeQByteArray.zig +++ b/src/qtshit/write/writeQByteArray.zig @@ -3,4 +3,4 @@ const writeUInt = @import("./writeUInt.zig").writeUInt; pub fn writeQByteArray(writer: anytype, array: []u8) !void { try writeUInt(writer, @intCast(u32, array.len)); try writer.writeAll(array); -} \ No newline at end of file +} diff --git a/src/qtshit/write/writeQStringList.zig b/src/qtshit/write/writeQStringList.zig index ed46cb5..b28ebcc 100644 --- a/src/qtshit/write/writeQStringList.zig +++ b/src/qtshit/write/writeQStringList.zig @@ -7,4 +7,4 @@ pub fn writeQStringList(writer: anytype, allocator: *std.mem.Allocator, strList: for (strList) |string| { try writeString(writer, allocator, string); } -} \ No newline at end of file +} diff --git a/src/qtshit/write/writeQVariant.zig b/src/qtshit/write/writeQVariant.zig index 1e0f62c..cf7154b 100644 --- a/src/qtshit/write/writeQVariant.zig +++ b/src/qtshit/write/writeQVariant.zig @@ -54,4 +54,4 @@ pub fn writeQVariant(writer: anytype, allocator: *std.mem.Allocator, variant: QV // @panic("Unsupported!"); //}, } -} \ No newline at end of file +} diff --git a/src/qtshit/write/writeQVariantList.zig b/src/qtshit/write/writeQVariantList.zig index 5258d5c..8f24340 100644 --- a/src/qtshit/write/writeQVariantList.zig +++ b/src/qtshit/write/writeQVariantList.zig @@ -8,4 +8,4 @@ pub fn writeQVariantList(writer: anytype, allocator: *std.mem.Allocator, varList for (varList) |v| { try writeQVariant(writer, allocator, v); } -} \ No newline at end of file +} diff --git a/src/qtshit/write/writeQVariantMap.zig b/src/qtshit/write/writeQVariantMap.zig index e778d65..a04f6c0 100644 --- a/src/qtshit/write/writeQVariantMap.zig +++ b/src/qtshit/write/writeQVariantMap.zig @@ -4,7 +4,6 @@ const writeString = @import("./writeString.zig").writeString; const writeUInt = @import("./writeUInt.zig").writeUInt; const writeQVariant = @import("./writeQVariant.zig").writeQVariant; - pub fn writeQVariantMap(writer: anytype, allocator: *std.mem.Allocator, map: std.StringHashMap(QVariantType)) !void { var data = std.ArrayList(u8).init(allocator); defer data.deinit(); @@ -19,4 +18,4 @@ pub fn writeQVariantMap(writer: anytype, allocator: *std.mem.Allocator, map: std try writer.writeAll(data.items); return; -} \ No newline at end of file +} diff --git a/src/qtshit/write/writeShort.zig b/src/qtshit/write/writeShort.zig index 2a7f0d2..c360a2f 100644 --- a/src/qtshit/write/writeShort.zig +++ b/src/qtshit/write/writeShort.zig @@ -1,3 +1,3 @@ pub fn writeShort(writer: anytype, number: u16) !void { try writer.writeIntBig(u16, number); -} \ No newline at end of file +} diff --git a/src/qtshit/write/writeSignedByte.zig b/src/qtshit/write/writeSignedByte.zig index 1314026..bbd1cef 100644 --- a/src/qtshit/write/writeSignedByte.zig +++ b/src/qtshit/write/writeSignedByte.zig @@ -1,3 +1,3 @@ pub fn writeSignedByte(writer: anytype, byte: i8) !void { try writer.writeIntBig(i8, number); -} \ No newline at end of file +} diff --git a/src/qtshit/write/writeString.zig b/src/qtshit/write/writeString.zig index f05139a..84875ad 100644 --- a/src/qtshit/write/writeString.zig +++ b/src/qtshit/write/writeString.zig @@ -11,4 +11,4 @@ pub fn writeString(writer: anytype, allocator: *std.mem.Allocator, str: []const // len * 2 because length of u8 not length of u16. try writeInt(writer, @intCast(i32, str_utf16BE.len * 2)); try writer.writeAll(std.mem.sliceAsBytes(str_utf16BE)); -} \ No newline at end of file +} diff --git a/src/qtshit/write/writeUInt.zig b/src/qtshit/write/writeUInt.zig index cd3d8d5..6d40257 100644 --- a/src/qtshit/write/writeUInt.zig +++ b/src/qtshit/write/writeUInt.zig @@ -1,3 +1,3 @@ pub fn writeUInt(writer: anytype, number: u32) !void { try writer.writeIntBig(u32, number); -} \ No newline at end of file +} diff --git a/src/tests.zig b/src/tests.zig index d91cc31..d585522 100644 --- a/src/tests.zig +++ b/src/tests.zig @@ -3,4 +3,4 @@ const unicode = @import("qtshit/utils/unicode.zig"); comptime { @import("std").testing.refAllDecls(@This()); -} \ No newline at end of file +}