Ejemplo n.º 1
0
        public NvList(Stream s)
        {
            var r = new NvListBinaryReader(s, Encoding.ASCII);

            NV_ENCODE encoding = (NV_ENCODE)r.ReadByte();

            if (encoding != NV_ENCODE.XDR)
            {
                throw new Exception("Is not encoding in XDR.");
            }
            byte endian = r.ReadByte();

            if (endian != 1)
            {
                throw new Exception("Incorrect endianness.");
            }
            short reserved = r.ReadInt16(); //reserved fields

            Load(r);
        }
Ejemplo n.º 2
0
        private void Load(NvListBinaryReader r)
        {
            int version = r.ReadInt32();

            if (version != NV_VERSION)
            {
                throw new NotSupportedException("Unsupport NVList version!");
            }

            NvFlags flags = (NvFlags)r.ReadInt32();

            while (true)
            {
                int encodedSize = r.ReadInt32();
                int decodedSize = r.ReadInt32();

                if (encodedSize == 0 && decodedSize == 0)
                {
                    break;
                }

                string     name             = r.ReadString();
                NvDataType type             = (NvDataType)r.ReadInt32();
                int        numberOfElements = r.ReadInt32();

                object val;
                switch (type)
                {
                case NvDataType.STRING:
                    val = r.ReadString();
                    break;

                case NvDataType.UINT64:
                    val = r.ReadUInt64();
                    break;

                case NvDataType.NVLIST:
                    val = new NvList(r);
                    break;

                case NvDataType.NVLIST_ARRAY:
                    var array = new NvList[numberOfElements];
                    for (int i = 0; i < numberOfElements; i++)
                    {
                        array[i] = new NvList(r);
                    }
                    val = array;
                    break;

                case NvDataType.BOOLEAN:
                    val = true;
                    break;

                case NvDataType.BOOLEAN_VALUE:
                    val = r.ReadInt32() != 0;
                    break;

                default:
                    throw new NotImplementedException();
                }
                mVals.Add(name, val);
            }
        }
Ejemplo n.º 3
0
 private NvList(NvListBinaryReader r)
 {
     Load(r);
 }