コード例 #1
0
        public override object ParsePayload(Stream stream, INamedBinaryTag iTag)
        {
            TagCompound tag = iTag as TagCompound;

            while (true)
            {
                byte     b    = stream.ReadSingleByte();
                ETagType type = (ETagType)b;

                if (type == ETagType.End)
                {
                    break;
                }

                string          key   = ParseName(stream);
                INamedBinaryTag inner = type.MakeTag(key);

                TagParserBase parser = Parsers[type];
                parser.ParsePayload(stream, inner);

                tag.Set(key, inner);
            }

            return(tag.Values);
        }
コード例 #2
0
ファイル: ListTagParser.cs プロジェクト: einsteinsci/nbt-io
        public override object ParsePayload(Stream stream, INamedBinaryTag iTag)
        {
            TagList list = iTag as TagList;

            byte     generic_b = stream.ReadSingleByte();
            ETagType generic   = (ETagType)generic_b;

            list.GenericType = generic;

            //if (generic == ETagType.End)
            //{
            //	throw new Exception("TagList cannot consist End tags.");
            //}

            byte[] count_b = new byte[4];
            stream.Read(count_b, 0, 4);
            count_b = count_b.ReverseIfLittleEndian();
            int count = BitConverter.ToInt32(count_b, 0);

            TagParserBase parser = Parsers[generic];

            for (int i = 0; i < count; i++)
            {
                INamedBinaryTag tag = generic.MakeTag(null);
                parser.ParsePayload(stream, tag);
                list.Add(tag);
            }

            return(list.Children);
        }