예제 #1
0
파일: NbtList.cs 프로젝트: Kingwl/MineCase
            public NbtTag Deserialize(BinaryReader br, bool requireName)
            {
                string name = null;

                if (requireName)
                {
                    name = br.ReadTagString();
                }

                var elementType = br.ReadTagType();
                var count       = br.ReadInt32().ToggleEndian();

                if (count <= 0)
                {
                    return(new NbtList(elementType, name));
                }

                var elements = new NbtTag[count];

                for (var i = 0; i < count; ++i)
                {
                    elements[i] = NbtTagSerializer.DeserializeTag(br, elementType, false);
                }

                return(new NbtList(elements, name));
            }
예제 #2
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);
                }
            }
예제 #3
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);
            }
예제 #4
0
        public NbtCompound ReadAsNbtTag()
        {
            NbtCompound nbt;

            using (MemoryStream ms = new MemoryStream(_span.ToArray()))
            {
                using (var br = new BinaryReader(ms, Encoding.UTF8, false))
                {
                    nbt = NbtTagSerializer.DeserializeTag <NbtCompound>(br);
                }

                Advance((int)ms.Position);
            }

            return(nbt);
        }
예제 #5
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);
                }
            }
예제 #6
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);
            }
        }
예제 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NbtFile"/> class.<para />
        /// 从流中初始化 Nbt 数据
        /// </summary>
        /// <param name="stream">要从中初始化数据的流</param>
        /// <param name="leaveOpen">读取完成后保持流的打开状态</param>
        public NbtFile(Stream stream, bool leaveOpen = true)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

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

            Contract.EndContractBlock();

            using (var br = new BinaryReader(stream, Encoding.UTF8, leaveOpen))
            {
                RootTag = NbtTagSerializer.DeserializeTag <NbtCompound>(br);
            }
        }
예제 #8
0
파일: NbtFile.cs 프로젝트: Kingwl/MineCase
        /// <summary>
        /// Initializes a new instance of the <see cref="NbtFile"/> class.<para />
        /// 从流中初始化 Nbt 数据
        /// </summary>
        /// <param name="stream">要从中初始化数据的流</param>
        public NbtFile(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

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

            Contract.EndContractBlock();

            using (var br = new BinaryReader(stream))
            {
                _rootTag = NbtTagSerializer.DeserializeTag <NbtCompound>(br, false);
            }
        }
예제 #9
0
            public NbtTag Deserialize(BinaryReader br, bool requireName)
            {
                string name = null;

                if (requireName)
                {
                    name = br.ReadTagString();
                }

                var elements = new List <NbtTag>();

                while (true)
                {
                    var curElement = NbtTagSerializer.DeserializeTag(br);
                    if (curElement.TagType == NbtTagType.End)
                    {
                        break;
                    }

                    elements.Add(curElement);
                }

                return(new NbtCompound(elements, name));
            }
예제 #10
0
 public static void WriteAsNbtTag(this BinaryWriter bw, NbtCompound value)
 {
     NbtTagSerializer.SerializeTag(value, bw);
 }
예제 #11
0
 internal static void RegisterSerializer()
 {
     NbtTagSerializer.RegisterTag(NbtTagType.Byte, new Serializer());
 }
예제 #12
0
 static NbtShort()
 {
     NbtTagSerializer.RegisterTag(NbtTagType.Short, new Serializer());
 }
예제 #13
0
 static NbtEnd()
 {
     NbtTagSerializer.RegisterTag(NbtTagType.End, new Serializer());
 }
예제 #14
0
 static NbtDouble()
 {
     NbtTagSerializer.RegisterTag(NbtTagType.Double, new Serializer());
 }
예제 #15
0
파일: NbtList.cs 프로젝트: Kingwl/MineCase
 static NbtList()
 {
     NbtTagSerializer.RegisterTag(NbtTagType.List, new Serializer());
 }
예제 #16
0
 static NbtCompound()
 {
     NbtTagSerializer.RegisterTag(NbtTagType.Compound, new Serializer());
 }
예제 #17
0
파일: NbtLong.cs 프로젝트: Kingwl/MineCase
 static NbtLong()
 {
     NbtTagSerializer.RegisterTag(NbtTagType.Long, new Serializer());
 }
예제 #18
0
 static NbtByte()
 {
     NbtTagSerializer.RegisterTag(NbtTagType.Byte, new Serializer());
 }