             146, 1, UInt8(inputCurrentLevel.count),
         ] + inputCurrentLevel
         let inputSubMessageData = Data(inputSubMessage)
-
-        // Normal decode should put everything into unknowns.
-        let msg3 = try ProtobufUnittest_TestAllTypes(serializedData: inputSubMessageData)
-        XCTAssertTrue(msg3.unknownFields.data.isEmpty)
-        XCTAssertEqual(msg3.optionalNestedMessage.unknownFields.data, inputCurrentLevelData)
-
-        let msg4 = try ProtobufUnittest_TestAllTypes(serializedData: inputSubMessageData,
-                                                      options: discardOptions)
-        XCTAssertTrue(msg4.unknownFields.data.isEmpty)
-        XCTAssertTrue(msg4.optionalNestedMessage.unknownFields.data.isEmpty)
+        do {
+            let msg1 = try ProtobufUnittest_TestAllTypes(serializedData: inputSubMessageData)
+            XCTAssertTrue(msg1.unknownFields.data.isEmpty)
+            XCTAssertEqual(msg1.optionalNestedMessage.unknownFields.data, inputCurrentLevelData)
+
+            let msg2 = try ProtobufUnittest_TestAllTypes(serializedData: inputSubMessageData,
+                                                          options: discardOptions)
+            XCTAssertTrue(msg2.unknownFields.data.isEmpty)
+            XCTAssertTrue(msg2.optionalNestedMessage.unknownFields.data.isEmpty)
+        }
+
+        // Unknown fields nested within a message extension field:
+        //   [protobuf_unittest.optional_nested_message_extension] {
+        //     2: 1
+        //     3: 0x0000000000000002
+        //     4: "\003"
+        //     5 {
+        //       7: 4
+        //     }
+        //     6: 0x00000005
+        //   }
+        do {
+            let msg1 = try ProtobufUnittest_TestAllExtensions(
+              serializedData: inputSubMessageData,
+              extensions: ProtobufUnittest_Unittest_Extensions)
+            XCTAssertTrue(msg1.unknownFields.data.isEmpty)
+            XCTAssertEqual(msg1.ProtobufUnittest_optionalNestedMessageExtension.unknownFields.data,
+                           inputCurrentLevelData)
+
+            let msg2 = try ProtobufUnittest_TestAllExtensions(
+              serializedData: inputSubMessageData,
+              extensions: ProtobufUnittest_Unittest_Extensions,
+              options: discardOptions)
+            XCTAssertTrue(msg2.unknownFields.data.isEmpty)
+            XCTAssertTrue(msg2.ProtobufUnittest_optionalNestedMessageExtension.unknownFields.data.isEmpty)
+        }
 
         // Unknown fields nested within a group field:
         //   OptionalGroup {

            53, 5, 0, 0, 0,
        ]
        let inputCurrentLevelData = Data(inputCurrentLevel)

        // Normal decode should put everything into unknowns.
        let msg1 = try ProtobufUnittest_TestEmptyMessage(serializedData: inputCurrentLevelData)
        XCTAssertEqual(msg1.unknownFields.data, inputCurrentLevelData)

        var discardOptions = BinaryDecodingOptions()
        discardOptions.discardUnknownFields = true
        let msg2 = try ProtobufUnittest_TestEmptyMessage(serializedData: inputCurrentLevelData,
                                                      options: discardOptions)
        XCTAssertTrue(msg2.unknownFields.data.isEmpty)

        // Unknown fields nested within a message field:
        //   optional_nested_message {

                do {
                    var options = BinaryDecodingOptions()
                    options.messageDepthLimit = limit
                    let _ =
                        try ProtobufUnittest_NestedTestAllTypes(serializedData: Data(binaryInput),
                                                                options: options)
                    if !expectSuccess {
                        XCTFail("Should not have succeed, pass: \(i), limit: \(limit)")
                    }
