Using ziggy to parse a simple file
config.zgy
{
.heartbeat = "1s",
}
config struct used to parse the zgy file
pub const Config = struct {
heartbeat: []const u8,
};
below is the function, which reads the file and uses ziggy. Based on new update from ziggy the function is using deserializeLeaky as the allocation passed is a arena allocator.
pub fn read_config(io: std.Io, file_name: []const u8, allocator: std.mem.Allocator) !Config {
const data = try read.read_file(io, file_name, allocator);
var meta: ziggy.Deserializer.Meta = .init;
const file_data: [:0]u8 = @ptrCast(data);
print("data from file: {s}\n", .{file_data});
const cfg = try ziggy.deserializeLeaky(Config, allocator, file_data, &meta, .{});
return cfg;
}
error message received is below. The part where code reads the file works as expected. Validated from print statement in fn. Not sure what is the issue, need help with parsing error error: Unexpected
zig build run
data from file: {
.heartbeat = "1s",
}
error: Unexpected
/home/karthick/.cache/zig/p/ziggy-0.1.0-kTg8vwR1BgALu5bIsNMQrQ2h2tpD8P-8Ax-1WjLU3Cuf/src/Deserializer.zig:180:5: 0x1189e47 in unexpected (root.zig)
return error.Unexpected;
^
/home/karthick/.cache/zig/p/ziggy-0.1.0-kTg8vwR1BgALu5bIsNMQrQ2h2tpD8P-8Ax-1WjLU3Cuf/src/Deserializer.zig:463:24: 0x117cd6b in deserializeOne__anon_27301 (root.zig)
.lb => return d.deserializeDict(T, &result, info, &seen, first),
^
/home/karthick/.cache/zig/p/ziggy-0.1.0-kTg8vwR1BgALu5bIsNMQrQ2h2tpD8P-8Ax-1WjLU3Cuf/src/Deserializer.zig:261:20: 0x11697aa in deserializeLeaky__anon_26867 (root.zig)
const result = try d.deserializeOne(T, tokenizer.next(src, true), true);
^
/home/karthick/projects/memcache/coordinator/src/config.zig:15:17: 0x1166813 in read_config (main.zig)
const cfg = try ziggy.deserializeLeaky(Config, allocator, file_data, &meta, .{});