Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding and decoding #3

Closed
AljoschaMeyer opened this issue Jun 10, 2024 · 1 comment
Closed

Encoding and decoding #3

AljoschaMeyer opened this issue Jun 10, 2024 · 1 comment

Comments

@AljoschaMeyer
Copy link
Contributor

// Encoding functions should have the following form:

pub fn encode_usize<Con: BulkConsumer<Item = u8>>(value: &usize, consumer: &mut Con) -> Result<(), Con::Error> {
    unimplemented!()
}

// To implement those, you'll need some helper functions for working with ufotofu. For example, you'll probably want the following:

pub fn consume_all<Item, Con: BulkConsumer<Item=Item>>(values: &Item[], consumer: &mut Con) -> Result<(), Con::Error> {
    unimplemented!()
}

// And, of course, there'll be nb_local versons of all of these as well (with their own helper functions, too):

pub async fn nb_local_encode_usize<Con: nb_local::BulkConsumer<Item = u8>>(value: &usize, consumer: &mut Con) -> Result<(), Con::Error> {
    unimplemented!()
}

// Note that these designs assume that encoding is infallible, which is not necessarily true in the greater rust ecosystem (for example, a poisoned mutex cannot be encoded with serde). I prefer the design of "every instance of a type is valid" and "every valid value can be encoded", hence no need for encoding errors.

// For decoding, things can obviously go wrong. Either because the data source errors, or because the data source produces garbage.
pub enum DecodeError<ProducerError> {
    ProducerErr(ProducerError),
    GarbageInput,
}

// Decoding functions should have the following form:

pub fn decode_usize<Pro: BulkProducer<Item = u8>>(producer: &mut Pro) -> Result<u8, DecodeError<Pro::Error>> {
    unimplemented!()
}

// And async:

pub async fn nb_local_decode_usize<Pro: nb_local::BulkProducer<Item = u8>>(producer: &mut Pro) -> Result<u8, DecodeError<Pro::Error>> {
    unimplemented!()
}

General encoding/decoding utilities should live in some (the?) ufotofu create.

@mycognosist
Copy link
Contributor

Are you suggesting that consume_all() and local_nb_consume_all() live in ufotofu and all the other methods are implemented in Willow?

@sgwilym sgwilym closed this as completed Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

3 participants