ollis commented on issue #40:
URL: https://github.com/apache/avro-rs/issues/40#issuecomment-2458999449
I can get it to work as expected by changing the implementation of Decimal
to use a custom implementation of Serialize and Deserialize instead of relying
on derive:
```rust
#[derive(Debug, Clone, Eq)]
pub struct Decimal {
value: BigInt,
len: usize,
}
impl Serialize for Decimal {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer
{
let bytes = &*self.to_vec().unwrap();
serializer.serialize_bytes(bytes)
}
}
impl<'de> Deserialize<'de> for Decimal {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
struct DecimalVisitor;
impl<'de> serde::de::Visitor<'de> for DecimalVisitor {
type Value = Decimal;
fn expecting(&self, formatter: &mut std::fmt::Formatter) ->
std::fmt::Result {
formatter.write_str("a byte slice or seq of bytes")
}
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
Ok(Decimal::from(v))
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value,
A::Error>
where
A: SeqAccess<'de>,
{
let mut bytes = Vec::new();
while let Some(value) = seq.next_element::<u8>()? {
bytes.push(value);
}
Ok(Decimal::from(bytes))
}
}
deserializer.deserialize_bytes(DecimalVisitor)
}
}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]