 
 }
 
+/// The `NSKeyedArchiverDelegate` protocol defines the optional methods implemented
+/// by delegates of `NSKeyedArchiver` objects.
 public protocol NSKeyedArchiverDelegate : class {
     
-    // Informs the delegate that the object is about to be encoded.  The delegate
-    // either returns this object or can return a different object to be encoded
-    // instead.  The delegate can also fiddle with the coder state.  If the delegate
-    // returns nil, nil is encoded.  This method is called after the original object
-    // may have replaced itself with replacementObject(for:).
-    // This method is not called for an object once a replacement mapping has been
-    // setup for that object (either explicitly, or because the object has previously
-    // been encoded).  This is also not called when nil is about to be encoded.
-    // This method is called whether or not the object is being encoded conditionally.
+    /// Informs the delegate that `object` is about to be encoded.
+    ///
+    /// This method is called after the original object may have replaced itself
+    /// with `replacementObject(for:)`.
+    ///
+    /// This method is called whether or not the object is being encoded conditionally.
+    ///
+    /// This method is not called for an object once a replacement mapping has been set up
+    /// for that object (either explicitly, or because the object has previously been encoded).
+    /// This method is also not called when `nil` is about to be encoded.
+    ///
+    /// - Parameters:
+    ///   - archiver:   The archiver that invoked the method.
+    ///   - object:     The object that is about to be encoded.
+    /// - Returns:      Either object or a different object to be encoded in its stead.
+    ///                 The delegate can also modify the coder state. If the delegate
+    ///                 returns `nil`, `nil` is encoded.
     func archiver(_ archiver: NSKeyedArchiver, willEncode object: Any) -> Any?
     
-    // Informs the delegate that the given object has been encoded.  The delegate
-    // might restore some state it had fiddled previously, or use this to keep
-    // track of the objects which are encoded.  The object may be nil.  Not called
-    // for conditional objects until they are really encoded (if ever).
+    /// Informs the delegate that a given object has been encoded.
+    ///
+    /// The delegate might restore some state it had modified previously,
+    /// or use this opportunity to keep track of the objects that are encoded.
+    ///
+    /// This method is not called for conditional objects until they are actually encoded (if ever).
+    ///
+    /// - Parameters:
+    ///   - archiver:   The archiver that invoked the method.
+    ///   - object:     The object that has been encoded.
     func archiver(_ archiver: NSKeyedArchiver, didEncode object: Any?)
     
-    // Informs the delegate that the newObject is being substituted for the
-    // object. This is also called when the delegate itself is doing/has done
-    // the substitution. The delegate may use this method if it is keeping track
-    // of the encoded or decoded objects.
+    /// Informs the delegate that one given object is being substituted for another given object.
+    ///
+    /// This method is called even when the delegate itself is doing, or has done,
+    /// the substitution. The delegate may use this method if it is keeping track
+    /// of the encoded or decoded objects.
+    ///
+    /// - Parameters:
+    ///   - archiver:   The archiver that invoked the method.
+    ///   - object:     The object being replaced in the archive.
+    ///   - newObject:  The object replacing `object` in the archive.
     func archiver(_ archiver: NSKeyedArchiver, willReplace object: Any?, withObject newObject: Any?)
     
-    // Notifies the delegate that encoding is about to finish.
+
+    /// Notifies the delegate that encoding is about to finish.
+    ///
+    /// - Parameter archiver: The archiver that invoked the method.
     func archiverWillFinish(_ archiver: NSKeyedArchiver)
     
-    // Notifies the delegate that encoding has finished.
+
+    /// Notifies the delegate that encoding has finished.
+    ///
+    /// - Parameter archiver: The archiver that invoked the method.
     func archiverDidFinish(_ archiver: NSKeyedArchiver)
 }

        encode(data._nsObject)
    }
    
    open override func encodeBytes(_ bytesp: UnsafePointer<UInt8>?, length lenv: Int, forKey key: String) {
        // this encodes the data inline
        let data = NSData(bytes: bytesp, length: lenv)

        NSNumber.self
]

/// `NSKeyedArchiver`, a concrete subclass of `NSCoder`, provides a way to encode objects
/// (and scalar values) into an architecture-independent format that can be stored in a file.
/// When you archive a set of objects, the class information and instance variables for each object
/// are written to the archive. `NSKeyedArchiver`’s companion class, `NSKeyedUnarchiver`,
/// decodes the data in an archive and creates a set of objects equivalent to the original set.
///
/// A keyed archive differs from a non-keyed archive in that all the objects and values
/// encoded into the archive are given names, or keys. When decoding a non-keyed archive,
/// values have to be decoded in the same order in which they were encoded.
/// When decoding a keyed archive, because values are requested by name, values can be decoded
/// out of sequence or not at all. Keyed archives, therefore, provide better support
/// for forward and backward compatibility.
/// 
/// The keys given to encoded values must be unique only within the scope of the current
/// object being encoded. A keyed archive is hierarchical, so the keys used by object A
/// to encode its instance variables do not conflict with the keys used by object B,
/// even if A and B are instances of the same class. Within a single object,
/// however, the keys used by a subclass can conflict with keys used in its superclasses.
///
/// An `NSKeyedArchiver` object can write the archive data to a file or to a
/// mutable-data object (an instance of `NSMutableData`) that you provide.
open class NSKeyedArchiver : NSCoder {

    struct ArchiverFlags : OptionSet {
        let rawValue : UInt
        
