const std = @import("std"); const Store = @import("../store.zig"); const json_utils = @import("../json_utils.zig"); const json = std.json; const Allocator = std.mem.Allocator; const ServerStatus = @This(); allocator: Allocator, status: []const u8, version: []const u8, characters_online: u64, pub fn parse(store: *Store, object: json.ObjectMap, allocator: Allocator) !ServerStatus { _ = store; const characters_online = json_utils.getInteger(object, "characters_online") orelse return error.MissingProperty; if (characters_online < 0) { return error.InvalidCharactersOnline; } return ServerStatus{ .allocator = allocator, .characters_online = @intCast(characters_online), .status = (try json_utils.dupeString(allocator, object, "status")) orelse return error.MissingStatus, .version = (try json_utils.dupeString(allocator, object, "version")) orelse return error.MissingVersion }; } pub fn deinit(self: ServerStatus) void { self.allocator.free(self.status); self.allocator.free(self.version); }