authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-02 17:08:00 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-02 17:08:00 -07:00
log43fbfb46b75705d2cb37c1a806450fe5647fa26e
tree40946975487a3f05e0dd1bcd3210b15c9c84e83e
parentfba9092061e7b3ff6180d96f6edd2ad413082f80

add Array convenience type


1 files changed, 6 insertions(+), 4 deletions(-)

json.zig+6-4
......@@ -535,7 +535,7 @@ pub const ValueIndex = enum(u32) {
535535 return this.v().string.to();
536536 }
537537
538 pub fn array(this: ValueIndex) []align(1) const ValueIndex {
538 pub fn array(this: ValueIndex) Array {
539539 return this.v().array.to();
540540 }
541541
......@@ -581,6 +581,8 @@ pub const Value = union(enum(u8)) {
581581 }
582582};
583583
584pub const Array = []align(1) const ValueIndex;
585
584586pub const StringIndex = enum(u32) {
585587 _,
586588
......@@ -616,7 +618,7 @@ pub const ArrayIndex = enum(u32) {
616618 try writer.writeAll("]");
617619 }
618620
619 pub fn to(this: ArrayIndex) []align(1) const ValueIndex {
621 pub fn to(this: ArrayIndex) Array {
620622 var d = doc.?.extras.ptr[@intFromEnum(this)..];
621623 std.debug.assert(@as(Value.Tag, @enumFromInt(d[0])) == .array);
622624 const len: u32 = @bitCast(d[1..5].*);
......@@ -642,7 +644,7 @@ pub const ObjectIndex = enum(u32) {
642644 try writer.writeAll("}");
643645 }
644646
645 pub fn to(this: ObjectIndex) struct { []align(1) const StringIndex, []align(1) const ValueIndex } {
647 pub fn to(this: ObjectIndex) struct { []align(1) const StringIndex, Array } {
646648 var d = doc.?.extras.ptr[@intFromEnum(this)..];
647649 std.debug.assert(@as(Value.Tag, @enumFromInt(d[0])) == .object);
648650 const len: u32 = @bitCast(d[1..5].*);
......@@ -670,7 +672,7 @@ pub const ObjectIndex = enum(u32) {
670672 return if (this.get(needle, .object)) |v| v.object() else null;
671673 }
672674
673 pub fn getA(this: ObjectIndex, needle: []const u8) ?[]align(1) const ValueIndex {
675 pub fn getA(this: ObjectIndex, needle: []const u8) ?Array {
674676 return if (this.get(needle, .array)) |v| v.array() else null;
675677 }
676678