예제 #1
0
파일: NbtList.cs 프로젝트: Kingwl/MineCase
            public void Serialize(NbtTag tag, BinaryWriter bw)
            {
                var nbtList = (NbtList)tag;

                if (nbtList.Name != null)
                {
                    bw.WriteTagValue(nbtList.Name);
                }

                foreach (var elem in nbtList._childTags)
                {
                    NbtTagSerializer.SerializeTag(elem, bw, false);
                }
            }
예제 #2
0
            public void Serialize(NbtTag tag, BinaryWriter bw, bool requireName)
            {
                var nbtCompound = (NbtCompound)tag;

                if (requireName)
                {
                    bw.WriteTagValue(nbtCompound.Name);
                }

                foreach (var elem in nbtCompound._childTags)
                {
                    NbtTagSerializer.SerializeTag(elem.Value, bw);
                }

                NbtTagSerializer.SerializeTag(new NbtEnd(), bw);
            }
예제 #3
0
            public void Serialize(NbtTag tag, BinaryWriter bw, bool requireName)
            {
                var nbtList = (NbtList)tag;

                if (requireName)
                {
                    bw.WriteTagValue(nbtList.Name);
                }

                bw.WriteTagValue(nbtList.ElementType);
                bw.Write(nbtList.Count.ToggleEndian());

                foreach (var elem in nbtList._childTags)
                {
                    NbtTagSerializer.SerializeTag(elem, bw, false, false);
                }
            }
예제 #4
0
        /// <summary>
        /// 将内容写入流中
        /// </summary>
        /// <param name="stream">要写入到的流</param>
        /// <param name="leaveOpen">写入完成后保持流的打开状态</param>
        public void WriteTo(Stream stream, bool leaveOpen = true)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (!stream.CanWrite)
            {
                throw new ArgumentException("流不可写", nameof(stream));
            }

            Contract.EndContractBlock();

            using (var bw = new BinaryWriter(stream, Encoding.UTF8, leaveOpen))
            {
                NbtTagSerializer.SerializeTag(RootTag, bw);
            }
        }
예제 #5
0
 public static void WriteAsNbtTag(this BinaryWriter bw, NbtCompound value)
 {
     NbtTagSerializer.SerializeTag(value, bw);
 }