Пример #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
        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);
        }
Пример #3
0
        public override void WritePayload(Stream stream, INamedBinaryTag iTag)
        {
            TagList list    = iTag as TagList;
            byte    generic = (byte)list.GenericType;

            stream.WriteByte(generic);

            byte[] data = BitConverter.GetBytes(list.Count);
            data = data.ReverseIfLittleEndian();
            stream.Write(data, 0, 4);

            foreach (INamedBinaryTag tag in list)
            {
                TagParserBase parser = Parsers[tag.TagType];
                parser.WritePayload(stream, tag);
            }
        }
Пример #4
0
        public override void WritePayload(Stream stream, INamedBinaryTag iTag)
        {
            TagCompound tag = iTag as TagCompound;

            foreach (KeyValuePair <string, INamedBinaryTag> kvp in tag.Values)
            {
                if (kvp.Key != kvp.Value.Name)
                {
                    throw new InvalidDataException(string.Format(
                                                       "Dictionary name ({0}) does not match tag name ({1})!", kvp.Key, kvp.Value.Name));
                }

                TagParserBase parser = Parsers[kvp.Value.TagType];
                parser.WriteFullTag(stream, kvp.Value);
            }

            WriteTag(stream, new TagEnd());
        }