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

feat: allow to access ByteArray fields #6023

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Th0rgal
Copy link

@Th0rgal Th0rgal commented Jul 15, 2024

This makes ByteArray fields accessible outside of the crate.

A ByteArray is stored in memory at two locations: one storage slot receives its length, while other slots store the multiple elements (data + pending_word).

I use ByteArray to store Strings. In my use case, most of the time the stored String would fit in a single felt and my users end up paying twice the price. I would like to impl an alternative storage optimized trait which only stores the data and pending_word and retrieves the String size by iterating until it finds an empty string. To do so efficiently I would need to be able to read the content of the struct. I could also add the alternative Store trait to a pr if you think that could be useful.


This change is Reviewable

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @Th0rgal)

a discussion (no related file):
This cannot be approved - as it breaks encapsulation (which would break any attempts for general future optimizations).

You may consider allowing for a conversion into felt252 - so you'd easily find and convert into short strings.
Also - just having an enum Short: felt252 | Long: ByteArray would probably meet most of your basic demands.

in general - how do you expect to save your strings in the storage?
do note that having objects with varying size is not actually ok (if you where planning on saving the str continusly).


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants