prost_uuid_doubleint/
lib.rs1use derive_more::{AsMut, AsRef, Constructor, Deref, DerefMut, From, Into};
2use prost::{
3 bytes::{Buf, BufMut},
4 encoding::{skip_field, uint64, DecodeContext, WireType},
5 DecodeError, Message,
6};
7use uuid::Uuid;
8const HIGH_TAG: u32 = 1;
9const LOW_TAG: u32 = 2;
10
11#[derive(
12 Clone,
13 Copy,
14 AsRef,
15 AsMut,
16 Deref,
17 DerefMut,
18 From,
19 Into,
20 Constructor,
21 Debug,
22 Default,
23 PartialEq,
24 Eq,
25 Hash,
26)]
27pub struct ProstUuid(Uuid);
28
29impl Message for ProstUuid {
30 fn encode_raw(&self, buf: &mut impl BufMut) {
31 let (high, low) = self.0.as_u64_pair();
32 uint64::encode(HIGH_TAG, &high, buf);
33 uint64::encode(LOW_TAG, &low, buf);
34 }
35
36 fn merge_field(
37 &mut self,
38 tag: u32,
39 wire_type: WireType,
40 buf: &mut impl Buf,
41 ctx: DecodeContext,
42 ) -> Result<(), DecodeError>
43 where
44 Self: Sized,
45 {
46 match tag {
47 HIGH_TAG => {
48 let (mut high, low) = self.0.as_u64_pair();
49 uint64::merge(wire_type, &mut high, buf, ctx)?;
50 self.0 = Uuid::from_u64_pair(high, low);
51 Ok(())
52 }
53 LOW_TAG => {
54 let (high, mut low) = self.0.as_u64_pair();
55 uint64::merge(wire_type, &mut low, buf, ctx)?;
56 self.0 = Uuid::from_u64_pair(high, low);
57 Ok(())
58 }
59 _ => skip_field(wire_type, tag, buf, ctx),
60 }
61 }
62
63 fn encoded_len(&self) -> usize {
64 let (high, low) = self.0.as_u64_pair();
65 uint64::encoded_len(HIGH_TAG, &high) + uint64::encoded_len(LOW_TAG, &low)
66 }
67
68 fn clear(&mut self) {
69 self.0 = Uuid::nil();
70 }
71}