From 4b54931a106b613d70f931d6dfa355b2bfa8c7fb Mon Sep 17 00:00:00 2001 From: Jacek Pospychala Date: Sat, 15 Jun 2024 15:08:15 +0200 Subject: [PATCH] update to zig 0.13 (#21) hi there, I updated this project to build on zig 0.13, would happily contribute. protocol.py is updated, build scripts updated, examples work, tests pass --------- Co-authored-by: Jacek Pospychala Co-authored-by: Malcolm Still --- .github/workflows/test.yaml | 6 +- .gitignore | 3 +- README.md | 2 +- build.zig | 35 +- build.zig.zon | 12 + examples/simple_consume/build.zig | 30 +- examples/simple_consume/build.zig.zon | 15 + examples/simple_consume/src/main.zig | 8 +- .../simple_consume_two_channels/build.zig | 30 +- .../simple_consume_two_channels/build.zig.zon | 36 ++ .../simple_consume_two_channels/src/main.zig | 16 +- examples/simple_publish/build.zig | 30 +- examples/simple_publish/build.zig.zon | 36 ++ examples/simple_publish_single/build.zig | 30 +- examples/simple_publish_single/build.zig.zon | 36 ++ protocol/generator.py | 14 +- src/amqp.zig | 2 +- src/basic.zig | 6 +- src/channel.zig | 4 +- src/connection.zig | 50 ++- src/connector.zig | 29 +- src/protocol.zig | 346 +++++++++--------- src/table.zig | 10 +- src/wire.zig | 82 ++--- 24 files changed, 507 insertions(+), 361 deletions(-) create mode 100644 build.zig.zon create mode 100644 examples/simple_consume/build.zig.zon create mode 100644 examples/simple_consume_two_channels/build.zig.zon create mode 100644 examples/simple_publish/build.zig.zon create mode 100644 examples/simple_publish_single/build.zig.zon diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 33972b8..d5e806e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v2 - uses: goto-bus-stop/setup-zig@v1 with: - version: 0.7.0 + version: 0.13.0 - run: zig build test lint: runs-on: ubuntu-latest @@ -18,5 +18,5 @@ jobs: - uses: actions/checkout@v2 - uses: goto-bus-stop/setup-zig@v1 with: - version: 0.7.0 - - run: zig fmt --check src/*.zig \ No newline at end of file + version: 0.13.0 + - run: zig fmt --check src/*.zig diff --git a/.gitignore b/.gitignore index e4e5c69..79e797b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ example.o bin/ zig-cache/ +zig-out/ inject.sh @@ -11,4 +12,4 @@ inject.sh TOUR.md *.pdf -src/example.zig \ No newline at end of file +src/example.zig diff --git a/README.md b/README.md index ba20316..2ed56e5 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ require. ### Build -- A zig compiler (tested on at least 0.7.0) +- A zig compiler (tested on at least 0.13.0) ### Regenerating `src/protocol.zig` diff --git a/build.zig b/build.zig index fd598d3..24a2be7 100644 --- a/build.zig +++ b/build.zig @@ -1,14 +1,31 @@ -const Builder = @import("std").build.Builder; +const std = @import("std"); -pub fn build(b: *Builder) void { - const mode = b.standardReleaseOptions(); - const lib = b.addStaticLibrary("zig-amqp", "src/amqp.zig"); - lib.setBuildMode(mode); - lib.install(); +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); - var main_tests = b.addTest("src/amqp.zig"); - main_tests.setBuildMode(mode); + const lib = b.addStaticLibrary(.{ + .name = "zig-amqp", + .root_source_file = .{ .path = "src/amqp.zig" }, + .target = target, + .optimize = optimize, + }); + b.installArtifact(lib); + + _ = b.addModule("amqp", .{ + .root_source_file = .{ .path = "src/amqp.zig" }, + .target = target, + .optimize = optimize, + }); + + const main_tests = b.addTest(.{ + .root_source_file = .{ .path = "src/amqp.zig" }, + .target = target, + .optimize = optimize, + }); + + const run_lib_unit_tests = b.addRunArtifact(main_tests); const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&main_tests.step); + test_step.dependOn(&run_lib_unit_tests.step); } diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..0450b38 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,12 @@ +.{ + .name = "amqp", + .version = "0.0.0", + + .dependencies = .{}, + + .paths = .{ + "build.zig", + "build.zig.zon", + "src", + }, +} diff --git a/examples/simple_consume/build.zig b/examples/simple_consume/build.zig index 11833e7..e1e4dd7 100644 --- a/examples/simple_consume/build.zig +++ b/examples/simple_consume/build.zig @@ -1,23 +1,23 @@ -const Builder = @import("std").build.Builder; +const std = @import("std"); -pub fn build(b: *Builder) void { - // Standard target options allows the person running `zig build` to choose - // what target to build for. Here we do not override the defaults, which - // means any target is allowed, and the default is native. Other options - // for restricting supported target set are available. +pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); - // Standard release options allow the person running `zig build` to select - // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. - const mode = b.standardReleaseOptions(); + const amqpDep = b.dependency("amqp", .{}); + const amqp = amqpDep.module("amqp"); - const exe = b.addExecutable("simple_consume", "src/main.zig"); - exe.setTarget(target); - exe.setBuildMode(mode); - exe.addPackagePath("amqp", "../../src/amqp.zig"); - exe.install(); + const exe = b.addExecutable(.{ + .name = "simple_consume", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + exe.root_module.addImport("amqp", amqp); - const run_cmd = exe.run(); + b.installArtifact(exe); + + const run_cmd = b.addRunArtifact(exe); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); diff --git a/examples/simple_consume/build.zig.zon b/examples/simple_consume/build.zig.zon new file mode 100644 index 0000000..1941adf --- /dev/null +++ b/examples/simple_consume/build.zig.zon @@ -0,0 +1,15 @@ +.{ + .name = "simple_consumer", + .version = "0.0.0", + + .dependencies = .{ + .amqp = .{ + .url = "../../", + .hash = "12201e2af5138be09dec4dfdd163cf8ef3c15c7c39e202661b64d71c6271a9d0886e", + }, + }, + + .paths = .{ + "", + }, +} diff --git a/examples/simple_consume/src/main.zig b/examples/simple_consume/src/main.zig index 551ccd0..c265183 100644 --- a/examples/simple_consume/src/main.zig +++ b/examples/simple_consume/src/main.zig @@ -14,9 +14,9 @@ pub fn main() !void { var consumer = try ch.basicConsume("simple_publish", .{ .no_ack = true }, null); var i: usize = 0; while (true) : (i += 1) { - var message = try consumer.next(); - var header = message.header; - var body = message.body; - std.debug.warn("{}\n", .{body}); + const message = try consumer.next(); + _ = message.header; + const body = message.body; + std.debug.print("{s}\n", .{body}); } } diff --git a/examples/simple_consume_two_channels/build.zig b/examples/simple_consume_two_channels/build.zig index efbaa55..e1e4dd7 100644 --- a/examples/simple_consume_two_channels/build.zig +++ b/examples/simple_consume_two_channels/build.zig @@ -1,23 +1,23 @@ -const Builder = @import("std").build.Builder; +const std = @import("std"); -pub fn build(b: *Builder) void { - // Standard target options allows the person running `zig build` to choose - // what target to build for. Here we do not override the defaults, which - // means any target is allowed, and the default is native. Other options - // for restricting supported target set are available. +pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); - // Standard release options allow the person running `zig build` to select - // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. - const mode = b.standardReleaseOptions(); + const amqpDep = b.dependency("amqp", .{}); + const amqp = amqpDep.module("amqp"); - const exe = b.addExecutable("simple_consume_two_channels", "src/main.zig"); - exe.setTarget(target); - exe.setBuildMode(mode); - exe.addPackagePath("amqp", "../../src/amqp.zig"); - exe.install(); + const exe = b.addExecutable(.{ + .name = "simple_consume", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + exe.root_module.addImport("amqp", amqp); - const run_cmd = exe.run(); + b.installArtifact(exe); + + const run_cmd = b.addRunArtifact(exe); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); diff --git a/examples/simple_consume_two_channels/build.zig.zon b/examples/simple_consume_two_channels/build.zig.zon new file mode 100644 index 0000000..89c6f78 --- /dev/null +++ b/examples/simple_consume_two_channels/build.zig.zon @@ -0,0 +1,36 @@ +.{ + .name = "simple_consume_two_channels", + // This is a [Semantic Version](https://semver.org/). + // In a future version of Zig it will be used for package deduplication. + .version = "0.0.0", + + // This field is optional. + // This is currently advisory only; Zig does not yet do anything + // with this value. + //.minimum_zig_version = "0.11.0", + + // This field is optional. + // Each dependency must either provide a `url` and `hash`, or a `path`. + // `zig build --fetch` can be used to fetch all dependencies of a package, recursively. + // Once all dependencies are fetched, `zig build` no longer requires + // internet connectivity. + .dependencies = .{ + .amqp = .{ + .url = "../../", + .hash = "12201e2af5138be09dec4dfdd163cf8ef3c15c7c39e202661b64d71c6271a9d0886e", + }, + }, + .paths = .{ + // This makes *all* files, recursively, included in this package. It is generally + // better to explicitly list the files and directories instead, to insure that + // fetching from tarballs, file system paths, and version control all result + // in the same contents hash. + "", + // For example... + //"build.zig", + //"build.zig.zon", + //"src", + //"LICENSE", + //"README.md", + }, +} diff --git a/examples/simple_consume_two_channels/src/main.zig b/examples/simple_consume_two_channels/src/main.zig index df415bd..1dc7727 100644 --- a/examples/simple_consume_two_channels/src/main.zig +++ b/examples/simple_consume_two_channels/src/main.zig @@ -16,14 +16,14 @@ pub fn main() !void { var consumer2 = try ch2.basicConsume("simple_publish", .{ .no_ack = true }, null); var i: usize = 0; while (true) : (i += 1) { - var message1 = try consumer1.next(); - var header1 = message1.header; - var body1 = message1.body; - std.debug.warn("@1: {}\n", .{body1}); + const message1 = try consumer1.next(); + _ = message1.header; + const body1 = message1.body; + std.debug.print("@1: {any}\n", .{body1}); - var message2 = try consumer2.next(); - var header2 = message2.header; - var body2 = message2.body; - std.debug.warn("@2: {}\n", .{body2}); + const message2 = try consumer2.next(); + _ = message2.header; + const body2 = message2.body; + std.debug.print("@2: {any}\n", .{body2}); } } diff --git a/examples/simple_publish/build.zig b/examples/simple_publish/build.zig index a0eabaa..e1e4dd7 100644 --- a/examples/simple_publish/build.zig +++ b/examples/simple_publish/build.zig @@ -1,23 +1,23 @@ -const Builder = @import("std").build.Builder; +const std = @import("std"); -pub fn build(b: *Builder) void { - // Standard target options allows the person running `zig build` to choose - // what target to build for. Here we do not override the defaults, which - // means any target is allowed, and the default is native. Other options - // for restricting supported target set are available. +pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); - // Standard release options allow the person running `zig build` to select - // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. - const mode = b.standardReleaseOptions(); + const amqpDep = b.dependency("amqp", .{}); + const amqp = amqpDep.module("amqp"); - const exe = b.addExecutable("simple_publish", "src/main.zig"); - exe.setTarget(target); - exe.setBuildMode(mode); - exe.addPackagePath("amqp", "../../src/amqp.zig"); - exe.install(); + const exe = b.addExecutable(.{ + .name = "simple_consume", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + exe.root_module.addImport("amqp", amqp); - const run_cmd = exe.run(); + b.installArtifact(exe); + + const run_cmd = b.addRunArtifact(exe); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); diff --git a/examples/simple_publish/build.zig.zon b/examples/simple_publish/build.zig.zon new file mode 100644 index 0000000..6bb29b1 --- /dev/null +++ b/examples/simple_publish/build.zig.zon @@ -0,0 +1,36 @@ +.{ + .name = "simple_publish", + // This is a [Semantic Version](https://semver.org/). + // In a future version of Zig it will be used for package deduplication. + .version = "0.0.0", + + // This field is optional. + // This is currently advisory only; Zig does not yet do anything + // with this value. + //.minimum_zig_version = "0.11.0", + + // This field is optional. + // Each dependency must either provide a `url` and `hash`, or a `path`. + // `zig build --fetch` can be used to fetch all dependencies of a package, recursively. + // Once all dependencies are fetched, `zig build` no longer requires + // internet connectivity. + .dependencies = .{ + .amqp = .{ + .url = "../../", + .hash = "12201e2af5138be09dec4dfdd163cf8ef3c15c7c39e202661b64d71c6271a9d0886e", + }, + }, + .paths = .{ + // This makes *all* files, recursively, included in this package. It is generally + // better to explicitly list the files and directories instead, to insure that + // fetching from tarballs, file system paths, and version control all result + // in the same contents hash. + "", + // For example... + //"build.zig", + //"build.zig.zon", + //"src", + //"LICENSE", + //"README.md", + }, +} diff --git a/examples/simple_publish_single/build.zig b/examples/simple_publish_single/build.zig index 8b9291d..e1e4dd7 100644 --- a/examples/simple_publish_single/build.zig +++ b/examples/simple_publish_single/build.zig @@ -1,23 +1,23 @@ -const Builder = @import("std").build.Builder; +const std = @import("std"); -pub fn build(b: *Builder) void { - // Standard target options allows the person running `zig build` to choose - // what target to build for. Here we do not override the defaults, which - // means any target is allowed, and the default is native. Other options - // for restricting supported target set are available. +pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); - // Standard release options allow the person running `zig build` to select - // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. - const mode = b.standardReleaseOptions(); + const amqpDep = b.dependency("amqp", .{}); + const amqp = amqpDep.module("amqp"); - const exe = b.addExecutable("simple_publish_single", "src/main.zig"); - exe.setTarget(target); - exe.setBuildMode(mode); - exe.addPackagePath("amqp", "../../src/amqp.zig"); - exe.install(); + const exe = b.addExecutable(.{ + .name = "simple_consume", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + exe.root_module.addImport("amqp", amqp); - const run_cmd = exe.run(); + b.installArtifact(exe); + + const run_cmd = b.addRunArtifact(exe); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); diff --git a/examples/simple_publish_single/build.zig.zon b/examples/simple_publish_single/build.zig.zon new file mode 100644 index 0000000..33c43ab --- /dev/null +++ b/examples/simple_publish_single/build.zig.zon @@ -0,0 +1,36 @@ +.{ + .name = "simple_publish_single", + // This is a [Semantic Version](https://semver.org/). + // In a future version of Zig it will be used for package deduplication. + .version = "0.0.0", + + // This field is optional. + // This is currently advisory only; Zig does not yet do anything + // with this value. + //.minimum_zig_version = "0.11.0", + + // This field is optional. + // Each dependency must either provide a `url` and `hash`, or a `path`. + // `zig build --fetch` can be used to fetch all dependencies of a package, recursively. + // Once all dependencies are fetched, `zig build` no longer requires + // internet connectivity. + .dependencies = .{ + .amqp = .{ + .url = "../../", + .hash = "12201e2af5138be09dec4dfdd163cf8ef3c15c7c39e202661b64d71c6271a9d0886e", + }, + }, + .paths = .{ + // This makes *all* files, recursively, included in this package. It is generally + // better to explicitly list the files and directories instead, to insure that + // fetching from tarballs, file system paths, and version control all result + // in the same contents hash. + "", + // For example... + //"build.zig", + //"build.zig.zon", + //"src", + //"LICENSE", + //"README.md", + }, +} diff --git a/protocol/generator.py b/protocol/generator.py index d8dce3a..50860ea 100644 --- a/protocol/generator.py +++ b/protocol/generator.py @@ -70,7 +70,7 @@ def eprint(*args, **kwargs): 'bit': "const", 'longlong': "const", 'short': "const", - 'table': "var", + 'table': "const", 'long': "const", 'octet': "const", 'timestamp': 'const', @@ -185,8 +185,6 @@ def buildField(field): def generate(file): print(f'const std = @import("std");') - print(f'const fs = std.fs;') - print(f'const os = std.os;') print(f'const Connector = @import("connector.zig").Connector;') print(f'const WireBuffer = @import("wire.zig").WireBuffer;') print(f'const Table = @import("table.zig").Table;') @@ -284,9 +282,9 @@ def generateSynchronousMethodFunction(parsed, class_name, method): # Send message print(f"conn.tx_buffer.updateFrameLength();") print(f"// TODO: do we need to retry write (if n isn't as high as we expect)?") - print(f"const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent());") + print(f"_ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent());") print(f"conn.tx_buffer.reset();") - print(f"std.log.debug(\"{klass_cap}@{{}}.{nameCleanCap(method_name)} ->\", .{{conn.channel}});") + print(f"std.log.debug(\"{klass_cap}@{{any}}.{nameCleanCap(method_name)} ->\", .{{conn.channel}});") print(f"return await{nameCleanCamel(method['response'])}(conn);") print(f"}}") @@ -308,7 +306,7 @@ def generateReadStruct(parsed, class_name, method): print(f"{CONSTNESS[Type]} {nameClean(field_name)} = conn.rx_buffer.{READS[Type]}(); ") print(f"try conn.rx_buffer.readEOF();") - print(f"std.log.debug(\"\\t<- {class_name_cap}@{{}}.{method_name_cap}\", .{{conn.channel}});") + print(f"std.log.debug(\"\\t<- {class_name_cap}@{{any}}.{method_name_cap}\", .{{conn.channel}});") print(f"return {nameCleanCamel(method['name'])} {{") for field_name, field in method['fields'].items(): @@ -362,9 +360,9 @@ def generateAsynchronousMethodFunction(parsed, class_name, method): # Send message print(f"conn.tx_buffer.updateFrameLength();") print(f"// TODO: do we need to retry write (if n isn't as high as we expect)?") - print(f"const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent());") + print(f"_ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent());") print(f"conn.tx_buffer.reset();") - print(f"std.log.debug(\"{klass_cap}@{{}}.{nameCleanCap(method_name)} ->\", .{{conn.channel}});") + print(f"std.log.debug(\"{klass_cap}@{{any}}.{nameCleanCap(method_name)} ->\", .{{conn.channel}});") print(f"}}") def nameClean(name): diff --git a/src/amqp.zig b/src/amqp.zig index c947fb9..7d0b151 100644 --- a/src/amqp.zig +++ b/src/amqp.zig @@ -6,7 +6,7 @@ pub const init = @import("connection.zig").Connection.init; const testing = @import("std").testing; -test "" { +test { _ = @import("basic.zig"); _ = @import("channel.zig"); _ = @import("connection.zig"); diff --git a/src/basic.zig b/src/basic.zig index 9f83479..296a3ef 100644 --- a/src/basic.zig +++ b/src/basic.zig @@ -17,9 +17,9 @@ pub const Basic = struct { const Self = @This(); pub fn next(self: *Self) !Message { - var deliver = proto.Basic.awaitDeliver(&self.connector); - var header = try self.connector.awaitHeader(); - var body = try self.connector.awaitBody(); + _ = try proto.Basic.awaitDeliver(&self.connector); + const header = try self.connector.awaitHeader(); + const body = try self.connector.awaitBody(); // TODO: a body may come in more than one part return Message{ diff --git a/src/channel.zig b/src/channel.zig index 5cbec66..292e883 100644 --- a/src/channel.zig +++ b/src/channel.zig @@ -24,7 +24,7 @@ pub const Channel = struct { } pub fn queueDeclare(self: *Self, name: []const u8, options: Queue.Options, args: ?*Table) !Queue { - var declare = try proto.Queue.declareSync( + _ = try proto.Queue.declareSync( &self.connector, name, options.passive, @@ -52,7 +52,7 @@ pub const Channel = struct { } pub fn basicConsume(self: *Self, name: []const u8, options: Basic.Consume.Options, args: ?*Table) !Basic.Consumer { - var consume = try proto.Basic.consumeSync( + _ = try proto.Basic.consumeSync( &self.connector, name, "", diff --git a/src/connection.zig b/src/connection.zig index ffe033f..9ea6b4f 100644 --- a/src/connection.zig +++ b/src/connection.zig @@ -1,11 +1,9 @@ const std = @import("std"); const net = std.net; const mem = std.mem; -const fs = std.fs; -const os = std.os; +const posix = std.posix; const builtin = std.builtin; const proto = @import("protocol.zig"); -const callbacks = @import("init.zig"); const WireBuffer = @import("wire.zig").WireBuffer; const Connector = @import("connector.zig").Connector; const Channel = @import("channel.zig").Channel; @@ -32,14 +30,14 @@ pub const Connection = struct { pub fn connect(self: *Self, address: net.Address) !void { const file = try net.tcpConnectToAddress(address); - const n = try file.write("AMQP\x00\x00\x09\x01"); + _ = try file.write("AMQP\x00\x00\x09\x01"); self.connector.file = file; self.connector.connection = self; var start = try proto.Connection.awaitStart(&self.connector); const remote_host = start.server_properties.lookup([]u8, "cluster_name"); - std.log.debug("Connected to {} AMQP server (version {}.{})\nmechanisms: {}\nlocale: {}\n", .{ + std.log.debug("Connected to {any} AMQP server (version {any}.{any})\nmechanisms: {any}\nlocale: {any}\n", .{ remote_host, start.version_major, start.version_minor, @@ -80,11 +78,11 @@ pub const Connection = struct { // avoid allocations. try proto.Connection.startOkAsync(&self.connector, &client_properties, "PLAIN", "\x00guest\x00guest", "en_US"); - var tune = try proto.Connection.awaitTune(&self.connector); + const tune = try proto.Connection.awaitTune(&self.connector); self.max_channels = tune.channel_max; try proto.Connection.tuneOkAsync(&self.connector, @bitSizeOf(u2048) - 1, tune.frame_max, tune.heartbeat); - var open_repsonse = try proto.Connection.openSync(&self.connector, "/"); + _ = try proto.Connection.openSync(&self.connector, "/"); } pub fn deinit(self: *Self) void { @@ -104,7 +102,7 @@ pub const Connection = struct { var i: u16 = 1; while (i < self.max_channels and i < @bitSizeOf(u2048)) : (i += 1) { const bit: u2048 = 1; - const shift: u11 = @intCast(u11, i); + const shift: u11 = @intCast(i); if (self.in_use_channels & (bit << shift) == 0) { self.in_use_channels |= (bit << shift); return i; @@ -117,8 +115,8 @@ pub const Connection = struct { pub fn freeChannel(self: *Self, channel_id: u16) void { if (channel_id >= @bitSizeOf(u2048)) return; // Look it's late okay... const bit: u2048 = 1; - self.in_use_channels &= ~(bit << @intCast(u11, channel_id)); - if (std.builtin.mode == .Debug) std.debug.warn("Freed channel {}, in_use_channels: {}\n", .{ channel_id, @popCount(u2048, self.in_use_channels) }); + self.in_use_channels &= ~(bit << @intCast(channel_id)); + if (std.builtin.mode == .Debug) std.debug.print("Freed channel {any}, in_use_channels: {any}\n", .{ channel_id, @popCount(self.in_use_channels) }); } }; @@ -130,18 +128,18 @@ test "read / write / shift volatility" { var client_rx_memory: [128]u8 = [_]u8{0} ** 128; var client_tx_memory: [128]u8 = [_]u8{0} ** 128; - var server_rx_buf = WireBuffer.init(server_rx_memory[0..]); - var server_tx_buf = WireBuffer.init(server_tx_memory[0..]); + const server_rx_buf = WireBuffer.init(server_rx_memory[0..]); + const server_tx_buf = WireBuffer.init(server_tx_memory[0..]); - var client_rx_buf = WireBuffer.init(client_rx_memory[0..]); - var client_tx_buf = WireBuffer.init(client_tx_memory[0..]); + _ = WireBuffer.init(client_rx_memory[0..]); + _ = WireBuffer.init(client_tx_memory[0..]); - const f = try os.pipe(); - defer os.close(f[0]); - defer os.close(f[1]); + const f = try posix.pipe(); + defer posix.close(f[0]); + defer posix.close(f[1]); var server_connector = Connector{ - .file = fs.File{ + .file = net.Stream{ .handle = f[0], }, .rx_buffer = server_rx_buf, @@ -150,7 +148,7 @@ test "read / write / shift volatility" { }; var client_connector = Connector{ - .file = fs.File{ + .file = net.Stream{ .handle = f[1], }, .rx_buffer = server_rx_buf, @@ -163,19 +161,19 @@ test "read / write / shift volatility" { // volatile values should be valid until at least the next call that // modifies the underlying buffers - var block = try server_connector.awaitMethod(proto.Connection.Blocked); - testing.expect(mem.eql(u8, block.reason, "hello")); - var block2 = try proto.Connection.awaitBlocked(&server_connector); // alternative form of await - testing.expect(mem.eql(u8, block2.reason, "world")); + const block = try server_connector.awaitMethod(proto.Connection.Blocked); + try testing.expect(mem.eql(u8, block.reason, "hello")); + const block2 = try proto.Connection.awaitBlocked(&server_connector); // alternative form of await + try testing.expect(mem.eql(u8, block2.reason, "world")); // Due to volatility, block.reason may not remain "hello" // 1. Having called awaitBlocked a second time, we're actually still good // as before messages are still in their original location in the buffer: - testing.expect(mem.eql(u8, block.reason, "hello")); + try testing.expect(mem.eql(u8, block.reason, "hello")); // 2. If another message is written and we copy it to the front of the buffer (shift) // and then await again, we find that block.reason is now "overw" instead of "hello" try proto.Connection.blockedAsync(&client_connector, "overwritten"); server_connector.rx_buffer.shift(); - var block3 = try server_connector.awaitMethod(proto.Connection.Blocked); - testing.expect(mem.eql(u8, block.reason, "overw")); + _ = try server_connector.awaitMethod(proto.Connection.Blocked); + try testing.expect(mem.eql(u8, block.reason, "overw")); } diff --git a/src/connector.zig b/src/connector.zig index 13f9253..02c210d 100644 --- a/src/connector.zig +++ b/src/connector.zig @@ -1,6 +1,5 @@ const std = @import("std"); -const os = std.os; -const fs = std.fs; +const posix = std.posix; const proto = @import("protocol.zig"); const wire = @import("wire.zig"); const Header = @import("wire.zig").Header; @@ -9,7 +8,7 @@ const Connection = @import("connection.zig").Connection; // TODO: think up a better name for this pub const Connector = struct { - file: fs.File = undefined, + file: std.net.Stream = undefined, // TODO: we're going to run into trouble real fast if we reallocate the buffers // and we have a bunch of copies of Connector everywhere. I think we just // need to store a pointer to the Connection @@ -22,19 +21,19 @@ pub const Connector = struct { pub fn sendHeader(self: *Self, size: u64, class: u16) !void { self.tx_buffer.writeHeader(self.channel, size, class); - _ = try std.os.write(self.file.handle, self.tx_buffer.extent()); + _ = try posix.write(self.file.handle, self.tx_buffer.extent()); self.tx_buffer.reset(); } pub fn sendBody(self: *Self, body: []const u8) !void { self.tx_buffer.writeBody(self.channel, body); - _ = try std.os.write(self.file.handle, self.tx_buffer.extent()); + _ = try posix.write(self.file.handle, self.tx_buffer.extent()); self.tx_buffer.reset(); } pub fn sendHeartbeat(self: *Self) !void { self.tx_buffer.writeHeartbeat(); - _ = try std.os.write(self.file.handle, self.tx_buffer.extent()); + _ = try posix.write(self.file.handle, self.tx_buffer.extent()); self.tx_buffer.reset(); std.log.debug("Heartbeat ->", .{}); } @@ -43,14 +42,14 @@ pub const Connector = struct { while (true) { if (!conn.rx_buffer.frameReady()) { // TODO: do we need to retry read (if n isn't as high as we expect)? - const n = try os.read(conn.file.handle, conn.rx_buffer.remaining()); + const n = try posix.read(conn.file.handle, conn.rx_buffer.remaining()); conn.rx_buffer.incrementEnd(n); if (conn.rx_buffer.isFull()) conn.rx_buffer.shift(); continue; } while (conn.rx_buffer.frameReady()) { const frame_header = try conn.rx_buffer.readFrameHeader(); - switch (frame_header.@"type") { + switch (frame_header.type) { .Method => { const method_header = try conn.rx_buffer.readMethodHeader(); if (method_header.class == 10 and method_header.method == 50) { @@ -61,7 +60,7 @@ pub const Connector = struct { try proto.Channel.closeOkAsync(conn); return error.ChannelClose; } - std.log.debug("awaitHeader: unexpected method {}.{}\n", .{ method_header.class, method_header.method }); + std.log.debug("awaitHeader: unexpected method {any}.{any}\n", .{ method_header.class, method_header.method }); return error.ImplementAsyncHandle; }, .Heartbeat => { @@ -85,14 +84,14 @@ pub const Connector = struct { while (true) { if (!conn.rx_buffer.frameReady()) { // TODO: do we need to retry read (if n isn't as high as we expect)? - const n = try os.read(conn.file.handle, conn.rx_buffer.remaining()); + const n = try posix.read(conn.file.handle, conn.rx_buffer.remaining()); conn.rx_buffer.incrementEnd(n); if (conn.rx_buffer.isFull()) conn.rx_buffer.shift(); continue; } while (conn.rx_buffer.frameReady()) { const frame_header = try conn.rx_buffer.readFrameHeader(); - switch (frame_header.@"type") { + switch (frame_header.type) { .Method => { const method_header = try conn.rx_buffer.readMethodHeader(); if (method_header.class == 10 and method_header.method == 50) { @@ -103,7 +102,7 @@ pub const Connector = struct { try proto.Channel.closeOkAsync(conn); return error.ChannelClose; } - std.log.debug("awaitBody: unexpected method {}.{}\n", .{ method_header.class, method_header.method }); + std.log.debug("awaitBody: unexpected method {any}.{any}\n", .{ method_header.class, method_header.method }); return error.ImplementAsyncHandle; }, .Heartbeat => { @@ -127,14 +126,14 @@ pub const Connector = struct { while (true) { if (!conn.rx_buffer.frameReady()) { // TODO: do we need to retry read (if n isn't as high as we expect)? - const n = try os.read(conn.file.handle, conn.rx_buffer.remaining()); + const n = try posix.read(conn.file.handle, conn.rx_buffer.remaining()); conn.rx_buffer.incrementEnd(n); if (conn.rx_buffer.isFull()) conn.rx_buffer.shift(); continue; } while (conn.rx_buffer.frameReady()) { const frame_header = try conn.rx_buffer.readFrameHeader(); - switch (frame_header.@"type") { + switch (frame_header.type) { .Method => { const method_header = try conn.rx_buffer.readMethodHeader(); if (T.CLASS == method_header.class and T.METHOD == method_header.method) { @@ -150,7 +149,7 @@ pub const Connector = struct { try proto.Channel.closeOkAsync(conn); return error.ChannelClose; } - std.log.debug("awaitBody: unexpected method {}.{}\n", .{ method_header.class, method_header.method }); + std.log.debug("awaitBody: unexpected method {any}.{any}\n", .{ method_header.class, method_header.method }); return error.ImplementAsyncHandle; } }, diff --git a/src/protocol.zig b/src/protocol.zig index 1d0c14d..b40c062 100644 --- a/src/protocol.zig +++ b/src/protocol.zig @@ -1,6 +1,4 @@ const std = @import("std"); -const fs = std.fs; -const os = std.os; const Connector = @import("connector.zig").Connector; const WireBuffer = @import("wire.zig").WireBuffer; const Table = @import("table.zig").Table; @@ -49,11 +47,11 @@ pub const Connection = struct { pub fn read(conn: *Connector) !Start { const version_major = conn.rx_buffer.readU8(); const version_minor = conn.rx_buffer.readU8(); - var server_properties = conn.rx_buffer.readTable(); + const server_properties = conn.rx_buffer.readTable(); const mechanisms = conn.rx_buffer.readLongString(); const locales = conn.rx_buffer.readLongString(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Connection@{}.Start", .{conn.channel}); + std.log.debug("\t<- Connection@{any}.Start", .{conn.channel}); return Start{ .version_major = version_major, .version_minor = version_minor, @@ -81,9 +79,9 @@ pub const Connection = struct { conn.tx_buffer.writeLongString(locales); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Connection@{}.Start ->", .{conn.channel}); + std.log.debug("Connection@{any}.Start ->", .{conn.channel}); return awaitStartOk(conn); } @@ -104,12 +102,12 @@ pub const Connection = struct { locale: []const u8, pub fn read(conn: *Connector) !StartOk { - var client_properties = conn.rx_buffer.readTable(); + const client_properties = conn.rx_buffer.readTable(); const mechanism = conn.rx_buffer.readShortString(); const response = conn.rx_buffer.readLongString(); const locale = conn.rx_buffer.readShortString(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Connection@{}.Start_ok", .{conn.channel}); + std.log.debug("\t<- Connection@{any}.Start_ok", .{conn.channel}); return StartOk{ .client_properties = client_properties, .mechanism = mechanism, @@ -134,9 +132,9 @@ pub const Connection = struct { conn.tx_buffer.writeShortString(locale); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Connection@{}.Start_ok ->", .{conn.channel}); + std.log.debug("Connection@{any}.Start_ok ->", .{conn.channel}); } // start_ok @@ -155,7 +153,7 @@ pub const Connection = struct { pub fn read(conn: *Connector) !Secure { const challenge = conn.rx_buffer.readLongString(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Connection@{}.Secure", .{conn.channel}); + std.log.debug("\t<- Connection@{any}.Secure", .{conn.channel}); return Secure{ .challenge = challenge, }; @@ -171,9 +169,9 @@ pub const Connection = struct { conn.tx_buffer.writeLongString(challenge); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Connection@{}.Secure ->", .{conn.channel}); + std.log.debug("Connection@{any}.Secure ->", .{conn.channel}); return awaitSecureOk(conn); } @@ -193,7 +191,7 @@ pub const Connection = struct { pub fn read(conn: *Connector) !SecureOk { const response = conn.rx_buffer.readLongString(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Connection@{}.Secure_ok", .{conn.channel}); + std.log.debug("\t<- Connection@{any}.Secure_ok", .{conn.channel}); return SecureOk{ .response = response, }; @@ -209,9 +207,9 @@ pub const Connection = struct { conn.tx_buffer.writeLongString(response); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Connection@{}.Secure_ok ->", .{conn.channel}); + std.log.debug("Connection@{any}.Secure_ok ->", .{conn.channel}); } // secure_ok @@ -234,7 +232,7 @@ pub const Connection = struct { const frame_max = conn.rx_buffer.readU32(); const heartbeat = conn.rx_buffer.readU16(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Connection@{}.Tune", .{conn.channel}); + std.log.debug("\t<- Connection@{any}.Tune", .{conn.channel}); return Tune{ .channel_max = channel_max, .frame_max = frame_max, @@ -256,9 +254,9 @@ pub const Connection = struct { conn.tx_buffer.writeU16(heartbeat); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Connection@{}.Tune ->", .{conn.channel}); + std.log.debug("Connection@{any}.Tune ->", .{conn.channel}); return awaitTuneOk(conn); } @@ -282,7 +280,7 @@ pub const Connection = struct { const frame_max = conn.rx_buffer.readU32(); const heartbeat = conn.rx_buffer.readU16(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Connection@{}.Tune_ok", .{conn.channel}); + std.log.debug("\t<- Connection@{any}.Tune_ok", .{conn.channel}); return TuneOk{ .channel_max = channel_max, .frame_max = frame_max, @@ -304,9 +302,9 @@ pub const Connection = struct { conn.tx_buffer.writeU16(heartbeat); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Connection@{}.Tune_ok ->", .{conn.channel}); + std.log.debug("Connection@{any}.Tune_ok ->", .{conn.channel}); } // tune_ok @@ -330,7 +328,7 @@ pub const Connection = struct { const bitset0 = conn.rx_buffer.readU8(); const reserved_2 = if (bitset0 & (1 << 0) == 0) true else false; try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Connection@{}.Open", .{conn.channel}); + std.log.debug("\t<- Connection@{any}.Open", .{conn.channel}); return Open{ .virtual_host = virtual_host, .reserved_1 = reserved_1, @@ -355,9 +353,9 @@ pub const Connection = struct { conn.tx_buffer.writeU8(bitset0); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Connection@{}.Open ->", .{conn.channel}); + std.log.debug("Connection@{any}.Open ->", .{conn.channel}); return awaitOpenOk(conn); } @@ -377,7 +375,7 @@ pub const Connection = struct { pub fn read(conn: *Connector) !OpenOk { const reserved_1 = conn.rx_buffer.readShortString(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Connection@{}.Open_ok", .{conn.channel}); + std.log.debug("\t<- Connection@{any}.Open_ok", .{conn.channel}); return OpenOk{ .reserved_1 = reserved_1, }; @@ -393,9 +391,9 @@ pub const Connection = struct { conn.tx_buffer.writeShortString(reserved_1); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Connection@{}.Open_ok ->", .{conn.channel}); + std.log.debug("Connection@{any}.Open_ok ->", .{conn.channel}); } // open_ok @@ -420,7 +418,7 @@ pub const Connection = struct { const class_id = conn.rx_buffer.readU16(); const method_id = conn.rx_buffer.readU16(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Connection@{}.Close", .{conn.channel}); + std.log.debug("\t<- Connection@{any}.Close", .{conn.channel}); return Close{ .reply_code = reply_code, .reply_text = reply_text, @@ -445,9 +443,9 @@ pub const Connection = struct { conn.tx_buffer.writeU16(method_id); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Connection@{}.Close ->", .{conn.channel}); + std.log.debug("Connection@{any}.Close ->", .{conn.channel}); return awaitCloseOk(conn); } @@ -464,7 +462,7 @@ pub const Connection = struct { pub fn read(conn: *Connector) !CloseOk { try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Connection@{}.Close_ok", .{conn.channel}); + std.log.debug("\t<- Connection@{any}.Close_ok", .{conn.channel}); return CloseOk{}; } }; @@ -476,9 +474,9 @@ pub const Connection = struct { conn.tx_buffer.writeMethodHeader(CONNECTION_CLASS, Connection.CLOSE_OK_METHOD); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Connection@{}.Close_ok ->", .{conn.channel}); + std.log.debug("Connection@{any}.Close_ok ->", .{conn.channel}); } // close_ok @@ -497,7 +495,7 @@ pub const Connection = struct { pub fn read(conn: *Connector) !Blocked { const reason = conn.rx_buffer.readShortString(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Connection@{}.Blocked", .{conn.channel}); + std.log.debug("\t<- Connection@{any}.Blocked", .{conn.channel}); return Blocked{ .reason = reason, }; @@ -513,9 +511,9 @@ pub const Connection = struct { conn.tx_buffer.writeShortString(reason); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Connection@{}.Blocked ->", .{conn.channel}); + std.log.debug("Connection@{any}.Blocked ->", .{conn.channel}); } // blocked @@ -531,7 +529,7 @@ pub const Connection = struct { pub fn read(conn: *Connector) !Unblocked { try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Connection@{}.Unblocked", .{conn.channel}); + std.log.debug("\t<- Connection@{any}.Unblocked", .{conn.channel}); return Unblocked{}; } }; @@ -543,9 +541,9 @@ pub const Connection = struct { conn.tx_buffer.writeMethodHeader(CONNECTION_CLASS, Connection.UNBLOCKED_METHOD); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Connection@{}.Unblocked ->", .{conn.channel}); + std.log.debug("Connection@{any}.Unblocked ->", .{conn.channel}); } // unblocked @@ -569,7 +567,7 @@ pub const Channel = struct { pub fn read(conn: *Connector) !Open { const reserved_1 = conn.rx_buffer.readShortString(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Channel@{}.Open", .{conn.channel}); + std.log.debug("\t<- Channel@{any}.Open", .{conn.channel}); return Open{ .reserved_1 = reserved_1, }; @@ -585,9 +583,9 @@ pub const Channel = struct { conn.tx_buffer.writeShortString(reserved_1); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Channel@{}.Open ->", .{conn.channel}); + std.log.debug("Channel@{any}.Open ->", .{conn.channel}); return awaitOpenOk(conn); } @@ -607,7 +605,7 @@ pub const Channel = struct { pub fn read(conn: *Connector) !OpenOk { const reserved_1 = conn.rx_buffer.readLongString(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Channel@{}.Open_ok", .{conn.channel}); + std.log.debug("\t<- Channel@{any}.Open_ok", .{conn.channel}); return OpenOk{ .reserved_1 = reserved_1, }; @@ -623,9 +621,9 @@ pub const Channel = struct { conn.tx_buffer.writeLongString(reserved_1); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Channel@{}.Open_ok ->", .{conn.channel}); + std.log.debug("Channel@{any}.Open_ok ->", .{conn.channel}); } // open_ok @@ -645,7 +643,7 @@ pub const Channel = struct { const bitset0 = conn.rx_buffer.readU8(); const active = if (bitset0 & (1 << 0) == 0) true else false; try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Channel@{}.Flow", .{conn.channel}); + std.log.debug("\t<- Channel@{any}.Flow", .{conn.channel}); return Flow{ .active = active, }; @@ -664,9 +662,9 @@ pub const Channel = struct { conn.tx_buffer.writeU8(bitset0); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Channel@{}.Flow ->", .{conn.channel}); + std.log.debug("Channel@{any}.Flow ->", .{conn.channel}); return awaitFlowOk(conn); } @@ -687,7 +685,7 @@ pub const Channel = struct { const bitset0 = conn.rx_buffer.readU8(); const active = if (bitset0 & (1 << 0) == 0) true else false; try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Channel@{}.Flow_ok", .{conn.channel}); + std.log.debug("\t<- Channel@{any}.Flow_ok", .{conn.channel}); return FlowOk{ .active = active, }; @@ -706,9 +704,9 @@ pub const Channel = struct { conn.tx_buffer.writeU8(bitset0); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Channel@{}.Flow_ok ->", .{conn.channel}); + std.log.debug("Channel@{any}.Flow_ok ->", .{conn.channel}); } // flow_ok @@ -733,7 +731,7 @@ pub const Channel = struct { const class_id = conn.rx_buffer.readU16(); const method_id = conn.rx_buffer.readU16(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Channel@{}.Close", .{conn.channel}); + std.log.debug("\t<- Channel@{any}.Close", .{conn.channel}); return Close{ .reply_code = reply_code, .reply_text = reply_text, @@ -758,9 +756,9 @@ pub const Channel = struct { conn.tx_buffer.writeU16(method_id); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Channel@{}.Close ->", .{conn.channel}); + std.log.debug("Channel@{any}.Close ->", .{conn.channel}); return awaitCloseOk(conn); } @@ -777,7 +775,7 @@ pub const Channel = struct { pub fn read(conn: *Connector) !CloseOk { try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Channel@{}.Close_ok", .{conn.channel}); + std.log.debug("\t<- Channel@{any}.Close_ok", .{conn.channel}); return CloseOk{}; } }; @@ -789,9 +787,9 @@ pub const Channel = struct { conn.tx_buffer.writeMethodHeader(CHANNEL_CLASS, Channel.CLOSE_OK_METHOD); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Channel@{}.Close_ok ->", .{conn.channel}); + std.log.debug("Channel@{any}.Close_ok ->", .{conn.channel}); } // close_ok @@ -830,9 +828,9 @@ pub const Exchange = struct { const reserved_2 = if (bitset0 & (1 << 2) == 0) true else false; const reserved_3 = if (bitset0 & (1 << 3) == 0) true else false; const no_wait = if (bitset0 & (1 << 4) == 0) true else false; - var arguments = conn.rx_buffer.readTable(); + const arguments = conn.rx_buffer.readTable(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Exchange@{}.Declare", .{conn.channel}); + std.log.debug("\t<- Exchange@{any}.Declare", .{conn.channel}); return Declare{ .reserved_1 = reserved_1, .exchange = exchange, @@ -875,9 +873,9 @@ pub const Exchange = struct { conn.tx_buffer.writeTable(arguments); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Exchange@{}.Declare ->", .{conn.channel}); + std.log.debug("Exchange@{any}.Declare ->", .{conn.channel}); return awaitDeclareOk(conn); } @@ -894,7 +892,7 @@ pub const Exchange = struct { pub fn read(conn: *Connector) !DeclareOk { try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Exchange@{}.Declare_ok", .{conn.channel}); + std.log.debug("\t<- Exchange@{any}.Declare_ok", .{conn.channel}); return DeclareOk{}; } }; @@ -906,9 +904,9 @@ pub const Exchange = struct { conn.tx_buffer.writeMethodHeader(EXCHANGE_CLASS, Exchange.DECLARE_OK_METHOD); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Exchange@{}.Declare_ok ->", .{conn.channel}); + std.log.debug("Exchange@{any}.Declare_ok ->", .{conn.channel}); } // declare_ok @@ -934,7 +932,7 @@ pub const Exchange = struct { const if_unused = if (bitset0 & (1 << 0) == 0) true else false; const no_wait = if (bitset0 & (1 << 1) == 0) true else false; try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Exchange@{}.Delete", .{conn.channel}); + std.log.debug("\t<- Exchange@{any}.Delete", .{conn.channel}); return Delete{ .reserved_1 = reserved_1, .exchange = exchange, @@ -962,9 +960,9 @@ pub const Exchange = struct { conn.tx_buffer.writeU8(bitset0); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Exchange@{}.Delete ->", .{conn.channel}); + std.log.debug("Exchange@{any}.Delete ->", .{conn.channel}); return awaitDeleteOk(conn); } @@ -981,7 +979,7 @@ pub const Exchange = struct { pub fn read(conn: *Connector) !DeleteOk { try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Exchange@{}.Delete_ok", .{conn.channel}); + std.log.debug("\t<- Exchange@{any}.Delete_ok", .{conn.channel}); return DeleteOk{}; } }; @@ -993,9 +991,9 @@ pub const Exchange = struct { conn.tx_buffer.writeMethodHeader(EXCHANGE_CLASS, Exchange.DELETE_OK_METHOD); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Exchange@{}.Delete_ok ->", .{conn.channel}); + std.log.debug("Exchange@{any}.Delete_ok ->", .{conn.channel}); } // delete_ok @@ -1032,9 +1030,9 @@ pub const Queue = struct { const exclusive = if (bitset0 & (1 << 2) == 0) true else false; const auto_delete = if (bitset0 & (1 << 3) == 0) true else false; const no_wait = if (bitset0 & (1 << 4) == 0) true else false; - var arguments = conn.rx_buffer.readTable(); + const arguments = conn.rx_buffer.readTable(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Queue@{}.Declare", .{conn.channel}); + std.log.debug("\t<- Queue@{any}.Declare", .{conn.channel}); return Declare{ .reserved_1 = reserved_1, .queue = queue, @@ -1074,9 +1072,9 @@ pub const Queue = struct { conn.tx_buffer.writeTable(arguments); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Queue@{}.Declare ->", .{conn.channel}); + std.log.debug("Queue@{any}.Declare ->", .{conn.channel}); return awaitDeclareOk(conn); } @@ -1100,7 +1098,7 @@ pub const Queue = struct { const message_count = conn.rx_buffer.readU32(); const consumer_count = conn.rx_buffer.readU32(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Queue@{}.Declare_ok", .{conn.channel}); + std.log.debug("\t<- Queue@{any}.Declare_ok", .{conn.channel}); return DeclareOk{ .queue = queue, .message_count = message_count, @@ -1122,9 +1120,9 @@ pub const Queue = struct { conn.tx_buffer.writeU32(consumer_count); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Queue@{}.Declare_ok ->", .{conn.channel}); + std.log.debug("Queue@{any}.Declare_ok ->", .{conn.channel}); } // declare_ok @@ -1152,9 +1150,9 @@ pub const Queue = struct { const routing_key = conn.rx_buffer.readShortString(); const bitset0 = conn.rx_buffer.readU8(); const no_wait = if (bitset0 & (1 << 0) == 0) true else false; - var arguments = conn.rx_buffer.readTable(); + const arguments = conn.rx_buffer.readTable(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Queue@{}.Bind", .{conn.channel}); + std.log.debug("\t<- Queue@{any}.Bind", .{conn.channel}); return Bind{ .reserved_1 = reserved_1, .queue = queue, @@ -1188,9 +1186,9 @@ pub const Queue = struct { conn.tx_buffer.writeTable(arguments); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Queue@{}.Bind ->", .{conn.channel}); + std.log.debug("Queue@{any}.Bind ->", .{conn.channel}); return awaitBindOk(conn); } @@ -1207,7 +1205,7 @@ pub const Queue = struct { pub fn read(conn: *Connector) !BindOk { try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Queue@{}.Bind_ok", .{conn.channel}); + std.log.debug("\t<- Queue@{any}.Bind_ok", .{conn.channel}); return BindOk{}; } }; @@ -1219,9 +1217,9 @@ pub const Queue = struct { conn.tx_buffer.writeMethodHeader(QUEUE_CLASS, Queue.BIND_OK_METHOD); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Queue@{}.Bind_ok ->", .{conn.channel}); + std.log.debug("Queue@{any}.Bind_ok ->", .{conn.channel}); } // bind_ok @@ -1246,9 +1244,9 @@ pub const Queue = struct { const queue = conn.rx_buffer.readShortString(); const exchange = conn.rx_buffer.readShortString(); const routing_key = conn.rx_buffer.readShortString(); - var arguments = conn.rx_buffer.readTable(); + const arguments = conn.rx_buffer.readTable(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Queue@{}.Unbind", .{conn.channel}); + std.log.debug("\t<- Queue@{any}.Unbind", .{conn.channel}); return Unbind{ .reserved_1 = reserved_1, .queue = queue, @@ -1276,9 +1274,9 @@ pub const Queue = struct { conn.tx_buffer.writeTable(arguments); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Queue@{}.Unbind ->", .{conn.channel}); + std.log.debug("Queue@{any}.Unbind ->", .{conn.channel}); return awaitUnbindOk(conn); } @@ -1295,7 +1293,7 @@ pub const Queue = struct { pub fn read(conn: *Connector) !UnbindOk { try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Queue@{}.Unbind_ok", .{conn.channel}); + std.log.debug("\t<- Queue@{any}.Unbind_ok", .{conn.channel}); return UnbindOk{}; } }; @@ -1307,9 +1305,9 @@ pub const Queue = struct { conn.tx_buffer.writeMethodHeader(QUEUE_CLASS, Queue.UNBIND_OK_METHOD); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Queue@{}.Unbind_ok ->", .{conn.channel}); + std.log.debug("Queue@{any}.Unbind_ok ->", .{conn.channel}); } // unbind_ok @@ -1333,7 +1331,7 @@ pub const Queue = struct { const bitset0 = conn.rx_buffer.readU8(); const no_wait = if (bitset0 & (1 << 0) == 0) true else false; try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Queue@{}.Purge", .{conn.channel}); + std.log.debug("\t<- Queue@{any}.Purge", .{conn.channel}); return Purge{ .reserved_1 = reserved_1, .queue = queue, @@ -1358,9 +1356,9 @@ pub const Queue = struct { conn.tx_buffer.writeU8(bitset0); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Queue@{}.Purge ->", .{conn.channel}); + std.log.debug("Queue@{any}.Purge ->", .{conn.channel}); return awaitPurgeOk(conn); } @@ -1380,7 +1378,7 @@ pub const Queue = struct { pub fn read(conn: *Connector) !PurgeOk { const message_count = conn.rx_buffer.readU32(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Queue@{}.Purge_ok", .{conn.channel}); + std.log.debug("\t<- Queue@{any}.Purge_ok", .{conn.channel}); return PurgeOk{ .message_count = message_count, }; @@ -1396,9 +1394,9 @@ pub const Queue = struct { conn.tx_buffer.writeU32(message_count); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Queue@{}.Purge_ok ->", .{conn.channel}); + std.log.debug("Queue@{any}.Purge_ok ->", .{conn.channel}); } // purge_ok @@ -1426,7 +1424,7 @@ pub const Queue = struct { const if_empty = if (bitset0 & (1 << 1) == 0) true else false; const no_wait = if (bitset0 & (1 << 2) == 0) true else false; try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Queue@{}.Delete", .{conn.channel}); + std.log.debug("\t<- Queue@{any}.Delete", .{conn.channel}); return Delete{ .reserved_1 = reserved_1, .queue = queue, @@ -1457,9 +1455,9 @@ pub const Queue = struct { conn.tx_buffer.writeU8(bitset0); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Queue@{}.Delete ->", .{conn.channel}); + std.log.debug("Queue@{any}.Delete ->", .{conn.channel}); return awaitDeleteOk(conn); } @@ -1479,7 +1477,7 @@ pub const Queue = struct { pub fn read(conn: *Connector) !DeleteOk { const message_count = conn.rx_buffer.readU32(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Queue@{}.Delete_ok", .{conn.channel}); + std.log.debug("\t<- Queue@{any}.Delete_ok", .{conn.channel}); return DeleteOk{ .message_count = message_count, }; @@ -1495,9 +1493,9 @@ pub const Queue = struct { conn.tx_buffer.writeU32(message_count); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Queue@{}.Delete_ok ->", .{conn.channel}); + std.log.debug("Queue@{any}.Delete_ok ->", .{conn.channel}); } // delete_ok @@ -1526,7 +1524,7 @@ pub const Basic = struct { const bitset0 = conn.rx_buffer.readU8(); const global = if (bitset0 & (1 << 0) == 0) true else false; try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Basic@{}.Qos", .{conn.channel}); + std.log.debug("\t<- Basic@{any}.Qos", .{conn.channel}); return Qos{ .prefetch_size = prefetch_size, .prefetch_count = prefetch_count, @@ -1551,9 +1549,9 @@ pub const Basic = struct { conn.tx_buffer.writeU8(bitset0); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Basic@{}.Qos ->", .{conn.channel}); + std.log.debug("Basic@{any}.Qos ->", .{conn.channel}); return awaitQosOk(conn); } @@ -1570,7 +1568,7 @@ pub const Basic = struct { pub fn read(conn: *Connector) !QosOk { try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Basic@{}.Qos_ok", .{conn.channel}); + std.log.debug("\t<- Basic@{any}.Qos_ok", .{conn.channel}); return QosOk{}; } }; @@ -1582,9 +1580,9 @@ pub const Basic = struct { conn.tx_buffer.writeMethodHeader(BASIC_CLASS, Basic.QOS_OK_METHOD); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Basic@{}.Qos_ok ->", .{conn.channel}); + std.log.debug("Basic@{any}.Qos_ok ->", .{conn.channel}); } // qos_ok @@ -1616,9 +1614,9 @@ pub const Basic = struct { const no_ack = if (bitset0 & (1 << 1) == 0) true else false; const exclusive = if (bitset0 & (1 << 2) == 0) true else false; const no_wait = if (bitset0 & (1 << 3) == 0) true else false; - var arguments = conn.rx_buffer.readTable(); + const arguments = conn.rx_buffer.readTable(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Basic@{}.Consume", .{conn.channel}); + std.log.debug("\t<- Basic@{any}.Consume", .{conn.channel}); return Consume{ .reserved_1 = reserved_1, .queue = queue, @@ -1658,9 +1656,9 @@ pub const Basic = struct { conn.tx_buffer.writeTable(arguments); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Basic@{}.Consume ->", .{conn.channel}); + std.log.debug("Basic@{any}.Consume ->", .{conn.channel}); return awaitConsumeOk(conn); } @@ -1680,7 +1678,7 @@ pub const Basic = struct { pub fn read(conn: *Connector) !ConsumeOk { const consumer_tag = conn.rx_buffer.readShortString(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Basic@{}.Consume_ok", .{conn.channel}); + std.log.debug("\t<- Basic@{any}.Consume_ok", .{conn.channel}); return ConsumeOk{ .consumer_tag = consumer_tag, }; @@ -1696,9 +1694,9 @@ pub const Basic = struct { conn.tx_buffer.writeShortString(consumer_tag); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Basic@{}.Consume_ok ->", .{conn.channel}); + std.log.debug("Basic@{any}.Consume_ok ->", .{conn.channel}); } // consume_ok @@ -1720,7 +1718,7 @@ pub const Basic = struct { const bitset0 = conn.rx_buffer.readU8(); const no_wait = if (bitset0 & (1 << 0) == 0) true else false; try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Basic@{}.Cancel", .{conn.channel}); + std.log.debug("\t<- Basic@{any}.Cancel", .{conn.channel}); return Cancel{ .consumer_tag = consumer_tag, .no_wait = no_wait, @@ -1742,9 +1740,9 @@ pub const Basic = struct { conn.tx_buffer.writeU8(bitset0); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Basic@{}.Cancel ->", .{conn.channel}); + std.log.debug("Basic@{any}.Cancel ->", .{conn.channel}); return awaitCancelOk(conn); } @@ -1764,7 +1762,7 @@ pub const Basic = struct { pub fn read(conn: *Connector) !CancelOk { const consumer_tag = conn.rx_buffer.readShortString(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Basic@{}.Cancel_ok", .{conn.channel}); + std.log.debug("\t<- Basic@{any}.Cancel_ok", .{conn.channel}); return CancelOk{ .consumer_tag = consumer_tag, }; @@ -1780,9 +1778,9 @@ pub const Basic = struct { conn.tx_buffer.writeShortString(consumer_tag); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Basic@{}.Cancel_ok ->", .{conn.channel}); + std.log.debug("Basic@{any}.Cancel_ok ->", .{conn.channel}); } // cancel_ok @@ -1810,7 +1808,7 @@ pub const Basic = struct { const mandatory = if (bitset0 & (1 << 0) == 0) true else false; const immediate = if (bitset0 & (1 << 1) == 0) true else false; try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Basic@{}.Publish", .{conn.channel}); + std.log.debug("\t<- Basic@{any}.Publish", .{conn.channel}); return Publish{ .reserved_1 = reserved_1, .exchange = exchange, @@ -1841,9 +1839,9 @@ pub const Basic = struct { conn.tx_buffer.writeU8(bitset0); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Basic@{}.Publish ->", .{conn.channel}); + std.log.debug("Basic@{any}.Publish ->", .{conn.channel}); } // publish @@ -1868,7 +1866,7 @@ pub const Basic = struct { const exchange = conn.rx_buffer.readShortString(); const routing_key = conn.rx_buffer.readShortString(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Basic@{}.Return", .{conn.channel}); + std.log.debug("\t<- Basic@{any}.Return", .{conn.channel}); return Return{ .reply_code = reply_code, .reply_text = reply_text, @@ -1893,9 +1891,9 @@ pub const Basic = struct { conn.tx_buffer.writeShortString(routing_key); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Basic@{}.Return ->", .{conn.channel}); + std.log.debug("Basic@{any}.Return ->", .{conn.channel}); } // @"return" @@ -1923,7 +1921,7 @@ pub const Basic = struct { const exchange = conn.rx_buffer.readShortString(); const routing_key = conn.rx_buffer.readShortString(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Basic@{}.Deliver", .{conn.channel}); + std.log.debug("\t<- Basic@{any}.Deliver", .{conn.channel}); return Deliver{ .consumer_tag = consumer_tag, .delivery_tag = delivery_tag, @@ -1954,9 +1952,9 @@ pub const Basic = struct { conn.tx_buffer.writeShortString(routing_key); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Basic@{}.Deliver ->", .{conn.channel}); + std.log.debug("Basic@{any}.Deliver ->", .{conn.channel}); } // deliver @@ -1980,7 +1978,7 @@ pub const Basic = struct { const bitset0 = conn.rx_buffer.readU8(); const no_ack = if (bitset0 & (1 << 0) == 0) true else false; try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Basic@{}.Get", .{conn.channel}); + std.log.debug("\t<- Basic@{any}.Get", .{conn.channel}); return Get{ .reserved_1 = reserved_1, .queue = queue, @@ -2005,9 +2003,9 @@ pub const Basic = struct { conn.tx_buffer.writeU8(bitset0); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Basic@{}.Get ->", .{conn.channel}); + std.log.debug("Basic@{any}.Get ->", .{conn.channel}); return awaitGetEmpty(conn); } @@ -2036,7 +2034,7 @@ pub const Basic = struct { const routing_key = conn.rx_buffer.readShortString(); const message_count = conn.rx_buffer.readU32(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Basic@{}.Get_ok", .{conn.channel}); + std.log.debug("\t<- Basic@{any}.Get_ok", .{conn.channel}); return GetOk{ .delivery_tag = delivery_tag, .redelivered = redelivered, @@ -2067,9 +2065,9 @@ pub const Basic = struct { conn.tx_buffer.writeU32(message_count); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Basic@{}.Get_ok ->", .{conn.channel}); + std.log.debug("Basic@{any}.Get_ok ->", .{conn.channel}); } // get_ok @@ -2088,7 +2086,7 @@ pub const Basic = struct { pub fn read(conn: *Connector) !GetEmpty { const reserved_1 = conn.rx_buffer.readShortString(); try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Basic@{}.Get_empty", .{conn.channel}); + std.log.debug("\t<- Basic@{any}.Get_empty", .{conn.channel}); return GetEmpty{ .reserved_1 = reserved_1, }; @@ -2104,9 +2102,9 @@ pub const Basic = struct { conn.tx_buffer.writeShortString(reserved_1); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Basic@{}.Get_empty ->", .{conn.channel}); + std.log.debug("Basic@{any}.Get_empty ->", .{conn.channel}); } // get_empty @@ -2128,7 +2126,7 @@ pub const Basic = struct { const bitset0 = conn.rx_buffer.readU8(); const multiple = if (bitset0 & (1 << 0) == 0) true else false; try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Basic@{}.Ack", .{conn.channel}); + std.log.debug("\t<- Basic@{any}.Ack", .{conn.channel}); return Ack{ .delivery_tag = delivery_tag, .multiple = multiple, @@ -2150,9 +2148,9 @@ pub const Basic = struct { conn.tx_buffer.writeU8(bitset0); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Basic@{}.Ack ->", .{conn.channel}); + std.log.debug("Basic@{any}.Ack ->", .{conn.channel}); } // ack @@ -2174,7 +2172,7 @@ pub const Basic = struct { const bitset0 = conn.rx_buffer.readU8(); const requeue = if (bitset0 & (1 << 0) == 0) true else false; try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Basic@{}.Reject", .{conn.channel}); + std.log.debug("\t<- Basic@{any}.Reject", .{conn.channel}); return Reject{ .delivery_tag = delivery_tag, .requeue = requeue, @@ -2196,9 +2194,9 @@ pub const Basic = struct { conn.tx_buffer.writeU8(bitset0); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Basic@{}.Reject ->", .{conn.channel}); + std.log.debug("Basic@{any}.Reject ->", .{conn.channel}); } // reject @@ -2218,7 +2216,7 @@ pub const Basic = struct { const bitset0 = conn.rx_buffer.readU8(); const requeue = if (bitset0 & (1 << 0) == 0) true else false; try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Basic@{}.Recover_async", .{conn.channel}); + std.log.debug("\t<- Basic@{any}.Recover_async", .{conn.channel}); return RecoverAsync{ .requeue = requeue, }; @@ -2237,9 +2235,9 @@ pub const Basic = struct { conn.tx_buffer.writeU8(bitset0); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Basic@{}.Recover_async ->", .{conn.channel}); + std.log.debug("Basic@{any}.Recover_async ->", .{conn.channel}); } // recover_async @@ -2259,7 +2257,7 @@ pub const Basic = struct { const bitset0 = conn.rx_buffer.readU8(); const requeue = if (bitset0 & (1 << 0) == 0) true else false; try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Basic@{}.Recover", .{conn.channel}); + std.log.debug("\t<- Basic@{any}.Recover", .{conn.channel}); return Recover{ .requeue = requeue, }; @@ -2278,9 +2276,9 @@ pub const Basic = struct { conn.tx_buffer.writeU8(bitset0); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Basic@{}.Recover ->", .{conn.channel}); + std.log.debug("Basic@{any}.Recover ->", .{conn.channel}); } // recover @@ -2296,7 +2294,7 @@ pub const Basic = struct { pub fn read(conn: *Connector) !RecoverOk { try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Basic@{}.Recover_ok", .{conn.channel}); + std.log.debug("\t<- Basic@{any}.Recover_ok", .{conn.channel}); return RecoverOk{}; } }; @@ -2308,9 +2306,9 @@ pub const Basic = struct { conn.tx_buffer.writeMethodHeader(BASIC_CLASS, Basic.RECOVER_OK_METHOD); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Basic@{}.Recover_ok ->", .{conn.channel}); + std.log.debug("Basic@{any}.Recover_ok ->", .{conn.channel}); } // recover_ok @@ -2331,7 +2329,7 @@ pub const Tx = struct { pub fn read(conn: *Connector) !Select { try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Tx@{}.Select", .{conn.channel}); + std.log.debug("\t<- Tx@{any}.Select", .{conn.channel}); return Select{}; } }; @@ -2343,9 +2341,9 @@ pub const Tx = struct { conn.tx_buffer.writeMethodHeader(TX_CLASS, SELECT_METHOD); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Tx@{}.Select ->", .{conn.channel}); + std.log.debug("Tx@{any}.Select ->", .{conn.channel}); return awaitSelectOk(conn); } @@ -2362,7 +2360,7 @@ pub const Tx = struct { pub fn read(conn: *Connector) !SelectOk { try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Tx@{}.Select_ok", .{conn.channel}); + std.log.debug("\t<- Tx@{any}.Select_ok", .{conn.channel}); return SelectOk{}; } }; @@ -2374,9 +2372,9 @@ pub const Tx = struct { conn.tx_buffer.writeMethodHeader(TX_CLASS, Tx.SELECT_OK_METHOD); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Tx@{}.Select_ok ->", .{conn.channel}); + std.log.debug("Tx@{any}.Select_ok ->", .{conn.channel}); } // select_ok @@ -2392,7 +2390,7 @@ pub const Tx = struct { pub fn read(conn: *Connector) !Commit { try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Tx@{}.Commit", .{conn.channel}); + std.log.debug("\t<- Tx@{any}.Commit", .{conn.channel}); return Commit{}; } }; @@ -2404,9 +2402,9 @@ pub const Tx = struct { conn.tx_buffer.writeMethodHeader(TX_CLASS, COMMIT_METHOD); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Tx@{}.Commit ->", .{conn.channel}); + std.log.debug("Tx@{any}.Commit ->", .{conn.channel}); return awaitCommitOk(conn); } @@ -2423,7 +2421,7 @@ pub const Tx = struct { pub fn read(conn: *Connector) !CommitOk { try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Tx@{}.Commit_ok", .{conn.channel}); + std.log.debug("\t<- Tx@{any}.Commit_ok", .{conn.channel}); return CommitOk{}; } }; @@ -2435,9 +2433,9 @@ pub const Tx = struct { conn.tx_buffer.writeMethodHeader(TX_CLASS, Tx.COMMIT_OK_METHOD); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Tx@{}.Commit_ok ->", .{conn.channel}); + std.log.debug("Tx@{any}.Commit_ok ->", .{conn.channel}); } // commit_ok @@ -2453,7 +2451,7 @@ pub const Tx = struct { pub fn read(conn: *Connector) !Rollback { try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Tx@{}.Rollback", .{conn.channel}); + std.log.debug("\t<- Tx@{any}.Rollback", .{conn.channel}); return Rollback{}; } }; @@ -2465,9 +2463,9 @@ pub const Tx = struct { conn.tx_buffer.writeMethodHeader(TX_CLASS, ROLLBACK_METHOD); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Tx@{}.Rollback ->", .{conn.channel}); + std.log.debug("Tx@{any}.Rollback ->", .{conn.channel}); return awaitRollbackOk(conn); } @@ -2484,7 +2482,7 @@ pub const Tx = struct { pub fn read(conn: *Connector) !RollbackOk { try conn.rx_buffer.readEOF(); - std.log.debug("\t<- Tx@{}.Rollback_ok", .{conn.channel}); + std.log.debug("\t<- Tx@{any}.Rollback_ok", .{conn.channel}); return RollbackOk{}; } }; @@ -2496,9 +2494,9 @@ pub const Tx = struct { conn.tx_buffer.writeMethodHeader(TX_CLASS, Tx.ROLLBACK_OK_METHOD); conn.tx_buffer.updateFrameLength(); // TODO: do we need to retry write (if n isn't as high as we expect)? - const n = try std.os.write(conn.file.handle, conn.tx_buffer.extent()); + _ = try std.posix.write(conn.file.handle, conn.tx_buffer.extent()); conn.tx_buffer.reset(); - std.log.debug("Tx@{}.Rollback_ok ->", .{conn.channel}); + std.log.debug("Tx@{any}.Rollback_ok ->", .{conn.channel}); } // rollback_ok diff --git a/src/table.zig b/src/table.zig index 0485456..fd0d063 100644 --- a/src/table.zig +++ b/src/table.zig @@ -29,7 +29,7 @@ pub const Table = struct { // can't error here. pub fn lookup(self: *Self, comptime T: type, key: []const u8) ?T { defer self.buf.reset(); - const length = self.buf.readU32(); + _ = self.buf.readU32(); while (self.buf.isMoreData()) { const current_key = self.buf.readShortString(); @@ -37,7 +37,7 @@ pub const Table = struct { const t = self.buf.readU8(); switch (t) { 'F' => { - var table = self.buf.readTable(); + const table = self.buf.readTable(); if (@TypeOf(table) == T and correct_key) return table; }, 't' => { @@ -94,13 +94,13 @@ pub const Table = struct { } fn updateLength(self: *Self) void { - mem.writeInt(u32, @ptrCast(*[@sizeOf(u32)]u8, &self.buf.mem[0]), @intCast(u32, self.buf.head - @sizeOf(u32)), .Big); + mem.writeInt(u32, @ptrCast(&self.buf.mem[0]), @intCast(self.buf.head - @sizeOf(u32)), .big); } pub fn print(self: *Self) void { for (self.buf.mem[0..self.buf.head]) |x| { - std.debug.warn("0x{x:0>2} ", .{x}); + std.debug.print("0x{x:0>2} ", .{x}); } - std.debug.warn("\n", .{}); + std.debug.print("\n", .{}); } }; diff --git a/src/wire.zig b/src/wire.zig index 9a3cedc..32fdc4e 100644 --- a/src/wire.zig +++ b/src/wire.zig @@ -24,11 +24,11 @@ pub const WireBuffer = struct { } pub fn printSpan(self: *Self) void { - for (self.mem[self.head..self.end]) |byte, i| { - std.debug.warn("{x:0>2}", .{byte}); - if ((i + 1) % 8 == 0) std.debug.warn("\n", .{}) else std.debug.warn(" ", .{}); + for (self.mem[self.head..self.end], 0..) |byte, i| { + std.debug.print("{x:0>2}", .{byte}); + if ((i + 1) % 8 == 0) std.debug.print("\n", .{}) else std.debug.print(" ", .{}); } - std.debug.warn("\n", .{}); + std.debug.print("\n", .{}); } // move head back to beginning of buffer @@ -43,7 +43,7 @@ pub const WireBuffer = struct { // shift moves data between head and end to the front of mem pub fn shift(self: *Self) void { const new_end = self.end - self.head; - mem.copy(u8, self.mem[0..new_end], self.mem[self.head..self.end]); + mem.copyForwards(u8, self.mem[0..new_end], self.mem[self.head..self.end]); self.head = 0; self.end = new_end; } @@ -73,10 +73,10 @@ pub const WireBuffer = struct { const frame_type = self.readU8(); const channel = self.readU16(); const size = self.readU32(); - // std.debug.warn("frame_type: {}, channel: {}, size: {}\n", .{frame_type, channel, size}); + // std.debug.print("frame_type: {any}, channel: {any}, size: {any}\n", .{frame_type, channel, size}); return FrameHeader{ - .@"type" = @intToEnum(FrameType, frame_type), + .type = @enumFromInt(frame_type), .channel = channel, .size = size, }; @@ -105,7 +105,7 @@ pub const WireBuffer = struct { } pub fn writeFrameHeader(self: *Self, frame_type: FrameType, channel: u16, size: u32) void { - self.writeU8(@enumToInt(frame_type)); + self.writeU8(@intFromEnum(frame_type)); self.writeU16(channel); self.writeU32(size); // This will be overwritten later } @@ -114,7 +114,7 @@ pub const WireBuffer = struct { self.writeEOF(); const head = self.head; self.head = 3; - self.writeU32(@intCast(u32, head - 8)); // size is head - header length (7 bytes) - frame end (1 bytes) + self.writeU32(@intCast(head - 8)); // size is head - header length (7 bytes) - frame end (1 bytes) self.head = head; } @@ -170,7 +170,7 @@ pub const WireBuffer = struct { pub fn writeBody(self: *Self, channel: u16, body: []const u8) void { self.writeFrameHeader(.Body, channel, 0); - std.mem.copy(u8, self.mem[self.head..], body); + std.mem.copyForwards(u8, self.mem[self.head..], body); self.head += body.len; self.updateFrameLength(); } @@ -181,46 +181,46 @@ pub const WireBuffer = struct { } pub fn readU8(self: *Self) u8 { - const r = @ptrCast(u8, self.mem[self.head]); + const r: u8 = self.mem[self.head]; self.head += 1; return r; } pub fn writeU8(self: *Self, byte: u8) void { - std.mem.writeInt(u8, &self.mem[self.head], byte, .Big); + std.mem.writeInt(u8, &self.mem[self.head], byte, .big); self.head += 1; } pub fn readU16(self: *Self) u16 { - const r = std.mem.readInt(u16, @ptrCast(*const [@sizeOf(u16)]u8, &self.mem[self.head]), .Big); + const r = std.mem.readInt(u16, @ptrCast(&self.mem[self.head]), .big); self.head += @sizeOf(u16); return r; } pub fn writeU16(self: *Self, short: u16) void { - std.mem.writeInt(u16, @ptrCast(*[@sizeOf(u16)]u8, &self.mem[self.head]), short, .Big); + std.mem.writeInt(u16, @ptrCast(&self.mem[self.head]), short, .big); self.head += 2; } pub fn readU32(self: *Self) u32 { - const r = std.mem.readInt(u32, @ptrCast(*const [@sizeOf(u32)]u8, &self.mem[self.head]), .Big); + const r = std.mem.readInt(u32, @ptrCast(&self.mem[self.head]), .big); self.head += @sizeOf(u32); return r; } pub fn writeU32(self: *Self, number: u32) void { - std.mem.writeInt(u32, @ptrCast(*[@sizeOf(u32)]u8, &self.mem[self.head]), number, .Big); + std.mem.writeInt(u32, @ptrCast(&self.mem[self.head]), number, .big); self.head += @sizeOf(u32); } pub fn readU64(self: *Self) u64 { - const r = std.mem.readInt(u64, @ptrCast(*const [@sizeOf(u64)]u8, &self.mem[self.head]), .Big); + const r = std.mem.readInt(u64, @ptrCast(&self.mem[self.head]), .big); self.head += @sizeOf(u64); return r; } pub fn writeU64(self: *Self, number: u64) void { - std.mem.writeInt(u64, @ptrCast(*[@sizeOf(u64)]u8, &self.mem[self.head]), number, .Big); + std.mem.writeInt(u64, @ptrCast(&self.mem[self.head]), number, .big); self.head += @sizeOf(u64); } @@ -242,8 +242,8 @@ pub const WireBuffer = struct { } pub fn writeShortString(self: *Self, string: []const u8) void { - self.writeU8(@intCast(u8, string.len)); - std.mem.copy(u8, self.mem[self.head..], string); + self.writeU8(@intCast(string.len)); + std.mem.copyForwards(u8, self.mem[self.head..], string); self.head += string.len; } @@ -255,8 +255,8 @@ pub const WireBuffer = struct { } pub fn writeLongString(self: *Self, string: []const u8) void { - self.writeU32(@intCast(u32, string.len)); - std.mem.copy(u8, self.mem[self.head..], string); + self.writeU32(@intCast(string.len)); + std.mem.copyForwards(u8, self.mem[self.head..], string); self.head += string.len; } @@ -271,7 +271,7 @@ pub const WireBuffer = struct { const length = self.readU32(); while (self.head - table_start < (length + @sizeOf(u32))) { - const key = self.readShortString(); + _ = self.readShortString(); const t = self.readU8(); switch (t) { @@ -279,13 +279,13 @@ pub const WireBuffer = struct { _ = self.readTable(); }, 't' => { - const b = self.readBool(); + _ = self.readBool(); }, 's' => { - const s = self.readShortString(); + _ = self.readShortString(); }, 'S' => { - const s = self.readLongString(); + _ = self.readLongString(); }, else => continue, } @@ -308,7 +308,7 @@ pub const WireBuffer = struct { pub fn writeTable(self: *Self, table: ?*Table) void { if (table) |t| { const table_bytes = t.buf.extent(); - std.mem.copy(u8, self.mem[self.head..], table_bytes); + std.mem.copyForwards(u8, self.mem[self.head..], table_bytes); self.head += table_bytes.len; } else { self.writeU32(0); @@ -317,7 +317,7 @@ pub const WireBuffer = struct { }; pub const FrameHeader = struct { - @"type": FrameType = .Method, + type: FrameType = .Method, channel: u16 = 0, size: u32 = 0, }; @@ -349,12 +349,12 @@ test "buffer is full" { var memory: [16]u8 = [_]u8{0} ** 16; var buf = WireBuffer.init(memory[0..]); - testing.expect(buf.isFull() == false); + try testing.expect(buf.isFull() == false); buf.incrementEnd(16); // simluate writing 16 bytes into buffer // The buffer should now be full - testing.expect(buf.isFull() == true); - testing.expect(buf.remaining().len == 0); + try testing.expect(buf.isFull() == true); + try testing.expect(buf.remaining().len == 0); } test "basic write / read" { @@ -379,18 +379,18 @@ test "basic write / read" { tx_buf.writeTable(&tx_table); // Simulate transmission - mem.copy(u8, rx_buf.remaining(), tx_buf.extent()); + mem.copyForwards(u8, rx_buf.remaining(), tx_buf.extent()); rx_buf.incrementEnd(tx_buf.extent().len); // Read from rx_buf (image this is the client's buffer) - testing.expect(rx_buf.readU8() == 22); - testing.expect(rx_buf.readU16() == 23); - testing.expect(rx_buf.readU32() == 24); - testing.expect(mem.eql(u8, rx_buf.readShortString(), "Hello")); - testing.expect(mem.eql(u8, rx_buf.readLongString(), "World")); - testing.expect(rx_buf.readBool() == true); + try testing.expect(rx_buf.readU8() == 22); + try testing.expect(rx_buf.readU16() == 23); + try testing.expect(rx_buf.readU32() == 24); + try testing.expect(mem.eql(u8, rx_buf.readShortString(), "Hello")); + try testing.expect(mem.eql(u8, rx_buf.readLongString(), "World")); + try testing.expect(rx_buf.readBool() == true); var rx_table = rx_buf.readTable(); - testing.expect(rx_table.lookup(bool, "flag1").? == true); - testing.expect(rx_table.lookup(bool, "flag2").? == false); - testing.expect(mem.eql(u8, rx_table.lookup([]u8, "longstring").?, "zig is the best")); + try testing.expect(rx_table.lookup(bool, "flag1").? == true); + try testing.expect(rx_table.lookup(bool, "flag2").? == false); + try testing.expect(mem.eql(u8, rx_table.lookup([]u8, "longstring").?, "zig is the best")); }