travisstaloch / simdjzon

simdjson port to zig
103 stars 5 forks source link

Parser assumes all slices are strings #15

Closed FreerGit closed 1 year ago

FreerGit commented 1 year ago
const std = @import("std");
const dom = @import("src/dom.zig");

test {
    const allocator = std.testing.allocator;

    const T = struct { xs: []struct { a: u8 } };

    const input =
        \\{ "xs": [
        \\{"a": 42}
        \\]}
    ;

    var parser = try dom.Parser.initFixedBuffer(allocator, input, .{});
    defer parser.deinit();
    try parser.parse();

    var s: T = undefined;
    try parser.element().get(&s);

    std.debug.print("\n{} \n", .{s});
}

The parser will fail, expecting the [{...}] to be a string.

travisstaloch commented 1 year ago

thanks for the report!

addressed in https://github.com/travisstaloch/simdjzon/commit/a74016e4e041e8535dd2d437bddef8c94d84e5a2

please let me know if there are any other issues (as i'm sure there will be). or if satisfies your needs, you may close it.

travisstaloch commented 1 year ago

Oh i should describe what i changed. I added a dom.Element.get_alloc() method which accepts a user allocator. its the same as get() but can handle non-string slice types.

travisstaloch commented 1 year ago

Previous fix was incomplete and only worked for objects with 1 field.

Addressed in https://github.com/travisstaloch/simdjzon/commit/acd573f7b2a10fafe56179024274c5befdc4dc01 which also added more complete tests.

Should be actually fixed now :slightly_smiling_face:

FreerGit commented 1 year ago

Cloned latest main and works perfectly. Closing this :)