diff --git a/src/main.zig b/src/main.zig index 603d26b..a7522f4 100644 --- a/src/main.zig +++ b/src/main.zig @@ -3,7 +3,6 @@ const std = @import("std"); const read = @import("./qtshit/read.zig"); const write = @import("./qtshit/write.zig"); - pub fn main() !void { const stdout = std.io.getStdOut().writer(); try stdout.print("Hello, {s}!\n", .{"world"}); @@ -11,9 +10,13 @@ pub fn main() !void { var byteList = std.ArrayList(u8).init(std.heap.page_allocator); defer byteList.deinit(); - try write.add_int(byteList.writer(), 4242); + // Write + try write.add_int(byteList.writer(), 9999); + try write.add_byte(byteList.writer(), 'a'); - var reader = std.io.fixedBufferStream(byteList.items).reader(); - try stdout.print("Number: {} \n", .{try read.get_int(reader)}); - -} \ No newline at end of file + // Read + var fBS = std.io.fixedBufferStream(byteList.items); + try stdout.print("int: {d} \n", .{try read.get_int(fBS.reader())}); + try stdout.print("byte: {c} \n", .{try read.get_byte(fBS.reader())}); + +} diff --git a/src/qtshit/read.zig b/src/qtshit/read.zig index 2e9b61a..09086b9 100644 --- a/src/qtshit/read.zig +++ b/src/qtshit/read.zig @@ -1,3 +1,21 @@ -pub fn get_int(reader: anytype) !u16 { +pub fn get_int(reader: anytype) !u32 { + return try reader.readIntBig(u32); +} + +pub fn get_short(reader: anytype) !u16 { return try reader.readIntBig(u16); +} + +pub fn get_byte(reader: anytype) !u8 { + return try reader.readByte(); +} + +pub fn get_string(reader: anytype, allocator: std.mem.Allocator) ![]u8 { + var buffer: [1024]u8 = undefined; + + return try reader.readUntilDelimiterAlloc( + allocator, + '\0', + 1024, + ); } \ No newline at end of file diff --git a/src/qtshit/test.zig b/src/qtshit/test.zig new file mode 100644 index 0000000..5708b06 --- /dev/null +++ b/src/qtshit/test.zig @@ -0,0 +1,53 @@ +const std = @import("std"); +const expect = std.testing.expect; + +const read = @import("./read.zig"); +const write = @import("./write.zig"); + +test "read/write int" { + var byteList = std.ArrayList(u8).init(std.heap.page_allocator); + defer byteList.deinit(); + + try write.add_int(byteList.writer(), 4242); + + var fBS = std.io.fixedBufferStream(byteList.items); + var val = try read.get_int(fBS.reader()); + + try expect(val == 4242); +} + +test "read/write short" { + var byteList = std.ArrayList(u8).init(std.heap.page_allocator); + defer byteList.deinit(); + + try write.add_short(byteList.writer(), 6969); + + var fBS = std.io.fixedBufferStream(byteList.items); + var val = try read.get_short(fBS.reader()); + + try expect(val == 6969); +} + +test "read/write byte" { + var byteList = std.ArrayList(u8).init(std.heap.page_allocator); + defer byteList.deinit(); + + try write.add_byte(byteList.writer(), 'a'); + + var fBS = std.io.fixedBufferStream(byteList.items); + var val = try read.get_byte(fBS.reader()); + + try expect(val == 'a'); +} + +test "read/write string" { + var byteList = std.ArrayList(u8).init(std.heap.page_allocator); + defer byteList.deinit(); + + try write.add_string(byteList.writer(), "Hello World!"); + + var fBS = std.io.fixedBufferStream(byteList.items); + var val = try read.get_string(fBS.reader()); + + try expect(std.mem.eql(u8, val, "Hello World!")); +} \ No newline at end of file diff --git a/src/qtshit/write.zig b/src/qtshit/write.zig index 656e015..94c7efa 100644 --- a/src/qtshit/write.zig +++ b/src/qtshit/write.zig @@ -1,6 +1,16 @@ -const std = @import("std"); - - -pub fn add_int(writer: anytype, number: u16) !void { +pub fn add_int(writer: anytype, number: u32) !void { try writer.writeIntBig(u32, number); +} + +pub fn add_short(writer: anytype, number: u16) !void { + try writer.writeIntBig(u16, number); +} + +pub fn add_byte(writer: anytype, byte: u8) !void { + try writer.writeByte(byte); +} + +pub fn add_string(writer: anytype, str: []u8) !void { + try writer.writeAll(str); + try writer.writeByte('\0'); } \ No newline at end of file diff --git a/src/qtshit/zig-cache/h/e2794c501721bfa6aa74d0b6a7237e2a.txt b/src/qtshit/zig-cache/h/e2794c501721bfa6aa74d0b6a7237e2a.txt new file mode 100644 index 0000000..428243f --- /dev/null +++ b/src/qtshit/zig-cache/h/e2794c501721bfa6aa74d0b6a7237e2a.txt @@ -0,0 +1,74 @@ +1062 1052843 1622541843780976996 537312898de534a981824375ec7211f7 /home/username/Projects/QuasselClient/src/qtshit/test.zig +5588 1081028 1622401981000000000 b28e8846a1fb551a569b56fcf123a093 /home/username/Zig/lib/std/std.zig +23635 1081029 1622401981000000000 00fbb8fea25ef05eeba646e26bb20cb6 /home/username/Zig/lib/std/builtin.zig +5086 1080039 1622401981000000000 d6192441c7258db0547cd11c747ddbd1 /home/username/Zig/lib/std/special/test_runner.zig +18282 1081153 1622401981000000000 c0d058ca884fd934a4f43772515ed826 /home/username/Zig/lib/std/start.zig +57926 1081063 1622401981000000000 ba9d80f4cc927315081961166c8c064f /home/username/Zig/lib/std/target.zig +85319 1081087 1622401981000000000 0a2500be811fa3aa250ce61f7121590b /home/username/Zig/lib/std/target/x86.zig +53217 1081066 1622401981000000000 a9590499d5dc3a7d3cd7aa9b375738cb /home/username/Zig/lib/std/math.zig +47037 1081173 1622401981000000000 1d2192661909773f951eface449f4c97 /home/username/Zig/lib/std/meta.zig +76171 1080872 1622401981000000000 e42b2515d2bd2ca1a758f94674ca1b4f /home/username/Zig/lib/std/debug.zig +49868 1081071 1622401981000000000 579c8d5bf9a8971a2e20fad1dbd9adce /home/username/Zig/lib/std/array_list.zig +102633 1080836 1622401981000000000 826ba94a31dac302fd13d076454534d6 /home/username/Zig/lib/std/mem.zig +20541 1081068 1622401981000000000 df4b1840f51e60f5bdbc1dbedc7e092a /home/username/Zig/lib/std/mem/Allocator.zig +44450 1080705 1622401981000000000 61ecf1dfc1bbc08a4fc62b44be4f2fcc /home/username/Zig/lib/std/heap.zig +389 1068873 1622542030348440681 088f9cea3c75b70a90a403a80b9d43e4 /home/username/Projects/QuasselClient/src/qtshit/write.zig +6937 1081250 1622401981000000000 13d91209e7be79b263b6bdba75c5d7bd /home/username/Zig/lib/std/io.zig +3733 1081259 1622401981000000000 21a631d05e989504b4ff3183a5d4268d /home/username/Zig/lib/std/io/writer.zig +5865 1081271 1622401981000000000 e4969eefc8d5e0daa48c3e49f4d7bf71 /home/username/Zig/lib/std/io/fixed_buffer_stream.zig +232 1061251 1622541451275968778 79d4a90da2f289f7bb97bfddaf2a44ec /home/username/Projects/QuasselClient/src/qtshit/read.zig +14707 1081262 1622401981000000000 ef35513a84751410d70fd0001a426f7c /home/username/Zig/lib/std/io/reader.zig +17680 1081150 1622401981000000000 d776aafb7ce0e1372623be706e5dba7c /home/username/Zig/lib/std/testing.zig +22756 1081122 1622401981000000000 d07ee73ddafae63b19ceef726d648e26 /home/username/Zig/lib/std/Thread.zig +8975 1080902 1622401981000000000 b3d72eb864f407db2c95dd6627fba4d3 /home/username/Zig/lib/std/Thread/Mutex.zig +111311 1080904 1622401981000000000 dd71f5dee8eb8d5b7b14ba6c7d2974b6 /home/username/Zig/lib/std/fs.zig +34154 1081054 1622401981000000000 06743bf9e2e200fec8f39a1d3596ba9f /home/username/Zig/lib/std/fs/file.zig +244016 1081022 1622401981000000000 ba35dc375979b529726bc588db1db177 /home/username/Zig/lib/std/os.zig +1777 1080910 1622401981000000000 8d2a34ac655098558374af64bfaa8252 /home/username/Zig/lib/std/os/bits.zig +63204 1081019 1622401981000000000 527fdf9fee2bc4585f4c6fc3e3ff4757 /home/username/Zig/lib/std/os/bits/linux.zig +8916 1081013 1622401981000000000 e9a3f40802d95a6a4b68af3fcfd14cd8 /home/username/Zig/lib/std/os/bits/linux/netlink.zig +6793 1081003 1622401981000000000 a2a3eb5025cf366e1f9966fbd4b73635 /home/username/Zig/lib/std/os/bits/linux/prctl.zig +1569 1081007 1622401981000000000 762bf41249b51deb66386a42d8c2719f /home/username/Zig/lib/std/os/bits/linux/securebits.zig +13413 1081014 1622401981000000000 b0c4c5f4b2828077f67ffc53afd1aadd /home/username/Zig/lib/std/os/bits/linux/x86_64.zig +8548 1081004 1622401981000000000 fa7bade920f4bed7f523840a46fbc2a7 /home/username/Zig/lib/std/os/bits/linux/errno-generic.zig +14029 1080900 1622401981000000000 1fdc14e8e375f22a75ecc60ad1866209 /home/username/Zig/lib/std/Thread/StaticResetEvent.zig +43314 1081064 1622401981000000000 fa699e8243a100850c5d5ef6739f9f0e /home/username/Zig/lib/std/elf.zig +51539 1081020 1622401981000000000 6912bc84bcc9b0d4c8dd68ffab1347fd /home/username/Zig/lib/std/os/linux.zig +58894 1080954 1622401981000000000 693949a4b33972d972d761d11c735c16 /home/username/Zig/lib/std/os/linux/io_uring.zig +3110 1080969 1622401981000000000 64788af658af91aafa790c4fd9d2f68c /home/username/Zig/lib/std/os/linux/x86_64.zig +14677 1080870 1622401981000000000 53c4bacaf2f06eacd48d428a2cbee72b /home/username/Zig/lib/std/dynamic_library.zig +13621 1080966 1622401981000000000 6768b7411b814161e8130498164dc03e /home/username/Zig/lib/std/os/linux/tls.zig +91467 1081024 1622401981000000000 9b053d1b135054334a57f9f37742f26d /home/username/Zig/lib/std/fmt.zig +41711 1081154 1622401981000000000 9c0bfafff5f40ab6809a9bcf07c3f824 /home/username/Zig/lib/std/hash_map.zig +36045 1081061 1622401981000000000 bf40545c6085dd9a95de9c3549569c30 /home/username/Zig/lib/std/dwarf.zig +23094 1080834 1622401981000000000 881b06f481df15d27be7b371a34f40bd /home/username/Zig/lib/std/dwarf_bits.zig +1393 1081265 1622401981000000000 ecc3a07871d2612484a07b8c2229ca48 /home/username/Zig/lib/std/io/seekable_stream.zig +15171 1081026 1622401981000000000 4a3fd55af64b0c2a9867644f4800cdaa /home/username/Zig/lib/std/leb128.zig +48533 1081056 1622401981000000000 7be360cbd3f5fd156ac043f8c36629e6 /home/username/Zig/lib/std/fs/path.zig +19148 1080810 1622401981000000000 5bd88f6706c5aaac347999ed9d72a5ab /home/username/Zig/lib/std/meta/trait.zig +30378 1081172 1622401981000000000 903fea5054a61a51eb818b59fca3831c /home/username/Zig/lib/std/unicode.zig +1590 1081117 1622401981000000000 0470f80d54ee5336adc3025569e3cdb7 /home/username/Zig/lib/std/hash.zig +10488 1081133 1622401981000000000 6b6234564c92515584e44ecd5dbac933 /home/username/Zig/lib/std/hash/wyhash.zig +4819 1081125 1622401981000000000 d4a704c39f8aa1e9295ed986271ba38a /home/username/Zig/lib/std/heap/arena_allocator.zig +13726 1081060 1622401981000000000 a3dea3a6bff91acfde117f119fa1e87f /home/username/Zig/lib/std/linked_list.zig +31051 1081123 1622401981000000000 a0782dc50610af33cad5afc3abd630a6 /home/username/Zig/lib/std/process.zig +9567 1080898 1622401981000000000 3ddcb10ecc92045bf775fa1dc83f4b43 /home/username/Zig/lib/std/Thread/ResetEvent.zig +1229 1080707 1622401981000000000 71465cfdef84e6cacd7bd5313fa61382 /home/username/Zig/lib/std/event.zig +65139 1081145 1622401981000000000 52ce51e5a0a76235f1b09712e220e861 /home/username/Zig/lib/std/event/loop.zig +647 1081116 1622401981000000000 fb95ab826a4142627b810d4d1c9272a8 /home/username/Zig/lib/std/atomic.zig +12428 1081112 1622401981000000000 852f2786036bc86d716a3e0dd8f95b19 /home/username/Zig/lib/std/atomic/queue.zig +11169 1081115 1622401981000000000 3f1bc5a75fa18752b21011adf71fa35e /home/username/Zig/lib/std/time.zig +7627 1080897 1622401981000000000 d90d890f52a10090385569db9b0a8cab /home/username/Zig/lib/std/Thread/AutoResetEvent.zig +6056 1081111 1622401981000000000 5c7d3bd9a8fa7c1a4f2f56ee043cab0b /home/username/Zig/lib/std/atomic/stack.zig +10409 1081152 1622401981000000000 82d9b7a5ac066966cc76ef90b7ffc386 /home/username/Zig/lib/std/log.zig +14139 1080906 1622401981000000000 57d3057cff5514ee4c4247e643dc44b0 /home/username/Zig/lib/std/Progress.zig +39937 1081127 1622401981000000000 d36f67bbcf5a94287681bd0af7e22bb5 /home/username/Zig/lib/std/heap/general_purpose_allocator.zig +6737 1081215 1622401981000000000 71c99558fef7c3c78f503a55f7e85aba /home/username/Zig/lib/std/math/log2.zig +74644 1080908 1622401981000000000 5a43b9b2b90c39f471532633bbb982a9 /home/username/Zig/lib/std/os/windows.zig +52182 1080977 1622401981000000000 4c9986516439dfc2c85364d7b6180cbb /home/username/Zig/lib/std/os/windows/bits.zig +131685 1080986 1622401981000000000 bc3fa898ee7db34328396faef199063e /home/username/Zig/lib/std/os/windows/win32error.zig +237754 1080989 1622401981000000000 767e8595d34a54317caabb7b29ad507f /home/username/Zig/lib/std/os/windows/ntstatus.zig +4196 1080972 1622401981000000000 e7c9e02ed8010ba45d6d9188cb663baf /home/username/Zig/lib/std/os/linux/vdso.zig +55667 1080702 1622401981000000000 91feab183766968b9b062a208734c37d /home/username/Zig/lib/std/macho.zig +21315 1081065 1622401981000000000 d477ff615228bc7577f8332fc1314e65 /home/username/Zig/lib/std/pdb.zig +11334 1080871 1622401981000000000 9a28b5cba8b4531decae0ad1c44bc2e4 /home/username/Zig/lib/std/coff.zig diff --git a/src/qtshit/zig-cache/o/65c41412800e9f66d3b98f5d4b80fba3/builtin.zig b/src/qtshit/zig-cache/o/65c41412800e9f66d3b98f5d4b80fba3/builtin.zig new file mode 100644 index 0000000..0795366 --- /dev/null +++ b/src/qtshit/zig-cache/o/65c41412800e9f66d3b98f5d4b80fba3/builtin.zig @@ -0,0 +1,104 @@ +const std = @import("std"); +/// Zig version. When writing code that supports multiple versions of Zig, prefer +/// feature detection (i.e. with `@hasDecl` or `@hasField`) over version checks. +pub const zig_version = std.SemanticVersion.parse("0.8.0-dev.2711+11ae6c42c") catch unreachable; +/// Temporary until self-hosted is feature complete. +pub const zig_is_stage2 = false; +/// Temporary until self-hosted supports the `cpu.arch` value. +pub const stage2_arch: std.Target.Cpu.Arch = .x86_64; + +pub const output_mode = std.builtin.OutputMode.Exe; +pub const link_mode = std.builtin.LinkMode.Static; +pub const is_test = true; +pub const single_threaded = false; +pub const abi = std.Target.Abi.gnu; +pub const cpu: std.Target.Cpu = .{ + .arch = .x86_64, + .model = &std.Target.x86.cpu.broadwell, + .features = std.Target.x86.featureSet(&[_]std.Target.x86.Feature{ + .@"64bit", + .adx, + .aes, + .avx, + .avx2, + .bmi, + .bmi2, + .cmov, + .cx16, + .cx8, + .ermsb, + .f16c, + .false_deps_lzcnt_tzcnt, + .false_deps_popcnt, + .fast_15bytenop, + .fast_scalar_fsqrt, + .fast_shld_rotate, + .fast_variable_shuffle, + .fma, + .fsgsbase, + .fxsr, + .idivq_to_divl, + .invpcid, + .lzcnt, + .macrofusion, + .mmx, + .movbe, + .nopl, + .pclmul, + .popcnt, + .prfchw, + .rdrnd, + .rdseed, + .sahf, + .slow_3ops_lea, + .sse, + .sse2, + .sse3, + .sse4_1, + .sse4_2, + .ssse3, + .vzeroupper, + .x87, + .xsave, + .xsaveopt, + }), +}; +pub const os = std.Target.Os{ + .tag = .linux, + .version_range = .{ .linux = .{ + .range = .{ + .min = .{ + .major = 5, + .minor = 10, + .patch = 41, + }, + .max = .{ + .major = 5, + .minor = 10, + .patch = 41, + }, + }, + .glibc = .{ + .major = 2, + .minor = 17, + .patch = 0, + }, + }}, +}; +pub const target = std.Target{ + .cpu = cpu, + .os = os, + .abi = abi, +}; +pub const object_format = std.Target.ObjectFormat.elf; +pub const mode = std.builtin.Mode.Debug; +pub const link_libc = false; +pub const link_libcpp = false; +pub const have_error_return_tracing = true; +pub const valgrind_support = true; +pub const position_independent_code = false; +pub const position_independent_executable = false; +pub const strip_debug_info = false; +pub const code_model = std.builtin.CodeModel.default; +pub var test_functions: []std.builtin.TestFn = undefined; // overwritten later +pub const test_io_mode = .blocking; diff --git a/src/qtshit/zig-cache/o/65c41412800e9f66d3b98f5d4b80fba3/test b/src/qtshit/zig-cache/o/65c41412800e9f66d3b98f5d4b80fba3/test new file mode 100755 index 0000000..de989e1 Binary files /dev/null and b/src/qtshit/zig-cache/o/65c41412800e9f66d3b98f5d4b80fba3/test differ diff --git a/src/qtshit/zig-cache/o/65c41412800e9f66d3b98f5d4b80fba3/test.o b/src/qtshit/zig-cache/o/65c41412800e9f66d3b98f5d4b80fba3/test.o new file mode 100644 index 0000000..6bdc51e Binary files /dev/null and b/src/qtshit/zig-cache/o/65c41412800e9f66d3b98f5d4b80fba3/test.o differ