From 786d4b7c92aa1cab4c27b110902ed1175d6b277f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20CORTIER?= Date: Mon, 6 Mar 2023 14:33:30 -0500 Subject: [PATCH] Implement `is_human_readable` to return `false` Currently, [is_human_readable](https://docs.rs/serde/latest/serde/trait.Serializer.html#method.is_human_readable) is not manually implemented and thus returns `true` (default). As a consequence, types supporting a more compact binary representation are serialized inefficiently (typically into a string representation). This is a breaking change: previously serialized types supporting a compact representation will fail at deserialization with this commit. --- src/de.rs | 7 ++++++- src/ser.rs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/de.rs b/src/de.rs index 6c00b3b..50fd21d 100644 --- a/src/de.rs +++ b/src/de.rs @@ -42,7 +42,12 @@ struct Deserializer<'a> { } impl<'a, 'r> serde::de::Deserializer<'a> for &'r mut Deserializer<'a> { type Error = SerdeAsn1DerError; - + + #[inline] + fn is_human_readable(&self) -> bool { + false + } + fn deserialize_any>(self, visitor: V) -> Result { match self.object.tag() { Boolean::TAG => self.deserialize_bool(visitor), diff --git a/src/ser.rs b/src/ser.rs index 1d74ac3..c356551 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -145,7 +145,12 @@ impl<'a, 'r, S: Sink> serde::ser::Serializer for &'r mut Serializer<'a, S> { type SerializeMap = KeyValueWriter; type SerializeStruct = SequenceWriter<'a, 'r, S>; type SerializeStructVariant = KeyValueWriter; - + + #[inline] + fn is_human_readable(&self) -> bool { + false + } + fn serialize_bool(self, v: bool) -> Result { Ok(v.encode(&mut self.sink).propagate(e!("Failed to write boolean"))?) }