| 436 | } |
| 437 | |
| 438 | Status metadata_deserialize( |
| 439 | Metadata* metadata, |
| 440 | const Config& config, |
| 441 | SerializationType serialize_type, |
| 442 | span<const char> serialized_buffer) { |
| 443 | if (metadata == nullptr) |
| 444 | return LOG_STATUS(Status_SerializationError( |
| 445 | "Error deserializing metadata; null metadata instance given.")); |
| 446 | |
| 447 | try { |
| 448 | switch (serialize_type) { |
| 449 | case SerializationType::JSON: { |
| 450 | ::capnp::MallocMessageBuilder message_builder; |
| 451 | auto builder = message_builder.initRoot<capnp::ArrayMetadata>(); |
| 452 | utils::decode_json_message(serialized_buffer, builder); |
| 453 | auto reader = builder.asReader(); |
| 454 | |
| 455 | // Deserialize |
| 456 | RETURN_NOT_OK(metadata_from_capnp(reader, metadata)); |
| 457 | |
| 458 | break; |
| 459 | } |
| 460 | case SerializationType::CAPNP: { |
| 461 | // Set traversal limit from config |
| 462 | uint64_t limit = |
| 463 | config.get<uint64_t>("rest.capnp_traversal_limit").value(); |
| 464 | ::capnp::ReaderOptions readerOptions; |
| 465 | // capnp uses the limit in words |
| 466 | readerOptions.traversalLimitInWords = limit / sizeof(::capnp::word); |
| 467 | |
| 468 | const auto mBytes = |
| 469 | reinterpret_cast<const kj::byte*>(serialized_buffer.data()); |
| 470 | ::capnp::FlatArrayMessageReader msg_reader( |
| 471 | kj::arrayPtr( |
| 472 | reinterpret_cast<const ::capnp::word*>(mBytes), |
| 473 | serialized_buffer.size() / sizeof(::capnp::word)), |
| 474 | readerOptions); |
| 475 | auto reader = msg_reader.getRoot<capnp::ArrayMetadata>(); |
| 476 | |
| 477 | // Deserialize |
| 478 | RETURN_NOT_OK(metadata_from_capnp(reader, metadata)); |
| 479 | |
| 480 | break; |
| 481 | } |
| 482 | default: { |
| 483 | return LOG_STATUS(Status_SerializationError( |
| 484 | "Error deserializing array metadata; Unknown serialization type " |
| 485 | "passed")); |
| 486 | } |
| 487 | } |
| 488 | } catch (kj::Exception& e) { |
| 489 | return LOG_STATUS(Status_SerializationError( |
| 490 | "Error deserializing array metadata; kj::Exception: " + |
| 491 | std::string(e.getDescription().cStr()))); |
| 492 | } catch (std::exception& e) { |
| 493 | return LOG_STATUS(Status_SerializationError( |
| 494 | "Error deserializing array metadata; exception " + |
| 495 | std::string(e.what()))); |
no test coverage detected