SpongePowered / nbt

Named Binary Tag (NBT) library for Java based on Graham Edgecombe's JNBT library. NBT is a tag based binary format designed to carry large amounts of binary data with smaller amounts of additional data.
https://flow.github.io/nbt
MIT License
51 stars 33 forks source link

LITTLE_ENDIAN Floats and Doubles are read as BIG_ENDIAN #15

Open xcube16 opened 5 years ago

xcube16 commented 5 years ago

https://github.com/flow/nbt/blob/7a1b6d986e6fbd01862356d47827b8b357349a22/src/main/java/com/flowpowered/nbt/stream/EndianSwitchableInputStream.java#L100-L122

As you can see, readInt() and readLong() take care of the endian ness, but readFloat() and readDouble() also try to take care of flipping the bytes around! This causes LITTLE_ENDIAN Floats and Doubles to be read as BIG_ENDIAN.

    public float readFloat() throws IOException {
        return Float.intBitsToFloat(readInt());
    }

    public double readDouble() throws IOException {
        return Double.longBitsToDouble(readLong());
    }

That should fix it.

If someone could sneak that into there next PR that would be nice! ;) Fixed in PR #16