// get the next byte array, prefixed by array length (signed int, 4 bytes) public static NbtByteArray ParseNbtByteArray(NbtByteReader reader, bool parseName = true) { NbtByteArray byteArray = new NbtByteArray(parseName ? ParseString(reader) : ""); int arrayLength = reader.ReadInt(); for (int i = 0; i < arrayLength; i++) { byteArray.Value.Add(reader.ReadSByte()); } return(byteArray); }
// get the next value prefixed by tag type (1 byte) and name length (unsigned short, 2 bytes) public static NbtTag ParseNextValueType(NbtByteReader reader) { TagType nextTagType = reader.ReadTagType(); switch (nextTagType) { case TagType.Byte: return(new NbtByte(ParseString(reader), reader.ReadSByte())); case TagType.Short: return(new NbtShort(ParseString(reader), reader.ReadShort())); case TagType.Int: return(new NbtInt(ParseString(reader), reader.ReadInt())); case TagType.Long: return(new NbtLong(ParseString(reader), reader.ReadLong())); case TagType.Float: return(new NbtFloat(ParseString(reader), reader.ReadFloat())); case TagType.Double: return(new NbtDouble(ParseString(reader), reader.ReadDouble())); case TagType.ByteArray: return(ParseNbtByteArray(reader)); case TagType.String: return(new NbtString(ParseString(reader), ParseString(reader))); case TagType.List: return(ParseNbtList(reader)); case TagType.Compound: return(ParseNbtCompound(reader)); case TagType.IntArray: return(ParseNbtIntArray(reader)); case TagType.LongArray: return(ParseNbtLongArray(reader)); default: throw new Exception("Should never get here."); } }