allow serializeMap to work with optionals
Some checks failed
AWS-Zig Build / build-zig-amd64-host (push) Successful in 1m28s
aws-zig mach nominated build / build-zig-nominated-mach-latest (push) Successful in 1m28s
aws-zig nightly build / build-zig-nightly (push) Failing after 33s

This commit is contained in:
Emil Lerch 2024-08-26 16:01:21 -07:00
parent c056dbb0ff
commit f5663fd84d
Signed by: lobo
GPG Key ID: A7B62D657EF764F8

View File

@ -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 // options is a json.Options, but since we're using our hacked json.zig we don't want to
// specifically call this out // specifically call this out
pub fn serializeMap(map: anytype, key: []const u8, options: anytype, out_stream: anytype) !bool { 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; if (map.len == 0) return true;
// TODO: Map might be [][]struct{key, value} rather than []struct{key, value} // TODO: Map might be [][]struct{key, value} rather than []struct{key, value}
var child_options = options; var child_options = options;