Changes
4 changed files (+134/-8)
-
-
@@ -30,4 +30,6 @@ browse.browse.Response,browse.load.Request, browse.load.Response, registry.info.Response, registry.register.Request, registry.register.Response, };
-
-
-
@@ -142,14 +142,25 @@ .parameters = &.{.{ .type = self_pointer }},.return_type = .fromZigType([*:0]const u8), }; inline for (info.fields, 0..) |field, j| { methods[j] = .{ .name = std.fmt.comptimePrint("set_{s}", .{field.name}), .parameters = &.{ .{ .type = self_pointer }, .{ .type = .fromZigType(CSetterValue(field.type)) }, }, .return_type = .{ .value = .void }, }; if (field.type == [][]const u8) { methods[j] = .{ .name = std.fmt.comptimePrint("append_{s}", .{field.name}), .parameters = &.{ .{ .type = self_pointer }, .{ .type = .fromZigType([*:0]const u8) }, }, .return_type = .{ .value = .void }, }; } else { methods[j] = .{ .name = std.fmt.comptimePrint("set_{s}", .{field.name}), .parameters = &.{ .{ .type = self_pointer }, .{ .type = .fromZigType(CSetterValue(field.type)) }, }, .return_type = .{ .value = .void }, }; } } items[i] = .{
-
-
-
@@ -69,6 +69,42 @@ .optional => |optional| .{ optional.child, true },else => .{ field.type, false }, }; // Slice of strings is difficult to handle, so it gets special method. if (UnwrappedValue == [][]const u8) { const appender = struct { fn append(ptr: *T, value: [*:0]const u8) callconv(.C) void { const copy = std.heap.c_allocator.dupe(u8, std.mem.span(value)) catch { std.log.err("Failed to copy string for {s}: out of memory", .{ field.name, }); return; }; const len = @field(@field(ptr, opts.field), field.name).len; const new_slice = std.heap.c_allocator.realloc( @field(@field(ptr, opts.field), field.name), len + 1, ) catch { std.log.err("Failed to resize {s}: out of memory", .{ field.name, }); std.heap.c_allocator.free(copy); return; }; new_slice[len] = copy; @field(@field(ptr, opts.field), field.name) = new_slice; } }; @export(&appender.append, .{ .name = std.fmt.comptimePrint("{s}_append_{s}", .{ T.cname, field.name }), }); continue; } const CValue = switch (@typeInfo(UnwrappedValue)) { .pointer => |pointer| switch (pointer.size) { .slice => [*:0]pointer.child,
-
-
-
@@ -60,3 +60,80 @@ allocator.free(std.mem.span(self.core_id));} }), .{}); }; pub const register = struct { pub const Request = json.Serializable(rc.RefCounted(struct { pub const cname = "roon_registry_register_Request"; extension_id: ?[]const u8 = null, display_name: ?[]const u8 = null, display_version: ?[]const u8 = null, publisher: ?[]const u8 = null, email: ?[]const u8 = null, token: ?[]const u8 = null, required_services: [][]const u8 = &.{}, optional_services: [][]const u8 = &.{}, provided_services: [][]const u8 = &.{}, pub fn init() @This() { return .{}; } pub fn deinit(self: *const @This()) void { inline for (@typeInfo(@This()).@"struct".fields) |field| { if (field.type == ?[]const u8) { if (@field(self, field.name)) |value| { allocator.free(value); } continue; } if (field.type == [][]const u8) { for (@field(self, field.name)) |service| { allocator.free(service); } allocator.free(@field(self, field.name)); continue; } @compileError("Unhandled field type."); } } }), .{}); export fn roon_registry_register_Request_new() callconv(.C) ?*Request { return Request.new(.init()) catch return null; } pub const Response = json.Deserializable(rc.RefCounted(extern struct { pub const cname = "json_registry_register_Response"; pub const deserializable = true; core_id: [*:0]const u8, token: [*:0]const u8, pub fn init(raw: Raw) !@This() { const core_id = try allocator.dupeZ(u8, raw.core_id); errdefer allocator.free(core_id); const token = try allocator.dupeZ(u8, raw.token); errdefer allocator.free(token); return .{ .core_id = core_id.ptr, .token = token.ptr, }; } pub const Raw = struct { core_id: []const u8, token: []const u8, }; pub fn deinit(self: *const @This()) void { allocator.free(std.mem.span(self.token)); allocator.free(std.mem.span(self.core_id)); } }), .{}); };
-