Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to latest zig #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/reply-bot.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ fn processEvent(event: zCord.Gateway.Event) !void {
else => {},
.message_create => {
const paths = try event.data.pathMatch(struct {
@"channel_id": zCord.Snowflake(.channel),
@"content": std.BoundedArray(u8, 0x1000),
channel_id: zCord.Snowflake(.channel),
content: std.BoundedArray(u8, 0x1000),
});

if (std.mem.eql(u8, paths.content.constSlice(), "Hello")) {
Expand Down
24 changes: 12 additions & 12 deletions src/Gateway.zig
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ fn connect(self: *Gateway) !void {
defer self.wz.flushReader() catch |err| {
flush_error = err;
};
errdefer |err| log.info("{}", .{stream.debugInfo()});
errdefer log.info("{}", .{stream.debugInfo()});

const root = try stream.root();
const paths = try root.pathMatch(struct {
@"op": u8,
op: u8,
@"d.heartbeat_interval": u32,
});

if (paths.@"op" != @enumToInt(discord.Gateway.Opcode.hello)) {
if (paths.op != @enumToInt(discord.Gateway.Opcode.hello)) {
return error.MalformedHelloResponse;
}

Expand Down Expand Up @@ -183,27 +183,27 @@ fn connect(self: *Gateway) !void {
defer self.wz.flushReader() catch |err| {
flush_error = err;
};
errdefer |err| log.info("{}", .{stream.debugInfo()});
errdefer log.info("{}", .{stream.debugInfo()});

const root = try stream.root();
// TODO: possibly "rewind" this to allow data reconsumption
const paths = try root.pathMatch(struct {
@"t": std.BoundedArray(u8, 0x100),
@"s": ?u32,
@"op": u8,
t: std.BoundedArray(u8, 0x100),
s: ?u32,
op: u8,
@"d.session_id": std.BoundedArray(u8, 0x100),
@"d.user.username": std.BoundedArray(u8, 0x100),
@"d.user.discriminator": std.BoundedArray(u8, 0x100),
});

if (!std.mem.eql(u8, paths.@"t".constSlice(), "READY")) {
if (!std.mem.eql(u8, paths.t.constSlice(), "READY")) {
return error.MalformedIdentify;
}
if (paths.@"op" != @enumToInt(discord.Gateway.Opcode.dispatch)) {
if (paths.op != @enumToInt(discord.Gateway.Opcode.dispatch)) {
return error.MalformedIdentify;
}

if (paths.@"s") |seq| {
if (paths.s) |seq| {
self.seq = seq;
}

Expand Down Expand Up @@ -347,7 +347,7 @@ fn recvEventNoReconnect(self: *Gateway) !Event {
const gateway_event = self.processEvent(self.wz.reader()) catch |err| switch (err) {
error.ConnectionReset, error.InvalidSession => |e| return e,
else => {
log.warn("Process chunks failed: {s}", .{err});
log.warn("Process chunks failed: {s}", .{@errorName(err)});
continue;
},
};
Expand Down Expand Up @@ -416,7 +416,7 @@ fn processEvent(self: *Gateway, reader: anytype) !?Event {
}
},
else => {
log.info("Unhandled {} -- {s}", .{ op, name });
log.info("Unhandled {} -- {?}", .{ op.?, name });
match.value.debugDump(std.io.getStdErr().writer()) catch {};
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/Gateway/Heartbeat.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn send(self: Heartbeat, msg: Message) void {

pub const CallbackHandler = struct {
context: *anyopaque,
func: fn (ctx: *anyopaque, msg: Message) void,
func: *const fn (ctx: *anyopaque, msg: Message) void,
};

const ThreadHandler = struct {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/https.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const iguanaTLS = @import("iguanaTLS");
const util = @import("util.zig");

pub const root_ca = struct {
const pem = @embedFile("../cacert.pem");
const pem = @embedFile("cacert.pem");
var cert_chain: ?iguanaTLS.x509.CertificateChain = null;

/// Initializes the bundled root certificates
Expand Down
2 changes: 1 addition & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ pub const util = @import("util.zig");
pub const root_ca = https.root_ca;
pub const Snowflake = discord.Snowflake;

test "" {
test {
std.testing.refAllDecls(@This());
}
2 changes: 1 addition & 1 deletion src/util.zig
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub const TimeoutStream = struct {
return .{ .context = self };
}

const PollFdEvents = std.meta.fieldInfo(std.os.pollfd, .events).field_type;
const PollFdEvents = std.meta.fieldInfo(std.os.pollfd, .events).type;
fn pollWait(self: TimeoutStream, events: PollFdEvents) !void {
if (self.expiration) |expiration| {
var polling = [_]std.os.pollfd{.{
Expand Down
3 changes: 2 additions & 1 deletion zig.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ description: Zig ⚡ Discord API with zero allocations in the critical path
dependencies:
- src: git https://github.com/truemedian/wz
- src: git https://github.com/truemedian/hzzp
- src: git https://github.com/marler8997/iguanaTLS
- src: git https://github.com/nektro/iguanaTLS
- src: git https://github.com/fengb/zasp