Exemplo n.º 1
0
        /// <summary>
        /// Extract a single element from the view
        /// </summary>
        /// <param name="buffer">A view with the encoded data</param>
        /// <param name="data">The data ArrayList to store the extracted data</param>
        /// <param name="format">The format of the data to be extracted</param>
        /// <returns>Return the view parameter</returns>
        static BufferView ReadElement(BufferView buffer, ArrayList data, Format.ElementsArray format)
        {
            for (int i = 0; i < format.Elements.Count; i++)
            {
                switch (format.Elements[i].ElementType)
                {
                case Format.Element.Type.ARRAY:
                    data.Add(ReadArray(buffer, (Format.ElementsArray)format.Elements[i]));
                    break;

                case Format.Element.Type.UINT:
                    data.Add(ReadUint(buffer));
                    break;

                case Format.Element.Type.INT:
                    data.Add(ReadInt(buffer));
                    break;

                case Format.Element.Type.FLOAT:
                    data.Add(ReadFloat(buffer));
                    break;

                case Format.Element.Type.TOKEN:
                    data.Add(ReadToken(buffer));
                    break;

                case Format.Element.Type.STRING:
                    data.Add(ReadString(buffer));
                    break;
                }
            }
            return(buffer);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Extract an array
        /// </summary>
        /// <param name="buffer">A view with the encoded data</param>
        /// <param name="format">A component of an inflated format object</param>
        /// <returns>Return the extracted data</returns>
        static ArrayList ReadArray(BufferView buffer, Format.ElementsArray format)
        {
            int length;

            // Get the number of elements
            length = (int)ReadUint(buffer);

            // Extract each element
            ArrayList array = new ArrayList();

            if (format.Elements.Count == 1)
            {
                for (int i = 0; i < length; i++)
                {
                    ReadElement(buffer, array, format);
                }
            }
            else
            {
                for (int i = 0; i < length; i++)
                {
                    ArrayList subArray = new ArrayList();
                    ReadElement(buffer, subArray, format);
                    array.Add(subArray);
                }
            }

            return(array);
        }