/// <summary> /// Reads a Gzip Compressed NbtBlob from stream. /// </summary> /// <exception cref="NBTException">Invalid Nbt</exception> public static NbtBlob ReadCompressedNbtBlob(this Stream stream) { using (var compress = new GZipStream(stream, CompressionMode.Decompress, true)) { var reader = new PrimitiveReader(compress); return(reader.ReadNbtBlob()); } }
public void TestNbtHelloWorldRead() { var helloWorld = new byte[] { 0x0a, 0x00, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x08, 0x00, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x09, 0x42, 0x61, 0x6e, 0x61, 0x6e, 0x72, 0x61, 0x6d, 0x61, 0x00 }; var stream = new MemoryStream(helloWorld); var reader = new PrimitiveReader(stream); var blob = reader.ReadNbtBlob(); Assert.Equal("hello world", blob.Name); Assert.Equal("Bananrama", ((Tag.String)blob.Root.Value["name"]).Value); }
public static ItemStack ReadItemStackProto(this PrimitiveReader reader) { var id = reader.ReadShort(); if (id == -1) { return(ItemStack.Empty); } return(new ItemStack() { Item = Item.GetFromId(id), Count = reader.ReadByte(), Damage = reader.ReadShort(), Nbt = reader.ReadNbtBlob() }); }