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) {...@@ -535,7 +535,7 @@ pub const ValueIndex = enum(u32) {
535 return this.v().string.to();535 return this.v().string.to();
536 }536 }
537537
538 pub fn array(this: ValueIndex) []align(1) const ValueIndex {538 pub fn array(this: ValueIndex) Array {
539 return this.v().array.to();539 return this.v().array.to();
540 }540 }
541541
...@@ -581,6 +581,8 @@ pub const Value = union(enum(u8)) {...@@ -581,6 +581,8 @@ pub const Value = union(enum(u8)) {
581 }581 }
582};582};
583583
584pub const Array = []align(1) const ValueIndex;
585
584pub const StringIndex = enum(u32) {586pub const StringIndex = enum(u32) {
585 _,587 _,
586588
...@@ -616,7 +618,7 @@ pub const ArrayIndex = enum(u32) {...@@ -616,7 +618,7 @@ pub const ArrayIndex = enum(u32) {
616 try writer.writeAll("]");618 try writer.writeAll("]");
617 }619 }
618620
619 pub fn to(this: ArrayIndex) []align(1) const ValueIndex {621 pub fn to(this: ArrayIndex) Array {
620 var d = doc.?.extras.ptr[@intFromEnum(this)..];622 var d = doc.?.extras.ptr[@intFromEnum(this)..];
621 std.debug.assert(@as(Value.Tag, @enumFromInt(d[0])) == .array);623 std.debug.assert(@as(Value.Tag, @enumFromInt(d[0])) == .array);
622 const len: u32 = @bitCast(d[1..5].*);624 const len: u32 = @bitCast(d[1..5].*);
...@@ -642,7 +644,7 @@ pub const ObjectIndex = enum(u32) {...@@ -642,7 +644,7 @@ pub const ObjectIndex = enum(u32) {
642 try writer.writeAll("}");644 try writer.writeAll("}");
643 }645 }
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 } {
646 var d = doc.?.extras.ptr[@intFromEnum(this)..];648 var d = doc.?.extras.ptr[@intFromEnum(this)..];
647 std.debug.assert(@as(Value.Tag, @enumFromInt(d[0])) == .object);649 std.debug.assert(@as(Value.Tag, @enumFromInt(d[0])) == .object);
648 const len: u32 = @bitCast(d[1..5].*);650 const len: u32 = @bitCast(d[1..5].*);
...@@ -670,7 +672,7 @@ pub const ObjectIndex = enum(u32) {...@@ -670,7 +672,7 @@ pub const ObjectIndex = enum(u32) {
670 return if (this.get(needle, .object)) |v| v.object() else null;672 return if (this.get(needle, .object)) |v| v.object() else null;
671 }673 }
672674
673 pub fn getA(this: ObjectIndex, needle: []const u8) ?[]align(1) const ValueIndex {675 pub fn getA(this: ObjectIndex, needle: []const u8) ?Array {
674 return if (this.get(needle, .array)) |v| v.array() else null;676 return if (this.get(needle, .array)) |v| v.array() else null;
675 }677 }
676678