-
Notifications
You must be signed in to change notification settings - Fork 48
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: support for borsh @ 1.5 #416
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems reasonable to me. I am not an expert in borsh, so while I've tried to review the logic I am not 100% sure it's correct. Can you leave a 1-2 paragraph comment here about relevant particulars of borsh serialization in case I need to maintain this code in the future :)
Of course! Borsh serializes integers in little-endian format. For For example, the test value uses limbs [1, 2, 3, 4], which should be:
I also just added lines in the test that call Let me know if I misunderstood how the limbs are put together and I can fix it. Thank you. For reference: https://borsh.io/ (see Integers section of Specialization). |
thank you. does borsh serialize fixed-sized integers as fixed-length bitstrings? i.e. is a u64 always exactly 8 bytes? My concern with the current implementation is that non-standard sized |
You're right. This was an oversight on my part and tried to be clever with iterating over the limbs. Maybe I should just do to_le_bytes and serialize that. I'll need to look into how to_le_bytes works under the hood for |
previous implementation was bugged
I couldn't find a better way than to use a macro to implement |
thanks, let me spend some time on this early next week and i'll see if i can figure out an elegant solution :) |
Would you mind checking out my branch here? If you think the implementation is correct, I can push it onto this branch and get this merged soon :) |
Motivation
Avoid having to implement a new type to handle
BorshSerialize
andBorshDeserialize
for ruint types.Solution
This PR implements
BorshSerialize
andBorshDeserialize
forUint
andBits
with basic tests.PR Checklist