From dc36e1341e876e7c251ffa08a6bfdd552c0d451f Mon Sep 17 00:00:00 2001 From: Piotr Majkrzak Date: Sun, 1 Sep 2024 17:44:44 +0200 Subject: [PATCH] Use u64 serialization of Snowflake for non human readable serializers --- src/model/id.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/model/id.rs b/src/model/id.rs index f3bbf82b27b..502b28101ed 100644 --- a/src/model/id.rs +++ b/src/model/id.rs @@ -343,12 +343,20 @@ mod snowflake { use serde::{Deserializer, Serializer}; pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result { - deserializer.deserialize_any(SnowflakeVisitor) + if deserializer.is_human_readable() { + deserializer.deserialize_any(SnowflakeVisitor) + } else { + deserializer.deserialize_u64(SnowflakeVisitor) + } } #[allow(clippy::trivially_copy_pass_by_ref)] pub fn serialize(id: &NonZeroU64, serializer: S) -> Result { - serializer.collect_str(&id.get()) + if serializer.is_human_readable() { + serializer.collect_str(&id.get()) + } else { + serializer.serialize_u64(id.get()) + } } struct SnowflakeVisitor;