         
         let offsets = data.prefix(table_size).typed(as: UInt64.self)
         
-        let from = Int(UInt64(bigEndian: offsets[index]))
-        let to = Int(UInt64(bigEndian: offsets[index + 1]))
-        
-        guard to > from && data.count >= table_size + to else { return nil }
-        
-        return DataPack(decode: data.dropFirst(table_size).dropFirst(from).prefix(to - from))
-    }
-    
-    @inlinable
-    subscript(keyValuePairs index: Int) -> (String, DataPack)? {
-        
-        guard type == .dictionary else { return nil }
+        let startIndex = Int(UInt64(bigEndian: offsets[index]))
+        let endIndex = Int(UInt64(bigEndian: offsets[index + 1]))
+        
+        guard endIndex > startIndex && data.count >= table_size + endIndex else { return nil }
+        
+        return DataPack(decode: data.dropFirst(table_size).dropFirst(startIndex).prefix(endIndex - startIndex), xref: xref, stack: stack)
+    }
+}
+
+extension DataPack {
+    
+    @frozen
+    @usableFromInline
+    struct UndecodedKeyValuePairs: RandomAccessCollection {
+        
+        @usableFromInline
+        typealias Indices = Range<Int>
+        
+        @usableFromInline
+        typealias Index = Int
+        
+        @usableFromInline
+        let data: Data
+        
+        @usableFromInline
+        let xref: Data
+        
+        @usableFromInline
+        let stack: Set<Int>
+        
+        @inlinable
+        init(data: Data, xref: Data, stack: Set<Int>) {
+            self.data = data
+            self.xref = xref
+            self.stack = stack
+        }
+    }
+}
+
+extension DataPack.UndecodedKeyValuePairs {
+    
+    @inlinable
+    var startIndex: Int {
+        return 0
+    }
+    
+    @inlinable
+    var endIndex: Int {
+        return Int(UInt64(bigEndian: data.prefix(8).load(as: UInt64.self)))
+    }
+    
+    @inlinable
+    subscript(index: Int) -> (String, DataPack)? {
         
         let count = self.count
         let table_size = (count + 1) << 4

            
            data.append(0x73)
            data.append(utf8: value)
            
        case let .signed(value):
            

extension DataPack {
    
    @inlinable
    public var type: DataPackType {
        switch self.base {
        case .null: return .null
        case .boolean: return .boolean
        case .string: return .string
        case .signed: return .signed
        case .unsigned: return .unsigned
        case .number: return .number
        case .binary: return .binary
        case .uuid: return .uuid
        case .array, .undecoded_array: return .array
        case .dictionary: return .dictionary
        }
    }
    
    @inlinable
    public var isNil: Bool {
        return type == .null
    }
    
    @inlinable
    public var isBool: Bool {
        return type == .boolean
    }
    
    @inlinable
    public var isString: Bool {
        return type == .string
    }
    
    @inlinable
    public var isArray: Bool {
        return type == .array
    }
    
    @inlinable
    public var isObject: Bool {
        return type == .dictionary
    }
    
    @inlinable
    public var isSigned: Bool {
        return type == .signed
    }
    
    @inlinable
    public var isUnsigned: Bool {
        return type == .unsigned
    }
    
    @inlinable
    public var isNumber: Bool {
        return type == .number
    }
    
    @inlinable
    public var isNumeric: Bool {
        switch type {
        case .signed: return true
        case .unsigned: return true
        case .number: return true
        default: return false
        }
    }
    
    @inlinable
    public var isBinary: Bool {
        return type == .binary
    }
    
    @inlinable
    public var isUUID: Bool {
        return type == .uuid
    }
}

extension DataPack {
    
    @inlinable
    public var boolValue: Bool? {
        switch self.base {
        case let .boolean(value): return value
        default: return nil
        }
    }
    
    @inlinable
    public var int8Value: Int8? {
        switch self.base {
        case let .signed(value): return Int8(exactly: value)
        case let .unsigned(value): return Int8(exactly: value)
        case let .number(value): return Int8(exactly: value)
        default: return nil
        }
    }
    
    @inlinable
    public var uint8Value: UInt8? {
        switch self.base {
        case let .signed(value): return UInt8(exactly: value)
        case let .unsigned(value): return UInt8(exactly: value)
        case let .number(value): return UInt8(exactly: value)
        default: return nil
        }
    }
    
    @inlinable
    public var int16Value: Int16? {
        switch self.base {
        case let .signed(value): return Int16(exactly: value)
        case let .unsigned(value): return Int16(exactly: value)
        case let .number(value): return Int16(exactly: value)
        default: return nil
        }
    }
    
    @inlinable
    public var uint16Value: UInt16? {
        switch self.base {
        case let .signed(value): return UInt16(exactly: value)
        case let .unsigned(value): return UInt16(exactly: value)
        case let .number(value): return UInt16(exactly: value)
        default: return nil
        }
    }
    
    @inlinable
    public var int32Value: Int32? {
        switch self.base {
        case let .signed(value): return Int32(exactly: value)
        case let .unsigned(value): return Int32(exactly: value)
        case let .number(value): return Int32(exactly: value)
        default: return nil
        }
    }
    
    @inlinable
    public var uint32Value: UInt32? {
        switch self.base {
        case let .signed(value): return UInt32(exactly: value)
        case let .unsigned(value): return UInt32(exactly: value)
        case let .number(value): return UInt32(exactly: value)
        default: return nil
        }
    }
    
    @inlinable
    public var int64Value: Int64? {
        switch self.base {
        case let .signed(value): return value
        case let .unsigned(value): return Int64(exactly: value)
        case let .number(value): return Int64(exactly: value)
        default: return nil
        }
    }
    
    @inlinable
    public var uint64Value: UInt64? {
        switch self.base {
        case let .signed(value): return UInt64(exactly: value)
        case let .unsigned(value): return value
        case let .number(value): return UInt64(exactly: value)
        default: return nil
        }
    }
    
    @inlinable
    public var intValue: Int? {
        switch self.base {
        case let .signed(value): return Int(exactly: value)
        case let .unsigned(value): return Int(exactly: value)
        case let .number(value): return Int(exactly: value)
        default: return nil
        }
    }
    
    @inlinable
    public var uintValue: UInt? {
        switch self.base {
        case let .signed(value): return UInt(exactly: value)
        case let .unsigned(value): return UInt(exactly: value)
        case let .number(value): return UInt(exactly: value)
        default: return nil
        }
    }
    
    @inlinable
    public var floatValue: Float? {
        switch self.base {
        case let .signed(value): return Float(exactly: value)
        case let .unsigned(value): return Float(exactly: value)
        case let .number(value): return Float(value)
        default: return nil
        }
    }
    
    @inlinable
    public var doubleValue: Double? {
        switch self.base {
        case let .signed(value): return Double(exactly: value)
        case let .unsigned(value): return Double(exactly: value)
        case let .number(value): return value
        default: return nil
        }
    }
    
    @inlinable
    public var decimalValue: Decimal? {
        switch self.base {
        case let .signed(value): return Decimal(value)
        case let .unsigned(value): return Decimal(value)
        case let .number(value): return Int64(exactly: value).map { Decimal($0) }
        default: return nil
        }
    }
    
    @inlinable
    public var string: String? {
        switch self.base {
        case let .string(value): return value
        default: return nil
        }
    }
    
    @inlinable
    public var binary: Data? {
        switch self.base {
        case let .binary(value): return value
        default: return nil
        }
    }
    
    @inlinable
    public var uuid: UUID? {
        switch self.base {
        case let .uuid(value): return value
        default: return nil
        }
    }
    
    @inlinable
    public var array: [DataPack]? {
        switch self.base {
        case let .array(value): return value
        case let .undecoded_array(value): return Array(value)
        default: return nil
        }
    }
    
    @inlinable
    public var dictionary: [String: DataPack]? {
        switch self.base {
        case let .dictionary(value): return value
        default: return nil
        }
    }
}

