Skip to content

Consolidate unsafe byte conversions in valence_nbt#465

Merged
rj00a merged 3 commits into
mainfrom
nbt-byte-conv
Aug 15, 2023
Merged

Consolidate unsafe byte conversions in valence_nbt#465
rj00a merged 3 commits into
mainfrom
nbt-byte-conv

Conversation

@rj00a

@rj00a rj00a commented Aug 15, 2023

Copy link
Copy Markdown
Member

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
@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