/// <summary>Writes the nbt's content to the <see cref="Stream"/></summary> /// <param name="tag">The tag to write to the <see cref="Stream"/></param> /// <param name="Context">The context to write to</param> public void WriteContent(NBTTagList tag, SerializationContext Context) { NBTTagType SubTagType = tag.SubType; ITagWriter Writer = NBTWriter.GetWriter(SubTagType); if (Writer == null) { throw new Exception($"Cannot find writer for {SubTagType}"); } Int32 Count = tag.Count; if (SubTagType == NBTTagType.List) { /*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;*/ Context.Stream.WriteByte((Byte)tag.GetInformation(NBTTagInformation.ListSubtype)); Context.WriteInt32((Int32)tag.GetInformation(NBTTagInformation.ListSize)); } else { for (Int32 I = 0; I < Count; I++) { Writer.WriteContent(tag[I], Context); } } }
/// <summary>Writes the nbt's content to the <see cref="Stream"/></summary> /// <param name="tag">The tag to write to the <see cref="Stream"/></param> /// <param name="Context">The context that provides a buffer, the stream and endianness of the NBT</param> public void WriteContent(ITag tag, SerializationContext Context) { switch (tag.Type) { //Arrays case NBTTagType.ByteArray: Byte[] Bytes = tag.GetValue <Byte[]>(); Context.WriteBytes(Bytes); return; case NBTTagType.IntArray: Int32[] Ints = tag.GetValue <Int32[]>(); Context.WriteInt32Array(Ints); return; case NBTTagType.LongArray: Int64[] Longs = tag.GetValue <Int64[]>(); Context.WriteInt64Array(Longs); return; //Values case NBTTagType.Byte: Context.Stream.WriteByte(tag.GetValue <Byte>()); return; case NBTTagType.Short: Context.WriteInt16(tag.GetValue <Int16>()); return; case NBTTagType.Int: Context.WriteInt32(tag.GetValue <Int32>()); return; case NBTTagType.Long: Context.WriteInt64(tag.GetValue <Int64>()); return; case NBTTagType.Double: Context.WriteDouble(tag.GetValue <Double>()); return; case NBTTagType.Float: Context.WriteFloat(tag.GetValue <Single>()); return; case NBTTagType.String: NBTWriter.WriteString(Context.Stream, tag.GetValue <String>(), Context.Endianness); return; case NBTTagType.End: case NBTTagType.Unknown: default: return; } }
/// <summary>Writes the nbt's header to the <see cref="Stream"/></summary> /// <param name="tag">The tag to write to the <see cref="Stream"/></param> /// <param name="Context">The context to write to</param> public void WriteHeader(NBTTagList tag, SerializationContext Context) { Context.Stream.WriteByte((Byte)tag.Type); NBTWriter.WriteString(Context, tag.Name); Context.Stream.WriteByte((Byte)tag.SubType); Context.WriteInt32((Int32)tag.Count); }
/// <summary>Writes the nbt's header to the <see cref="Stream"/></summary> /// <param name="tag">The tag to write to the <see cref="Stream"/></param> /// <param name="Context">The context to write to</param> public void WriteHeader(ITag tag, SerializationContext Context) { Context.Stream.WriteByte((Byte)tag.Type); NBTWriter.WriteString(Context, tag.Name); Context.Stream.WriteByte((Byte)tag.GetInformation(NBTTagInformation.ListSubtype)); Context.WriteInt32((Int32)tag.GetInformation(NBTTagInformation.ListSize)); }
/// <summary>Writes the nbt's content to the <see cref="Stream"/></summary> /// <param name="tag">The tag to write to the <see cref="Stream"/></param> /// <param name="Context">The context to write to</param> public void WriteContent(ITag tag, SerializationContext Context) { Int32 Count = tag.Count; for (Int32 I = 0; I < Count; I++) { NBTWriter.Write(tag[I], Context); } Context.Stream.WriteByte((Byte)NBTTagType.End); }
/// <summary>Writes the nbt's content to the <see cref="Stream"/></summary> /// <param name="tag">The tag to write to the <see cref="Stream"/></param> /// <param name="Context">The context to write to</param> public void WriteContent(ITag tag, SerializationContext Context) { Object O = tag.GetInformation(NBTTagInformation.ListSubtype); if (O == null) { throw new Exception("Cannot read list sub type"); } var SubTagType = (NBTTagType)O; ITagWriter Writer = NBTWriter.GetWriter(SubTagType); if (Writer == null) { throw new Exception($"Cannot find writer for {SubTagType}"); } Int32 Count = tag.Count; if (SubTagType == NBTTagType.List) { for (Int32 I = 0; I < Count; I++) { ITag Item = tag[I]; Context.Stream.WriteByte((Byte)Item.GetInformation(NBTTagInformation.ListSubtype)); Context.WriteInt32((Int32)Item.GetInformation(NBTTagInformation.ListSize)); Writer.WriteContent(Item, Context); } } else { for (Int32 I = 0; I < Count; I++) { Writer.WriteContent(tag[I], Context); } } }
/// <summary>Writes the nbt's header to the <see cref="Stream"/></summary> /// <param name="tag">The tag to write to the <see cref="Stream"/></param> /// <param name="Context">The context that provides a buffer, the stream and endianness of the NBT</param> public void WriteHeader(ITag tag, SerializationContext Context) { Context.Stream.WriteByte((Byte)tag.Type); NBTWriter.WriteString(Context, tag.Name); }