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

Consolidate unsafe byte conversions in valence_nbt #465

Merged
merged 3 commits into from
Aug 15, 2023
Merged

Conversation

rj00a
Copy link
Member

@rj00a rj00a commented Aug 15, 2023

Objective

When using valence_nbt, it's often necessary to convert to and from slices and vecs of i8 and u8. But this requires unsafe code if you want to avoid copying things.

Solution

Expose the following functions in valence_nbt:

  • u8_vec_into_i8_vec(vec: Vec<u8>) -> Vec<i8>
  • i8_vec_into_u8_vec(vec: Vec<i8>) -> Vec<u8>
  • u8_slice_as_i8_slice(slice: &[u8]) -> &[i8]
  • i8_slice_as_u8_slice(slice: &[i8]) -> &[u8]

We've also made use of these functions ourselves to reduce the total amount of unsafe code. Should also help in #263

@rj00a rj00a enabled auto-merge (squash) August 15, 2023 14:55
@rj00a rj00a merged commit d134832 into main Aug 15, 2023
13 checks passed
@rj00a rj00a deleted the nbt-byte-conv branch August 15, 2023 15:14
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.

1 participant