const std = @import("std"); pub const deserialise = @import("deserialise.zig"); pub const Raw = union(enum) { string: []u8, binary: []u8, pub fn deinit(self: Raw, alloc: std.mem.Allocator) void { switch (self) { .string => |s| alloc.free(s), .binary => |b| alloc.free(b), } } }; pub const MapEntry = struct { key: Object, value: Object, pub fn deinit(self: MapEntry, alloc: std.mem.Allocator) void { self.key.deinit(alloc); self.value.deinit(alloc); } }; pub const Object = union(enum) { nil, bool: bool, integer: i64, float: f64, raw: Raw, array: []Object, map: []MapEntry, extension: struct { type: u8, bytes: []u8 }, pub fn deinit(self: Object, alloc: std.mem.Allocator) void { switch (self) { .raw => |raw| raw.deinit(alloc), .array => |array| { for (array) |x| { x.deinit(alloc); } alloc.free(array); }, .map => |map| { for (map) |elem| { elem.key.deinit(alloc); elem.value.deinit(alloc); } alloc.free(map); }, .extension => |ext| alloc.free(ext.bytes), else => {}, } } }; test { std.testing.refAllDecls(@This()); } test { const o: Object = .nil; _ = o; }