fmt code.
This commit is contained in:
parent
1ec3cfb28f
commit
67c9353455
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
pub const readQStringList = @import("./read/readQStringList.zig").readQStringList;
|
||||
|
|
|
@ -11,4 +11,4 @@ test "deserialize byte" {
|
|||
var byte = try readByte(fBS.reader());
|
||||
|
||||
try std.testing.expect(byte == 0x01);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,4 +11,4 @@ test "deserialize long" {
|
|||
|
||||
var long = try readLong(fBS.reader());
|
||||
try std.testing.expect(long == -131200002131);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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, ""));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,4 +11,4 @@ test "deserialize signed byte" {
|
|||
|
||||
var signedByte = try readSignedByte(fBS.reader());
|
||||
try std.testing.expect(signedByte == -69);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,4 +13,4 @@ const readSignedByte = @import("./readSignedByte.zig");
|
|||
|
||||
comptime {
|
||||
@import("std").testing.refAllDecls(@This());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
|
|
@ -3,4 +3,4 @@ const readMessage = @import("./readMessage.zig");
|
|||
|
||||
comptime {
|
||||
@import("std").testing.refAllDecls(@This());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,4 +19,4 @@ pub const QDateTime = struct {
|
|||
JulianDay: i32,
|
||||
MillisOfDay: i32,
|
||||
Zone: u8,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -34,4 +34,4 @@ pub const Message = struct {
|
|||
RealName: []u8,
|
||||
AvatarUrl: []u8,
|
||||
Content: []u8,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,4 +40,4 @@ test "utf8 and utf16BE conversion" {
|
|||
defer testing.allocator.free(utf8Decoded);
|
||||
|
||||
try testing.expectEqualStrings(utf8, utf8Decoded);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
pub const writeFrame = @import("./write/writeFrame.zig").writeFrame;
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
pub fn writeByte(writer: anytype, byte: u8) !void {
|
||||
try writer.writeByte(byte);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
pub fn writeInt(writer: anytype, number: i32) !void {
|
||||
try writer.writeIntBig(i32, number);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,4 +7,4 @@ pub fn writeQStringList(writer: anytype, allocator: *std.mem.Allocator, strList:
|
|||
for (strList) |string| {
|
||||
try writeString(writer, allocator, string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,4 +54,4 @@ pub fn writeQVariant(writer: anytype, allocator: *std.mem.Allocator, variant: QV
|
|||
// @panic("Unsupported!");
|
||||
//},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,4 +8,4 @@ pub fn writeQVariantList(writer: anytype, allocator: *std.mem.Allocator, varList
|
|||
for (varList) |v| {
|
||||
try writeQVariant(writer, allocator, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
pub fn writeShort(writer: anytype, number: u16) !void {
|
||||
try writer.writeIntBig(u16, number);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
pub fn writeSignedByte(writer: anytype, byte: i8) !void {
|
||||
try writer.writeIntBig(i8, number);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
pub fn writeUInt(writer: anytype, number: u32) !void {
|
||||
try writer.writeIntBig(u32, number);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,4 +3,4 @@ const unicode = @import("qtshit/utils/unicode.zig");
|
|||
|
||||
comptime {
|
||||
@import("std").testing.refAllDecls(@This());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue