1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use crate::NullValue;

impl From<()> for NullValue {
    fn from(_: ()) -> Self {
        Self::NullValue
    }
}

impl serde::Serialize for NullValue {
    fn serialize<S>(&self, ser: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        ().serialize(ser)
    }
}

impl<'de> serde::Deserialize<'de> for NullValue {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        deserializer.deserialize_unit(NullValueVisitor)
    }
}

struct NullValueVisitor;

impl<'de> serde::de::Visitor<'de> for NullValueVisitor {
    type Value = NullValue;

    fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        formatter.write_str("google.protobuf.NullValue")
    }

    fn visit_unit<E>(self) -> Result<Self::Value, E>
    where
        E: serde::de::Error,
    {
        Ok(NullValue::NullValue)
    }
}