Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gen code without chrono to handle nullable logical-dates #75

Merged
merged 2 commits into from
Oct 7, 2024

Conversation

kebbestrom
Copy link

I use this tool to generate my Rust code from Avro schemas, but I want to use something other than Chrono dates. Instead, I would use the i64 version for my logical dates.

The code currently being generated for nullable dates needs to handle this correctly. It will incorrectly try serializing the Option<i64> using chrono::serde::ts_milliseconds_option.

Here is an example of generating the Avro schema logical_dates.avsc with chrono dates disabled:

/// Date type
#[derive(Debug, PartialEq, Eq, Clone, serde::Deserialize, serde::Serialize)]
pub struct DateLogicalType {
    pub birthday: i32,
    #[serde(with = "chrono::serde::ts_milliseconds_option")]
    #[serde(default = "default_datelogicaltype_meeting_time")]
    pub meeting_time: Option<i64>,
    #[serde(default = "default_datelogicaltype_release_datetime_micro")]
    pub release_datetime_micro: i64,
}

#[inline(always)]
fn default_datelogicaltype_meeting_time() -> Option<i64> { None }

#[inline(always)]
fn default_datelogicaltype_release_datetime_micro() -> i64 { 1570903062000000 }

@lerouxrgd lerouxrgd merged commit 7b78697 into lerouxrgd:master Oct 7, 2024
2 checks passed
@lerouxrgd
Copy link
Owner

Thanks for the fix !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants