Beispiel #1
0
        internal static int[] ReadIntArray(Stream input)
        {
            int length       = TagInt.ReadInt(input);
            int bufferLength = length * 4;

            byte[] buffer = new byte[bufferLength];
            if (bufferLength != input.Read(buffer, 0, bufferLength))
            {
                throw new Exception();
            }

            int[] ints = new int[length];
            for (int i = 0; i < length; i++)
            {
                if (BitConverter.IsLittleEndian)
                {
                    BitHelper.SwapBytes(buffer, i * 4, 4);
                }

                ints[i] = BitConverter.ToInt32(buffer, i * 4);
            }

            buffer = null;

            return(ints);
        }
Beispiel #2
0
        internal static byte[] ReadByteArray(Stream input)
        {
            int length = TagInt.ReadInt(input);

            byte[] bytes = new byte[length];
            if (length != input.Read(bytes, 0, length))
            {
                throw new Exception();
            }

            return(bytes);
        }
Beispiel #3
0
        internal static List <AbstractTag> ReadTagList(Stream input)
        {
            TagType tagType = (TagType)TagByte.ReadByte(input);
            int     length  = TagInt.ReadInt(input);

            List <AbstractTag> tags = new List <AbstractTag>();

            for (int i = 0; i < length; i++)
            {
                AbstractTag tag = null;

                switch (tagType)
                {
                case TagType.Byte:
                    tag = TagByte.ReadUnnamedTagByte(input);
                    break;

                case TagType.ByteArray:
                    tag = TagByteArray.ReadUnnamedTagByteArray(input);
                    break;

                case TagType.Compound:
                    tag = TagCompound.ReadUnnamedTagCompound(input);
                    break;

                case TagType.Double:
                    tag = TagDouble.ReadUnnamedTagDouble(input);
                    break;

                case TagType.End:
                    tag = new TagEnd();
                    break;

                case TagType.Float:
                    tag = TagFloat.ReadUnnamedTagFloat(input);
                    break;

                case TagType.Int:
                    tag = TagInt.ReadUnnamedTagInt(input);
                    break;

                case TagType.IntArray:
                    tag = TagIntArray.ReadUnnamedTagIntArray(input);
                    break;

                case TagType.List:
                    tag = TagList.ReadUnnamedTagList(input);
                    break;

                case TagType.Long:
                    tag = TagLong.ReadUnnamedTagLong(input);
                    break;

                case TagType.Short:
                    tag = TagShort.ReadUnnamedTagShort(input);
                    break;

                case TagType.String:
                    tag = TagString.ReadUnnamedTagString(input);
                    break;

                default:
                    tag = null;
                    break;
                }

                if (tag != null)
                {
                    tags.Add(tag);
                }
            }

            return(tags);
        }