whir/transcript/
codecs.rs1use static_assertions::assert_impl_all;
2use zerocopy::{FromBytes, IntoBytes, KnownLayout};
3
4use super::{Codec, Decoding, Encoding, NargDeserialize, VerificationResult};
5
6pub struct Empty;
8
9impl<T> Encoding<[T]> for Empty {
10 fn encode(&self) -> impl AsRef<[T]> {
11 []
12 }
13}
14
15impl<T> Decoding<[T]> for Empty {
16 type Repr = [T; 0];
17
18 fn decode(_buf: Self::Repr) -> Self {
19 Self
20 }
21}
22
23impl NargDeserialize for Empty {
24 fn deserialize_from_narg(_buf: &mut &[u8]) -> VerificationResult<Self> {
25 Ok(Self)
26 }
27}
28
29assert_impl_all!(Empty: Codec);
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, FromBytes, KnownLayout, IntoBytes)]
33#[repr(transparent)]
34pub struct U64(pub u64);
35
36impl Encoding<[u8]> for U64 {
37 fn encode(&self) -> impl AsRef<[u8]> {
38 self.0.to_le_bytes()
39 }
40}
41
42impl Decoding<[u8]> for U64 {
43 type Repr = [u8; 8];
44
45 fn decode(buf: Self::Repr) -> Self {
46 Self(u64::from_le_bytes(buf))
47 }
48}
49
50impl NargDeserialize for U64 {
51 fn deserialize_from_narg(buf: &mut &[u8]) -> VerificationResult<Self> {
52 NargDeserialize::deserialize_from_narg(buf)
53 .map(u64::from_le_bytes)
54 .map(Self)
55 }
56}
57
58assert_impl_all!(U64: Codec);