/// <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) { var index = _objectTable.Count; var dict = new BinaryPlistDictionary(_objectTable, value.Count); var item = new BinaryPlistItem(dict) { IsDictionary = true }; _objectTable.Add(item); foreach (var 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); var skip = size * _objectRefSize; for (var 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); }