I have this piece of testing code but it always returns EndOfStream error.
From what I understand and saw in the stdlib it can only return that if the read bytes are less than what the reader buffer can hold. But My file has over 440k characters so that shouldn't be the case here.
-# I know the while loop will overwrite the map_data variable if there are multiple files. This is just temporary for testing.
pub fn start() !void {
const smp = std.heap.smp_allocator;
const maps_path = "assets/maps";
var maps_dir = try std.fs.cwd().openDir(maps_path, .{.iterate = true});
defer maps_dir.close();
var map_data: TiledMapData = undefined;
var maps_iter = maps_dir.iterate();
while (try maps_iter.next()) |map| {
switch (map.kind) {
.file => {
var read_buf: [1024]u8 = undefined;
const file = try maps_dir.openFile(map.name, .{});
var file_reader = file.reader(&read_buf).interface;
const json_str = try file_reader.readAlloc(
smp,
4_000_000
);
map_data = try parseData(smp, json_str);
// TODO Change the function so it can return multiple maps!
},
else => unreachable,
}
}
std.debug.print("{any}", .{map_data.tile_layers});
std.debug.print("{any}", .{map_data.collision_layer});
std.debug.print("{any}", .{map_data.marker_layer});
}