From 43fbfb46b75705d2cb37c1a806450fe5647fa26e Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 2 Jun 2024 17:08:00 -0700 Subject: [PATCH] add Array convenience type --- json.zig | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/json.zig b/json.zig index bcf34354f8683562a86f077d20247bc336c4d701..f5a1f589f52d7122f1ba1487dec1e27ec2997437 100644 --- a/json.zig +++ b/json.zig @@ -535,7 +535,7 @@ pub const ValueIndex = enum(u32) { return this.v().string.to(); } - pub fn array(this: ValueIndex) []align(1) const ValueIndex { + pub fn array(this: ValueIndex) Array { return this.v().array.to(); } @@ -581,6 +581,8 @@ pub const Value = union(enum(u8)) { } }; +pub const Array = []align(1) const ValueIndex; + pub const StringIndex = enum(u32) { _, @@ -616,7 +618,7 @@ pub const ArrayIndex = enum(u32) { try writer.writeAll("]"); } - pub fn to(this: ArrayIndex) []align(1) const ValueIndex { + pub fn to(this: ArrayIndex) Array { var d = doc.?.extras.ptr[@intFromEnum(this)..]; std.debug.assert(@as(Value.Tag, @enumFromInt(d[0])) == .array); const len: u32 = @bitCast(d[1..5].*); @@ -642,7 +644,7 @@ pub const ObjectIndex = enum(u32) { try writer.writeAll("}"); } - pub fn to(this: ObjectIndex) struct { []align(1) const StringIndex, []align(1) const ValueIndex } { + pub fn to(this: ObjectIndex) struct { []align(1) const StringIndex, Array } { var d = doc.?.extras.ptr[@intFromEnum(this)..]; std.debug.assert(@as(Value.Tag, @enumFromInt(d[0])) == .object); const len: u32 = @bitCast(d[1..5].*); @@ -670,7 +672,7 @@ pub const ObjectIndex = enum(u32) { return if (this.get(needle, .object)) |v| v.object() else null; } - pub fn getA(this: ObjectIndex, needle: []const u8) ?[]align(1) const ValueIndex { + pub fn getA(this: ObjectIndex, needle: []const u8) ?Array { return if (this.get(needle, .array)) |v| v.array() else null; } -- 2.54.0