PistonDevelopers / hematite_nbt

A full-featured Rust crate for working with Minecraft's Named Binary Tag (NBT) file format, including Serde support.
MIT License
99 stars 37 forks source link

Feature/allow quick exit #69

Open CoreyShupe opened 2 years ago

CoreyShupe commented 2 years ago

In the minecraft net source code there is a "quick exit" during 0x00 reads for base NBT objects.

    private static Tag readUnnamedTag(DataInput dataInput, int n, NbtAccounter nbtAccounter) throws IOException {
        byte by = dataInput.readByte();
        if (by == 0) {
            return EndTag.INSTANCE;
        }
        StringTag.skipString(dataInput);
        try {
            return TagTypes.getType(by).load(dataInput, n, nbtAccounter);
        // omitted
    }

Here we see that when the tag is 0x00 it won't read a header - and instead exit early with a "blank object", we should replicate this behavior when we have an object with nothing to serialize. This is especially helpful for "empty" nbt tags.