internal int Read(BinaryObject currentObject, byte[] bytes, int index) { int offset = 0; byte type = bytes[index]; offset += 1; int keyLength = BitConverter.ToInt32(bytes, index + offset); offset += 4; string key = Encoding.UTF8.GetString(bytes, index + offset, keyLength); offset += keyLength; int valLength = BitConverter.ToInt32(bytes, index + offset); offset += 4 + valLength; BinaryObject obj = null; if (type == (byte)BinaryObject.BinaryTypes.Object) { obj = new BinaryObject(key); int innerIndex = index + offset - valLength; while (innerIndex < index + offset) innerIndex += Read(obj, bytes, innerIndex); } else { if (type != (byte)BinaryFormatter.BinaryObject.BinaryTypes.ByteArray) { string val = Encoding.UTF8.GetString(bytes, index + offset - valLength, valLength); obj = new BinaryObject(key, val); } else { byte[] val = new byte[valLength]; Array.Copy(bytes, index + offset - valLength, val, 0, val.Length); obj = new BinaryObject(key, val); } } if (currentObject == null) _items.Add(obj); else currentObject.Add(obj); return offset; }