-
Notifications
You must be signed in to change notification settings - Fork 16
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
Replace original bedrockrs_nbt with mirai-nbt #48
Replace original bedrockrs_nbt with mirai-nbt #48
Conversation
project can now compile
Seems like the modifications to the paletted_storage crate weren't included in this PR? Edit: fixed now |
I do think that you could even seperate the nbt library into its own repository. NBTs are used quite often... hence why a standalone library would be helpful. |
Also.. how would one handle serializing a given blob of NBT data with a different endianess, I quite loved our // IIRC it looked about like that...
bedrockrs_nbt::serialize::<NbtLittleEndianNetwork>(&nbt) |
With my lib your example would look like bedrockrs_nbt::to_var_bytes(&nbt) Each version also has a function that is suffixed with let mut ser = bedrockrs_nbt::Serializer::new(&mut buffer);
ser.serialize::<_, BigEndian>(&nbt).unwrap(); I guess I should probably expose a new function that wraps this, allowing you to do it like this: bedrockrs_nbt::to_bytes::<BigEndian>(&nbt).unwrap();
bedrockrs_nbt::to_bytes_in::<BigEndian>(&mut writer, &nbt).unwrap(); to match your original NBT lib. I think I might close this PR and move the NBT library to a new repository (should I call it bedrockrs_nbt?) Then I'll create a new PR that ports bedrockrs to it. I think if I were to continue inside of this PR it would get quite messy. |
Calling it Also I think that the way you are doing it with extra functions is completely fine, it quite reminds me of bedrockrs_nbt::to_bytes::<BigEndian>(&nbt).unwrap();
bedrockrs_nbt::to_bytes_in::<BigEndian>(&mut writer, &nbt).unwrap(); Up to you 🦐 |
Closing this in favour of #49 |
This is quite a big PR but luckily most of it is a direct copy from the original Mirai code. I've made several changes to the original version from Mirai:
anyhow
crate have been replaced with a newNbtError
type.BinaryRead
andBinaryWrite
traits that this crate relies on have been copy-pasted straight into theread.rs
andwrite.rs
files respectively. The use ofanyhow
here has been replaced with a newStreamError
type. Depending on what we end up doing this code should probably be moved to thebedrockrs_shared
crate or replaced with the existing binary read/write implementation. Additionally some Mirai-specific types such asVector
andBlockPosition
have been removed.Documentation for the NBT crate can be found at https://teampathfinders.github.io/mirai/mirai_nbt/index.html (or in the code of course). Although the new error type is not documented here. The
BinaryRead
andBinaryWrite
traits are documented at https://teampathfinders.github.io/mirai/mirai_util/index.html.Some code has not properly been ported yet such as the NBT palette deserialization in the
paletted_storage
crate. I still need to look into how I can use yourCursor
method with my NBT lib. I made sure the project compiles but will wait until we decide on what to do with the world format library before making more changes.Another small issue I found is that
ProtoCodecError
implements clone, requiringNbtError
to also implement it. InStreamError
I store the original error types for errors such asUtf8Error
andio::Error
, the latter does not implement clone though so I instead opted to convert it to a string. It is probably useful to keep the IO error so any idea what we should do with this?