Skip to content

Commit

Permalink
Fingerprint postcard sizes (unicode-org#5428)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian authored Aug 21, 2024
1 parent c3e1fed commit 24d8c81
Show file tree
Hide file tree
Showing 15 changed files with 124,235 additions and 124,197 deletions.
33 changes: 33 additions & 0 deletions provider/core/src/export/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,39 @@ impl core::hash::Hash for DataPayload<ExportMarker> {
}
}

impl DataPayload<ExportMarker> {
/// Calculates a payload hash and the postcard size
pub fn hash_and_postcard_size<H: core::hash::Hasher>(&self, state: &mut H) -> usize {
use postcard::ser_flavors::Flavor;

struct HashFlavor<'a, H>(&'a mut H, usize);
impl<'a, H: core::hash::Hasher> Flavor for HashFlavor<'a, H> {
type Output = usize;

fn try_push(&mut self, data: u8) -> postcard::Result<()> {
self.0.write_u8(data);
self.1 += 1;
Ok(())
}

fn finalize(self) -> postcard::Result<Self::Output> {
Ok(self.1)
}
}

let mut serializer = postcard::Serializer {
output: HashFlavor(state, 0),
};

let _infallible = self
.get()
.payload
.serialize_yoke(&mut <dyn erased_serde::Serializer>::erase(&mut serializer));

serializer.output.1
}
}

/// Marker type for [`ExportBox`].
#[allow(clippy::exhaustive_structs)] // marker type
#[derive(Debug)]
Expand Down
476 changes: 238 additions & 238 deletions provider/data/calendar/fingerprints.csv

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions provider/data/casemap/fingerprints.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
props/casemap@1, <singleton>, 22515B, ff76a17649a34363
props/casemap_unfold@1, <singleton>, 976B, 85d63de2fdea5a3d
props/casemap@1, <singleton>, 22515B, 22428B, ff76a17649a34363
props/casemap_unfold@1, <singleton>, 976B, 932B, 85d63de2fdea5a3d
Loading

0 comments on commit 24d8c81

Please sign in to comment.