Пример #1
0
        internal static PipData Deserialize(PipReader reader)
        {
            Contract.Requires(reader != null);
            var              entriesStringId = reader.ReadPipDataId();
            PipDataEntry     headerEntry;
            PipDataEntryList entries;

            if (entriesStringId.IsValid)
            {
                headerEntry = PipDataEntry.Deserialize(reader);

                // Use the string table to get the raw bytes to back the entries
                entries = new PipDataEntryList(reader.StringTable.GetBytes(entriesStringId));
            }
            else
            {
                var count = reader.ReadInt32Compact();
                if (count == 0)
                {
                    return(Invalid);
                }

                headerEntry = PipDataEntry.Deserialize(reader);
                var entriesArray = new PipDataEntry[count];
                for (int i = 0; i < count; i++)
                {
                    entriesArray[i] = PipDataEntry.Deserialize(reader);
                }

                entries = PipDataEntryList.FromEntries(entriesArray);
            }

            Contract.Assume(headerEntry.EntryType == PipDataEntryType.NestedDataHeader);
            Contract.Assume(headerEntry.Escaping != PipDataFragmentEscaping.Invalid);
            return(new PipData(headerEntry, entries, entriesStringId));
        }