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

enable encoding/decoding of variable-length input data (e.g. BoundedVec) #26

Open
grjte opened this issue Nov 7, 2024 · 0 comments · May be fixed by #27
Open

enable encoding/decoding of variable-length input data (e.g. BoundedVec) #26

grjte opened this issue Nov 7, 2024 · 0 comments · May be fixed by #27
Labels
enhancement New feature or request

Comments

@grjte
Copy link
Contributor

grjte commented Nov 7, 2024

Problem

When using BoundedVec, it's not possible to pass the data to this encoder or decoder, because the storage vector is padded and we don't have a way to specify the that only the first len bytes should be encoded/decoded. We need function variants that either accept types of BoundedVec instead of fixed-length arrays or that accept both an array and a specification of the length of the meaningful data inside that array.

Happy Case

Example:

fn do_something(encoded_id: [u8; ENCODED_LEN], raw_id: BoundedVec<u8, ID_MAX_LEN>) {
    let encoded_raw_id: [u8; ENCODED_LEN] = noir_base64::BASE64_URL_ENCODER.encode_var(raw_id.storage(), raw_id.len());
    assert(encoded_id === encoded_raw_id);
}

Workaround

Not that I can think of. We would need to be able to create a fixed-length array of the correct length from a BoundedVec, which isn't possible because we can't declare a fixed-length array to have a length that's not known at compile time

Workaround Description

No response

Additional Context

No response

Project Impact

Nice-to-have

Blocker Context

No response

Would you like to submit a PR for this Issue?

Yes

Support Needs

No response

@grjte grjte added the enhancement New feature or request label Nov 7, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Nov 7, 2024
@grjte grjte linked a pull request Nov 7, 2024 that will close this issue
2 tasks
@grjte grjte changed the title make the lib more ergonomic for variable-length input data (e.g. BoundedVec) enable encoding/decoding of variable-length input data (e.g. BoundedVec) Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 📋 Backlog
Development

Successfully merging a pull request may close this issue.

1 participant