(Conformance.ConformanceRequest request)
| 229 | } |
| 230 | |
| 231 | private Conformance.ConformanceResponse doTest(Conformance.ConformanceRequest request) { |
| 232 | com.google.protobuf.AbstractMessage testMessage; |
| 233 | boolean isProto3 = |
| 234 | request.getMessageType().equals("protobuf_test_messages.proto3.TestAllTypesProto3"); |
| 235 | boolean isProto2 = |
| 236 | request.getMessageType().equals("protobuf_test_messages.proto2.TestAllTypesProto2"); |
| 237 | |
| 238 | switch (request.getPayloadCase()) { |
| 239 | case PROTOBUF_PAYLOAD: |
| 240 | { |
| 241 | if (isProto3) { |
| 242 | try { |
| 243 | ExtensionRegistry extensions = ExtensionRegistry.newInstance(); |
| 244 | TestMessagesProto3.registerAllExtensions(extensions); |
| 245 | testMessage = |
| 246 | parseBinary( |
| 247 | request.getProtobufPayload(), TestAllTypesProto3.parser(), extensions); |
| 248 | } catch (InvalidProtocolBufferException e) { |
| 249 | return Conformance.ConformanceResponse.newBuilder() |
| 250 | .setParseError(e.getMessage()) |
| 251 | .build(); |
| 252 | } |
| 253 | } else if (isProto2) { |
| 254 | try { |
| 255 | ExtensionRegistry extensions = ExtensionRegistry.newInstance(); |
| 256 | TestMessagesProto2.registerAllExtensions(extensions); |
| 257 | testMessage = |
| 258 | parseBinary( |
| 259 | request.getProtobufPayload(), TestAllTypesProto2.parser(), extensions); |
| 260 | } catch (InvalidProtocolBufferException e) { |
| 261 | return Conformance.ConformanceResponse.newBuilder() |
| 262 | .setParseError(e.getMessage()) |
| 263 | .build(); |
| 264 | } |
| 265 | } else { |
| 266 | throw new RuntimeException("Protobuf request doesn't have specific payload type."); |
| 267 | } |
| 268 | break; |
| 269 | } |
| 270 | case JSON_PAYLOAD: |
| 271 | { |
| 272 | try { |
| 273 | JsonFormat.Parser parser = JsonFormat.parser().usingTypeRegistry(typeRegistry); |
| 274 | if (request.getTestCategory() |
| 275 | == Conformance.TestCategory.JSON_IGNORE_UNKNOWN_PARSING_TEST) { |
| 276 | parser = parser.ignoringUnknownFields(); |
| 277 | } |
| 278 | if (isProto3) { |
| 279 | TestMessagesProto3.TestAllTypesProto3.Builder builder = |
| 280 | TestMessagesProto3.TestAllTypesProto3.newBuilder(); |
| 281 | parser.merge(request.getJsonPayload(), builder); |
| 282 | testMessage = builder.build(); |
| 283 | } else if (isProto2) { |
| 284 | TestMessagesProto2.TestAllTypesProto2.Builder builder = |
| 285 | TestMessagesProto2.TestAllTypesProto2.newBuilder(); |
| 286 | parser.merge(request.getJsonPayload(), builder); |
| 287 | testMessage = builder.build(); |
| 288 | } else { |
no test coverage detected