Skip to content

Commit

Permalink
Repackage data-model::encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
sgwilym committed Aug 6, 2024
1 parent 4c7c9fe commit 0634ea1
Show file tree
Hide file tree
Showing 28 changed files with 81 additions and 90 deletions.
4 changes: 2 additions & 2 deletions data-model/src/encoding/compact_width.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ pub mod encoding {

use crate::encoding::unsigned_int::{U16BE, U32BE, U64BE, U8BE};

#[syncify_replace(use crate::encoding::parameters_sync::{Decodable, };)]
use crate::encoding::parameters::Decodable;
#[syncify_replace(use crate::encoding::sync::{Decodable};)]
use crate::encoding::Decodable;

/// Encode a `u64` integer as a `compact_width(value)`-byte big-endian integer, and consume that with a [`BulkConsumer`].
pub async fn encode_compact_width_be<Consumer: BulkConsumer<Item = u8>>(
Expand Down
42 changes: 27 additions & 15 deletions data-model/src/encoding/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
pub mod bytes;
pub mod compact_width;
/*
mod bytes;
mod compact_width;
mod error;
mod max_power;
mod traits_sync;
mod unsigned_int;

pub use bytes::encoding::produce_byte;
pub use bytes::is_bitflagged;

pub use compact_width::encoding::*;
pub use compact_width::CompactWidth;

pub use error::*;
*/
pub mod error;
pub mod parameters;
pub mod parameters_sync;
pub mod relativity;
// mod relativity;

mod traits;
pub use traits::*;

mod relativity;

pub(crate) mod shared_buffers;
pub mod unsigned_int;

pub mod max_power;
pub mod max_power_sync {
use super::max_power;
pub use max_power::encoding_sync::*;
pub use max_power::max_power;
pub use unsigned_int::*;

pub use max_power::{decode_max_power, encode_max_power, max_power};

pub mod sync {
pub use super::bytes::encoding_sync::produce_byte;
pub use super::compact_width::encoding_sync::*;
pub use super::max_power::encoding_sync::*;
pub use super::traits_sync::*;
}
6 changes: 3 additions & 3 deletions data-model/src/encoding/relativity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ pub(super) mod encoding {
#[syncify_replace(use ufotofu::sync::{BulkConsumer, BulkProducer};)]
use ufotofu::local_nb::{BulkConsumer, BulkProducer};

#[syncify_replace(use crate::encoding::parameters_sync::{Encodable, Decodable, RelativeDecodable, RelativeEncodable};)]
use crate::encoding::parameters::{Decodable, Encodable, RelativeDecodable, RelativeEncodable};
#[syncify_replace(use crate::encoding::sync::{Encodable, Decodable, RelativeDecodable, RelativeEncodable};)]
use crate::encoding::{Decodable, Encodable, RelativeDecodable, RelativeEncodable};

#[syncify_replace(use crate::encoding::max_power_sync::{decode_max_power, encode_max_power};)]
#[syncify_replace(use crate::encoding::sync::{decode_max_power, encode_max_power};)]
use crate::encoding::max_power::{decode_max_power, encode_max_power};

#[syncify_replace(use crate::encoding::compact_width::encoding_sync::{ decode_compact_width_be, encode_compact_width_be};)]
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions data-model/src/encoding/unsigned_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ mod encoding {
#[syncify_replace(use ufotofu::sync::{BulkConsumer, BulkProducer};)]
use ufotofu::local_nb::{BulkConsumer, BulkProducer};

#[syncify_replace(use crate::encoding::parameters_sync::{Decodable, Encodable};)]
use crate::encoding::parameters::{Decodable, Encodable};
#[syncify_replace(use crate::encoding::sync::{Decodable, Encodable};)]
use crate::encoding::{Decodable, Encodable};

impl Encodable for U8BE {
async fn encode<Consumer>(&self, consumer: &mut Consumer) -> Result<(), Consumer::Error>
Expand Down
6 changes: 3 additions & 3 deletions data-model/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use arbitrary::size_hint::and_all;
use arbitrary::Arbitrary;

use crate::{
encoding::{error::DecodeError, unsigned_int::U64BE},
encoding::{DecodeError, U64BE},
parameters::{IsAuthorisedWrite, NamespaceId, PayloadDigest, SubspaceId},
path::Path,
};
Expand Down Expand Up @@ -121,8 +121,8 @@ mod encoding {
#[syncify_replace(use ufotofu::sync::{BulkConsumer, BulkProducer};)]
use ufotofu::local_nb::{BulkConsumer, BulkProducer};

#[syncify_replace(use crate::encoding::parameters_sync::{Decodable, Encodable};)]
use crate::encoding::parameters::{Decodable, Encodable};
#[syncify_replace(use crate::encoding::sync::{Decodable, Encodable};)]
use crate::encoding::{Decodable, Encodable};

impl<const MCL: usize, const MCC: usize, const MPL: usize, N, S, PD> Encodable
for Entry<MCL, MCC, MPL, N, S, PD>
Expand Down
10 changes: 5 additions & 5 deletions data-model/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,16 +787,16 @@ use syncify::syncify_replace;
mod encoding {
use super::*;

use crate::encoding::{error::DecodeError, shared_buffers::ScratchSpacePathDecoding};
use crate::encoding::{shared_buffers::ScratchSpacePathDecoding, DecodeError};

#[syncify_replace(use ufotofu::sync::{BulkConsumer, BulkProducer};)]
use ufotofu::local_nb::{BulkConsumer, BulkProducer};

#[syncify_replace(use crate::encoding::parameters_sync::{Decodable, Encodable};)]
use crate::encoding::parameters::{Decodable, Encodable};
#[syncify_replace(use crate::encoding::sync::{Decodable, Encodable};)]
use crate::encoding::{Decodable, Encodable};

#[syncify_replace(use crate::encoding::max_power_sync::{decode_max_power, encode_max_power};)]
use crate::encoding::max_power::{decode_max_power, encode_max_power};
#[syncify_replace(use crate::encoding::sync::{decode_max_power, encode_max_power};)]
use crate::encoding::{decode_max_power, encode_max_power};

impl<const MCL: usize, const MCC: usize, const MPL: usize> Encodable for Path<MCL, MCC, MPL> {
async fn encode<C>(&self, consumer: &mut C) -> Result<(), C::Error>
Expand Down
5 changes: 1 addition & 4 deletions earthstar/src/cinn25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use arbitrary::{
};
use either::Either;
use ufotofu::local_nb::{BulkConsumer, BulkProducer};
use willow_data_model::encoding::{
error::DecodeError,
parameters::{Decodable, Encodable},
};
use willow_data_model::encoding::{Decodable, DecodeError, Encodable};

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Shortname<const MIN_LENGTH: usize, const MAX_LENGTH: usize>(pub Vec<u8>);
Expand Down
5 changes: 1 addition & 4 deletions earthstar/src/identity_id.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use arbitrary::Arbitrary;
use ufotofu::local_nb::{BulkConsumer, BulkProducer};
use willow_data_model::{
encoding::{
error::DecodeError,
parameters::{Decodable, Encodable},
},
encoding::{Decodable, DecodeError, Encodable},
SubspaceId,
};

Expand Down
5 changes: 1 addition & 4 deletions earthstar/src/namespace_id.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use arbitrary::Arbitrary;
use ufotofu::local_nb::{BulkConsumer, BulkProducer};
use willow_data_model::{
encoding::{
error::DecodeError,
parameters::{Decodable, Encodable},
},
encoding::{Decodable, DecodeError, Encodable},
NamespaceId,
};

Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/mc_is_authorised_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use libfuzzer_sys::fuzz_target;
use meadowcap::{AccessMode, McAuthorisationToken};
use signature::Signer;
use ufotofu::sync::consumer::IntoVec;
use willow_data_model::encoding::parameters_sync::Encodable;
use willow_data_model::encoding::sync::Encodable;
use willow_data_model::Entry;
use willow_data_model::IsAuthorisedWrite;
use willow_data_model_fuzz::{
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/u16be_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use libfuzzer_sys::fuzz_target;
use ufotofu::local_nb::consumer::TestConsumer;
use willow_data_model::encoding::unsigned_int::U16BE;
use willow_data_model::encoding::U16BE;
use willow_data_model_fuzz::encode::encoding_roundtrip;

fuzz_target!(|data: (u16, TestConsumer<u8, u16, ()>)| {
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/u16be_encoding_random.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![no_main]

use libfuzzer_sys::fuzz_target;
use willow_data_model::encoding::unsigned_int::U16BE;
use willow_data_model::encoding::U16BE;
use willow_data_model_fuzz::encode::encoding_random;

fuzz_target!(|data: &[u8]| {
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/u32be_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use libfuzzer_sys::fuzz_target;
use ufotofu::local_nb::consumer::TestConsumer;
use willow_data_model::encoding::unsigned_int::U32BE;
use willow_data_model::encoding::U32BE;
use willow_data_model_fuzz::encode::encoding_roundtrip;

fuzz_target!(|data: (u32, TestConsumer<u8, u16, ()>)| {
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/u32be_encoding_random.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![no_main]

use libfuzzer_sys::fuzz_target;
use willow_data_model::encoding::unsigned_int::U32BE;
use willow_data_model::encoding::U32BE;
use willow_data_model_fuzz::encode::encoding_random;

fuzz_target!(|data: &[u8]| {
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/u64be_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use libfuzzer_sys::fuzz_target;
use ufotofu::local_nb::consumer::TestConsumer;
use willow_data_model::encoding::unsigned_int::U64BE;
use willow_data_model::encoding::U64BE;
use willow_data_model_fuzz::encode::encoding_roundtrip;

fuzz_target!(|data: (u64, TestConsumer<u8, u16, ()>)| {
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/u64be_encoding_random.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![no_main]

use libfuzzer_sys::fuzz_target;
use willow_data_model::encoding::unsigned_int::U64BE;
use willow_data_model::encoding::U64BE;
use willow_data_model_fuzz::encode::encoding_random;

fuzz_target!(|data: &[u8]| {
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/u8be_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use libfuzzer_sys::fuzz_target;
use ufotofu::local_nb::consumer::TestConsumer;
use willow_data_model::encoding::unsigned_int::U8BE;
use willow_data_model::encoding::U8BE;
use willow_data_model_fuzz::encode::encoding_roundtrip;

fuzz_target!(|data: (u8, TestConsumer<u8, u16, ()>)| {
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/u8be_encoding_random.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![no_main]

use libfuzzer_sys::fuzz_target;
use willow_data_model::encoding::unsigned_int::U8BE;
use willow_data_model::encoding::U8BE;
use willow_data_model_fuzz::encode::encoding_random;

fuzz_target!(|data: &[u8]| {
Expand Down
3 changes: 1 addition & 2 deletions fuzz/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use ufotofu::{
};

use willow_data_model::encoding::{
error::DecodeError,
parameters::{Decodable, Encodable, RelativeDecodable, RelativeEncodable},
DecodeError, {Decodable, Encodable, RelativeDecodable, RelativeEncodable},
};

pub async fn encoding_roundtrip<T, C>(item: T, consumer: &mut TestConsumer<u8, u16, ()>)
Expand Down
5 changes: 2 additions & 3 deletions fuzz/src/placeholder_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use arbitrary::Arbitrary;
use ufotofu::local_nb::{BulkConsumer, BulkProducer};
use ufotofu::sync::{BulkConsumer as BulkConsumerSync, BulkProducer as BulkProducerSync};
use willow_data_model::encoding::{
error::DecodeError,
parameters::{Decodable, Encodable},
parameters_sync::{Decodable as DecodableSync, Encodable as EncodableSync},
sync::{Decodable as DecodableSync, Encodable as EncodableSync},
Decodable, DecodeError, Encodable,
};
use willow_data_model::PayloadDigest;

Expand Down
10 changes: 5 additions & 5 deletions fuzz/src/silly_sigs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ pub mod encoding {
#[syncify_replace(use ufotofu::sync::{BulkConsumer, BulkProducer};)]
use ufotofu::local_nb::{BulkConsumer, BulkProducer};

use willow_data_model::encoding::error::DecodeError;
#[syncify_replace(use willow_data_model::encoding::parameters_sync::{Encodable, Decodable};)]
use willow_data_model::encoding::parameters::{Decodable, Encodable};
use willow_data_model::encoding::DecodeError;
#[syncify_replace(use willow_data_model::encoding::sync::{Encodable, Decodable};)]
use willow_data_model::encoding::{Decodable, Encodable};

#[syncify_replace(use willow_data_model::encoding::bytes::encoding_sync::produce_byte;)]
use willow_data_model::encoding::bytes::encoding::produce_byte;
#[syncify_replace(use willow_data_model::encoding::sync::produce_byte;)]
use willow_data_model::encoding::produce_byte;

impl Encodable for SillyPublicKey {
async fn encode<Consumer>(&self, consumer: &mut Consumer) -> Result<(), Consumer::Error>
Expand Down
2 changes: 1 addition & 1 deletion meadowcap/src/communal_capability.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use signature::{Signer, Verifier};
use ufotofu::{sync::consumer::IntoVec, sync::Consumer};
use willow_data_model::{
encoding::parameters_sync::{Encodable, RelativeEncodable},
encoding::sync::{Encodable, RelativeEncodable},
grouping::Area,
NamespaceId, SubspaceId,
};
Expand Down
3 changes: 1 addition & 2 deletions meadowcap/src/mc_authorisation_token.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use signature::Verifier;
use ufotofu::sync::consumer::IntoVec;
use willow_data_model::{
encoding::parameters_sync::Encodable, Entry, IsAuthorisedWrite, NamespaceId, PayloadDigest,
SubspaceId,
encoding::sync::Encodable, Entry, IsAuthorisedWrite, NamespaceId, PayloadDigest, SubspaceId,
};

use crate::{mc_capability::McCapability, AccessMode, IsCommunal};
Expand Down
22 changes: 8 additions & 14 deletions meadowcap/src/mc_capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use either::Either;
use signature::{Error as SignatureError, Signer, Verifier};
use ufotofu::sync::consumer::IntoVec;
use willow_data_model::{
encoding::parameters_sync::Encodable, grouping::Area, Entry, NamespaceId, PayloadDigest,
SubspaceId,
encoding::sync::Encodable, grouping::Area, Entry, NamespaceId, PayloadDigest, SubspaceId,
};

use crate::{
Expand Down Expand Up @@ -293,25 +292,20 @@ pub(super) mod encoding {
#[syncify_replace(use ufotofu::sync::{BulkConsumer, BulkProducer};)]
use ufotofu::local_nb::{BulkConsumer, BulkProducer};

#[syncify_replace(use willow_data_model::encoding::parameters_sync::{Encodable, Decodable, RelativeDecodable, RelativeEncodable};)]
use willow_data_model::encoding::parameters::{
Decodable, Encodable, RelativeDecodable, RelativeEncodable,
};
#[syncify_replace(use willow_data_model::encoding::sync::{Encodable, Decodable, RelativeDecodable, RelativeEncodable};)]
use willow_data_model::encoding::{Decodable, Encodable, RelativeDecodable, RelativeEncodable};

use willow_data_model::encoding::{
bytes::is_bitflagged, compact_width::CompactWidth, error::DecodeError,
parameters_sync::Encodable as EncodableSync,
is_bitflagged, sync::Encodable as EncodableSync, CompactWidth, DecodeError,
};

#[syncify_replace(use willow_data_model::encoding::bytes::encoding_sync::produce_byte;)]
use willow_data_model::encoding::bytes::encoding::produce_byte;
#[syncify_replace(use willow_data_model::encoding::sync::produce_byte;)]
use willow_data_model::encoding::produce_byte;

#[syncify_replace(
use willow_data_model::encoding::compact_width::encoding_sync::{encode_compact_width_be, decode_compact_width_be};
use willow_data_model::encoding::sync::{encode_compact_width_be, decode_compact_width_be};
)]
use willow_data_model::encoding::compact_width::encoding::{
decode_compact_width_be, encode_compact_width_be,
};
use willow_data_model::encoding::{decode_compact_width_be, encode_compact_width_be};

impl<
const MCL: usize,
Expand Down
19 changes: 8 additions & 11 deletions meadowcap/src/mc_subspace_capability.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use signature::{Error as SignatureError, Signer, Verifier};
use ufotofu::sync::{consumer::IntoVec, Consumer};
use willow_data_model::encoding::parameters_sync::Encodable;
use willow_data_model::encoding::sync::Encodable;
use willow_data_model::NamespaceId;
use willow_data_model::SubspaceId;

Expand Down Expand Up @@ -233,23 +233,20 @@ pub(super) mod encoding {
#[syncify_replace(use ufotofu::sync::{BulkConsumer, BulkProducer};)]
use ufotofu::local_nb::{BulkConsumer, BulkProducer};

#[syncify_replace(use willow_data_model::encoding::parameters_sync::{Encodable, Decodable};)]
use willow_data_model::encoding::parameters::{Decodable, Encodable};
#[syncify_replace(use willow_data_model::encoding::sync::{Encodable, Decodable};)]
use willow_data_model::encoding::{Decodable, Encodable};

use willow_data_model::encoding::{
compact_width::CompactWidth, error::DecodeError,
parameters_sync::Encodable as EncodableSync,
sync::Encodable as EncodableSync, CompactWidth, DecodeError,
};

#[syncify_replace(use willow_data_model::encoding::bytes::encoding_sync::produce_byte;)]
use willow_data_model::encoding::bytes::encoding::produce_byte;
#[syncify_replace(use willow_data_model::encoding::sync::produce_byte;)]
use willow_data_model::encoding::produce_byte;

#[syncify_replace(
use willow_data_model::encoding::compact_width::encoding_sync::{encode_compact_width_be, decode_compact_width_be};
use willow_data_model::encoding::sync::{encode_compact_width_be, decode_compact_width_be};
)]
use willow_data_model::encoding::compact_width::encoding::{
decode_compact_width_be, encode_compact_width_be,
};
use willow_data_model::encoding::{decode_compact_width_be, encode_compact_width_be};

impl<NamespacePublicKey, NamespaceSignature, UserPublicKey, UserSignature> Encodable
for McSubspaceCapability<
Expand Down
2 changes: 1 addition & 1 deletion meadowcap/src/owned_capability.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use signature::{Error as SignatureError, Signer, Verifier};
use ufotofu::{sync::consumer::IntoVec, sync::Consumer};
use willow_data_model::{
encoding::parameters_sync::{Encodable, RelativeEncodable},
encoding::sync::{Encodable, RelativeEncodable},
grouping::{Area, AreaSubspace},
NamespaceId, Path, SubspaceId,
};
Expand Down

0 comments on commit 0634ea1

Please sign in to comment.