support for timestamp as f128 (more)

f128 is not really the correct data type long term. More information on the exact details are
https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html and
https://smithy.io/2.0/spec/protocol-traits.html\#timestampformat-trait

But...it will hold all our values and parses correctly, so we can use it for now
This commit is contained in:
Emil Lerch 2025-02-05 13:21:53 -08:00
parent 4313f8585b
commit 96e2b7bbc1
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
3 changed files with 13 additions and 1 deletions

View File

@ -716,7 +716,7 @@ fn generateTypeFor(shape_id: []const u8, writer: anytype, state: GenerationState
// The serializer will have to deal with the idea we might be an array // The serializer will have to deal with the idea we might be an array
return try generateTypeFor(shape.set.member_target, writer, state, true); return try generateTypeFor(shape.set.member_target, writer, state, true);
}, },
.timestamp => |s| try generateSimpleTypeFor(s, "i64", writer), .timestamp => |s| try generateSimpleTypeFor(s, "f128", writer),
.blob => |s| try generateSimpleTypeFor(s, "[]const u8", writer), .blob => |s| try generateSimpleTypeFor(s, "[]const u8", writer),
.boolean => |s| try generateSimpleTypeFor(s, "bool", writer), .boolean => |s| try generateSimpleTypeFor(s, "bool", writer),
.double => |s| try generateSimpleTypeFor(s, "f64", writer), .double => |s| try generateSimpleTypeFor(s, "f64", writer),

View File

@ -783,6 +783,12 @@ fn parseInt(comptime T: type, val: []const u8) !T {
return e; return e;
}; };
} }
if (T == f128) {
return @as(f128, date.parseEnglishToTimestamp(val)) catch |e| {
log.err("Error coercing date string '{s}' to timestamp value", .{val});
return e;
};
}
log.err("Error parsing string '{s}' to integer", .{val}); log.err("Error parsing string '{s}' to integer", .{val});
return rc; return rc;
} }

View File

@ -105,6 +105,12 @@ fn parseInternal(comptime T: type, element: *xml.Element, options: ParseOptions)
}, },
.Float, .ComptimeFloat => { .Float, .ComptimeFloat => {
return std.fmt.parseFloat(T, element.children.items[0].CharData) catch |e| { return std.fmt.parseFloat(T, element.children.items[0].CharData) catch |e| {
if (element.children.items[0].CharData[element.children.items[0].CharData.len - 1] == 'Z') {
// We have an iso8601 in an integer field (we think)
// Try to coerce this into our type
const timestamp = try date.parseIso8601ToTimestamp(element.children.items[0].CharData);
return @floatFromInt(timestamp);
}
if (log_parse_traces) { if (log_parse_traces) {
std.log.err( std.log.err(
"Could not parse '{s}' as float in element '{s}': {any}", "Could not parse '{s}' as float in element '{s}': {any}",