Skip to content

Commit

Permalink
Merge pull request #51 from earthstar-project/encoding-relations
Browse files Browse the repository at this point in the history
Encoding relations API
  • Loading branch information
sgwilym authored Oct 23, 2024
2 parents 569c3fe + 7ea01ff commit 5b0a780
Show file tree
Hide file tree
Showing 58 changed files with 1,478 additions and 551 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ the repo's issues, milestones, and projects.
protocol.
- [meadowcap-js](https://github.com/earthstar-project/meadowcap-js) - TypeScript
implementation of Meadowcap

## Fuzz tests

This repository has many fuzz tests. To use `cargo fuzz` commands, you must first make `fuzz` the working directory so that the nightly compiler (on which cargo-fuzz relies) is used for compiling the tests.

```
cd fuzz
cargo fuzz run <test_name_here>
```

There is also a command for running all the fuzz tests sequentially:

```
cd fuzz
./run_all.sh -- -max_total_time=<number_of_seconds>
```

---

Expand Down
16 changes: 9 additions & 7 deletions data-model/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,18 @@ mod encoding {
S: SubspaceId + Decodable,
PD: PayloadDigest + Decodable,
{
async fn decode<Prod>(producer: &mut Prod) -> Result<Self, DecodeError<Prod::Error>>
async fn decode_canonical<Prod>(
producer: &mut Prod,
) -> Result<Self, DecodeError<Prod::Error>>
where
Prod: BulkProducer<Item = u8>,
{
let namespace_id = N::decode(producer).await?;
let subspace_id = S::decode(producer).await?;
let path = Path::<MCL, MCC, MPL>::decode(producer).await?;
let timestamp = U64BE::decode(producer).await?.into();
let payload_length = U64BE::decode(producer).await?.into();
let payload_digest = PD::decode(producer).await?;
let namespace_id = N::decode_canonical(producer).await?;
let subspace_id = S::decode_canonical(producer).await?;
let path = Path::<MCL, MCC, MPL>::decode_canonical(producer).await?;
let timestamp = U64BE::decode_canonical(producer).await?.into();
let payload_length = U64BE::decode_canonical(producer).await?.into();
let payload_digest = PD::decode_canonical(producer).await?;

Ok(Entry {
namespace_id,
Expand Down
11 changes: 8 additions & 3 deletions data-model/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,8 @@ mod encoding {
use ufotofu::local_nb::{BulkConsumer, BulkProducer};

use willow_encoding::DecodeError;
#[syncify_replace(use willow_encoding::sync::{Decodable, Encodable};)]
use willow_encoding::{Decodable, Encodable};
#[syncify_replace(use willow_encoding::sync::{Decodable, Encodable, RelationDecodable};)]
use willow_encoding::{Decodable, Encodable, RelationDecodable};

#[syncify_replace(use willow_encoding::sync::{decode_max_power, encode_max_power};)]
use willow_encoding::{decode_max_power, encode_max_power};
Expand All @@ -818,7 +818,7 @@ mod encoding {
}

impl<const MCL: usize, const MCC: usize, const MPL: usize> Decodable for Path<MCL, MCC, MPL> {
async fn decode<P>(producer: &mut P) -> Result<Self, DecodeError<P::Error>>
async fn decode_canonical<P>(producer: &mut P) -> Result<Self, DecodeError<P::Error>>
where
P: BulkProducer<Item = u8>,
{
Expand Down Expand Up @@ -855,6 +855,11 @@ mod encoding {
Ok(unsafe { buf.to_path(component_count) })
}
}

impl<const MCL: usize, const MCC: usize, const MPL: usize> RelationDecodable
for Path<MCL, MCC, MPL>
{
}
}

#[cfg(feature = "dev")]
Expand Down
Loading

0 comments on commit 5b0a780

Please sign in to comment.