/// <summary> /// Adds a dictionary to the internal object table. /// </summary> /// <param name="value">The value to add.</param> /// <returns>The index of the added value.</returns> private int AddDictionary(IDictionary value) { int index = objectTable.Count; var dict = new BinaryPlistDictionary(objectTable, value.Count); var item = new BinaryPlistItem(dict); item.IsDictionary = true; objectTable.Add(item); foreach (object key in value.Keys) { dict.KeyReference.Add(AddObject(key)); dict.ObjectReference.Add(AddObject(value[key])); objectRefCount += 2; } if (dict.KeyReference.Count < 15) { item.Marker.Add((byte)(0xD0 | (byte)dict.KeyReference.Count)); } else { item.Marker.Add(0xDF); AddIntegerCount(item.Marker, dict.KeyReference.Count); } objectTableSize += item.Size; return(index); }
/// <summary> /// Reads a dictionary value from the given reader, starting at the given index and of the given size. /// </summary> /// <param name="reader"> /// The <see cref="BinaryReader" /> to read the dictionary value from. /// </param> /// <param name="index">The index in the stream the dictionary value starts at.</param> /// <param name="size">The number of items in the dictionary.</param> /// <returns>A dictionary value.</returns> private BinaryPlistDictionary ReadDictionary(BinaryReader reader, long index, int size) { var dictionary = new BinaryPlistDictionary(objectTable, size); int skip = size * objectRefSize; for (int i = 0; i < size; i++) { dictionary.KeyReference.Add((int)ReadInteger(reader, index + (i * objectRefSize), objectRefSize)); dictionary.ObjectReference.Add((int)ReadInteger(reader, skip + index + (i * objectRefSize), objectRefSize)); } return(dictionary); }