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

derive MaxSize and Size method on the type #45

Open
dshulyak opened this issue Feb 28, 2023 · 0 comments
Open

derive MaxSize and Size method on the type #45

dshulyak opened this issue Feb 28, 2023 · 0 comments

Comments

@dshulyak
Copy link
Collaborator

MaxSize method should estimate the maximum possible size of the struct that needs to be decoded taking into account limits (such as max for the collections). Any value that overflows such MaxSize for the type must be discarded with an error.

Size method is an optimization for Encode. Without Size consumer is forced to allocate memory multiple times for a single encode operation, instead it should be possible to use the following code.

encoder := scale.NewEncoder(bytes.NewBuffer(make([]byte, typed.Size()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant