Skip to content

Commit

Permalink
allow serializeMap to work with optionals
Browse files Browse the repository at this point in the history
  • Loading branch information
elerch committed Aug 26, 2024
1 parent c056dbb commit f5663fd
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions codegen/src/json.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ const std = @import("std");
// options is a json.Options, but since we're using our hacked json.zig we don't want to
// specifically call this out
pub fn serializeMap(map: anytype, key: []const u8, options: anytype, out_stream: anytype) !bool {
if (@typeInfo(@TypeOf(map)) == .Optional) {
if (map == null)
return true
else
return serializeMapInternal(map.?, key, options, out_stream);
}
return serializeMapInternal(map, key, options, out_stream);
}

fn serializeMapInternal(map: anytype, key: []const u8, options: anytype, out_stream: anytype) !bool {
if (map.len == 0) return true;
// TODO: Map might be [][]struct{key, value} rather than []struct{key, value}
var child_options = options;
Expand Down

0 comments on commit f5663fd

Please sign in to comment.