connection: eliminate String method variants
After contemplating this for a little bit, there's no point in exposing these separately from the plain variants. Even nats.c internally calls its plain variants after calling `strlen` on the input. Zig benefits from having nicer pointer types than C, so we get "string" handling for free from the fact that the standard variants take slices anyway.
This commit is contained in:
parent
1256feb7ef
commit
65ab46f714
@ -15,7 +15,7 @@ fn onMessage(
|
||||
});
|
||||
|
||||
if (message.getReply()) |reply| {
|
||||
connection.publishString(reply, "salutations") catch @panic("HELP");
|
||||
connection.publish(reply, "salutations") catch @panic("HELP");
|
||||
}
|
||||
|
||||
userdata.* = true;
|
||||
@ -30,7 +30,7 @@ pub fn main() !void {
|
||||
defer subscription.destroy();
|
||||
|
||||
while (!done) {
|
||||
const reply = try connection.requestString("channel", "greetings", 1000);
|
||||
const reply = try connection.request("channel", "greetings", 1000);
|
||||
defer reply.destroy();
|
||||
|
||||
std.debug.print("Reply \"{s}\" got message: {s}\n", .{
|
||||
|
@ -244,16 +244,6 @@ pub const Connection = opaque {
|
||||
).raise();
|
||||
}
|
||||
|
||||
pub fn publishString(
|
||||
self: *Connection,
|
||||
subject: [:0]const u8,
|
||||
message: [:0]const u8,
|
||||
) Error!void {
|
||||
return Status.fromInt(
|
||||
nats_c.natsConnection_PublishString(@ptrCast(self), subject.ptr, message.ptr),
|
||||
).raise();
|
||||
}
|
||||
|
||||
pub fn publishMessage(self: *Connection, message: *Message) Error!void {
|
||||
return Status.fromInt(
|
||||
nats_c.natsConnection_PublishMsg(@ptrCast(self), @ptrCast(message)),
|
||||
@ -277,22 +267,6 @@ pub const Connection = opaque {
|
||||
).raise();
|
||||
}
|
||||
|
||||
pub fn publishRequestString(
|
||||
self: *Connection,
|
||||
subject: [:0]const u8,
|
||||
reply: [:0]const u8,
|
||||
message: [:0]const u8,
|
||||
) Error!void {
|
||||
return Status.fromInt(
|
||||
nats_c.natsConnection_PublishRequestString(
|
||||
@ptrCast(self),
|
||||
subject.ptr,
|
||||
reply.ptr,
|
||||
message.ptr,
|
||||
),
|
||||
).raise();
|
||||
}
|
||||
|
||||
pub fn request(
|
||||
self: *Connection,
|
||||
subject: [:0]const u8,
|
||||
@ -313,25 +287,6 @@ pub const Connection = opaque {
|
||||
return status.toError() orelse response;
|
||||
}
|
||||
|
||||
pub fn requestString(
|
||||
self: *Connection,
|
||||
subject: [:0]const u8,
|
||||
req: [:0]const u8,
|
||||
timeout: i64,
|
||||
) Error!*Message {
|
||||
var response: *Message = undefined;
|
||||
|
||||
const status = Status.fromInt(nats_c.natsConnection_RequestString(
|
||||
@ptrCast(&response),
|
||||
@ptrCast(self),
|
||||
subject.ptr,
|
||||
req.ptr,
|
||||
timeout,
|
||||
));
|
||||
|
||||
return status.toError() orelse response;
|
||||
}
|
||||
|
||||
pub fn requestMessage(
|
||||
self: *Connection,
|
||||
req: *Message,
|
||||
|
Loading…
x
Reference in New Issue
Block a user