/// <summary>Reads the nbt's content from the <see cref="Stream"/></summary> /// <param name="tag">The tag to read from the <see cref="Stream"/></param> /// <param name="Context">The context that provides a buffer, the stream and endianness of the NBT</param> public void ReadContent(ITag tag, SerializationContext Context) { Stream Reader = Context.Stream; Int32 Length; switch (tag.Type) { //Arrays case NBTTagType.ByteArray: Length = Context.ReadInt32(); tag.SetValue(Context.ReadBytes(Length)); return; case NBTTagType.IntArray: Length = Context.ReadInt32(); tag.SetValue(Context.ReadInt32Array(Length)); return; case NBTTagType.LongArray: Length = Context.ReadInt32(); tag.SetValue(Context.ReadInt64Array(Length)); return; //Values case NBTTagType.Byte: tag.SetValue((Byte)Context.Stream.ReadByte()); return; case NBTTagType.Short: tag.SetValue(Context.ReadInt16()); return; case NBTTagType.Int: tag.SetValue(Context.ReadInt32()); return; case NBTTagType.Long: tag.SetValue(Context.ReadInt64()); return; case NBTTagType.Double: tag.SetValue(Context.ReadDouble()); return; case NBTTagType.Float: tag.SetValue(Context.ReadFloat()); return; case NBTTagType.String: tag.SetValue(NBTReader.ReadString(Reader, Context.Endianness)); return; case NBTTagType.Unknown: case NBTTagType.End: default: return; } }
/// <summary>Reads the nbt's header from the <see cref="Stream"/></summary> /// <param name="tag">The tag to read from the <see cref="Stream"/></param> /// <param name="Context">The context to read from</param> public void ReadHeader(ITag tag, SerializationContext Context) { tag.Name = NBTReader.ReadString(Context); //Read subtype tag.SetInformation(NBTTagInformation.ListSubtype, (NBTTagType)Context.Stream.ReadByte()); //Read size tag.SetInformation(NBTTagInformation.ListSize, Context.ReadInt32()); }
/// <summary>Reads the nbt's content from the <see cref="Stream"/></summary> /// <param name="tag">The tag to read from the <see cref="Stream"/></param> /// <param name="Context">The context that provides a buffer, the stream and endianness of the NBT</param> public void ReadContent(ITag tag, SerializationContext Context) { ITag SubTag = NBTReader.Read(Context); while (SubTag != null) { tag.Add(SubTag); SubTag = NBTReader.Read(Context); } }
/// <summary>Reads the nbt's content from the <see cref="Stream"/></summary> /// <param name="tag">The tag to read from the <see cref="Stream"/></param> /// <param name="Context">The context to read from</param> public void ReadContent(ITag tag, SerializationContext Context) { ITag SubTag; Object O = tag.GetInformation(NBTTagInformation.ListSubtype); if (O == null) { throw new Exception("List returned no subtype"); } var SubTagType = (NBTTagType)O; ITagReader Reader = NBTReader.GetReader(SubTagType); if (Reader == null) { throw new Exception($"No reader for type: {SubTagType}"); } if (SubTagType == NBTTagType.List) { for (Int32 I = 0; I < tag.Count; I++) { SubTag = new NBTTagList(SubTagType); SubTag.SetInformation(NBTTagInformation.ListSubtype, (NBTTagType)Context.Stream.ReadByte()); SubTag.SetInformation(NBTTagInformation.ListSize, Context.ReadInt32()); Reader.ReadContent(SubTag, Context); tag[I] = SubTag; } } else { for (Int32 I = 0; I < tag.Count; I++) { SubTag = NBTTagFactory.Create(SubTagType); tag[I] = SubTag; Reader.ReadContent(SubTag, Context); } } }
/// <summary>Reads the nbt's header from the <see cref="Stream"/></summary> /// <param name="tag">The tag to read from the <see cref="Stream"/></param> /// <param name="Context">The context that provides a buffer, the stream and endianness of the NBT</param> public void ReadHeader(ITag tag, SerializationContext Context) { tag.Name = NBTReader.ReadString(Context); }
/// <summary>Reads the nbt's header from the <see cref="Stream"/></summary> /// <param name="tag">The tag to read from the <see cref="Stream"/></param> /// <param name="Context">The context that provides a buffer, the stream and endianness of the NBT</param> public void ReadHeader(ITag tag, SerializationContext Context) { tag.Name = NBTReader.ReadString(Context.Stream, Context.Endianness); }